Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
Education
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
黄奎
Education
Commits
e4105f28
Commit
e4105f28
authored
Sep 22, 2020
by
罗超
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
http://gitlab.oytour.com/Kui2/education
into master
parents
f9e70ec2
2550c954
Hide whitespace changes
Inline
Side-by-side
Showing
23 changed files
with
772 additions
and
53 deletions
+772
-53
GlobalKey.cs
Edu.Common/GlobalKey.cs
+5
-0
ConvertHelper.cs
Edu.Common/Plugin/ConvertHelper.cs
+22
-0
UserInfo.cs
Edu.Model/CacheModel/UserInfo.cs
+5
-0
RB_Menu.cs
Edu.Model/Entity/System/RB_Menu.cs
+0
-2
RB_Role.cs
Edu.Model/Entity/System/RB_Role.cs
+59
-0
RB_Group.cs
Edu.Model/Entity/User/RB_Group.cs
+0
-2
MenuTree_ViewModel.cs
Edu.Model/ViewModel/System/MenuTree_ViewModel.cs
+37
-0
RB_Menu_ViewModel.cs
Edu.Model/ViewModel/System/RB_Menu_ViewModel.cs
+2
-1
RB_Role_ViewModel.cs
Edu.Model/ViewModel/System/RB_Role_ViewModel.cs
+13
-0
RB_Group_ViewModel.cs
Edu.Model/ViewModel/User/RB_Group_ViewModel.cs
+4
-0
RB_School_ViewModel.cs
Edu.Model/ViewModel/User/RB_School_ViewModel.cs
+32
-0
Edu.Module.System.csproj
Edu.Module.System/Edu.Module.System.csproj
+14
-0
MenuModule.cs
Edu.Module.System/MenuModule.cs
+166
-0
RoleModule.cs
Edu.Module.System/RoleModule.cs
+94
-0
RB_MenuRepository.cs
Edu.Repository/System/RB_MenuRepository.cs
+114
-0
RB_RoleRepository.cs
Edu.Repository/System/RB_RoleRepository.cs
+96
-0
BaseController.cs
Edu.WebApi/Controllers/BaseController.cs
+1
-1
LoginController.cs
Edu.WebApi/Controllers/User/LoginController.cs
+16
-29
UserController.cs
Edu.WebApi/Controllers/User/UserController.cs
+13
-1
Edu.WebApi.csproj
Edu.WebApi/Edu.WebApi.csproj
+1
-0
ApiFilterAttribute.cs
Edu.WebApi/Filter/ApiFilterAttribute.cs
+6
-16
WebApiTokenHelper.cs
Edu.WebApi/Helper/WebApiTokenHelper.cs
+64
-0
education.sln
education.sln
+8
-1
No files found.
Edu.Common/GlobalKey.cs
View file @
e4105f28
...
@@ -20,5 +20,10 @@ namespace Edu.Common
...
@@ -20,5 +20,10 @@ namespace Edu.Common
/// 当前请求的post参数
/// 当前请求的post参数
/// </summary>
/// </summary>
public
const
string
UserPostInfo
=
"UserPostInfo"
;
public
const
string
UserPostInfo
=
"UserPostInfo"
;
/// <summary>
/// 用户验证信息
/// </summary>
public
const
string
JWT_User_Key
=
"edu_userInfo"
;
}
}
}
}
Edu.Common/Plugin/ConvertHelper.cs
View file @
e4105f28
...
@@ -114,5 +114,27 @@ namespace Edu.Common
...
@@ -114,5 +114,27 @@ namespace Edu.Common
}
}
return
result
;
return
result
;
}
}
/// <summary>
/// 格式化时间【yyyy-MM-dd HH:mm:ss】
/// </summary>
/// <param name="time"></param>
/// <returns></returns>
public
static
string
FormatTime
(
object
time
)
{
string
timeStr
=
""
;
if
(
time
!=
null
)
{
try
{
timeStr
=
Convert
.
ToDateTime
(
time
.
ToString
()).
ToString
(
"yyyy-MM-dd HH:mm:ss"
);
}
catch
{
}
}
return
timeStr
;
}
}
}
}
}
\ No newline at end of file
Edu.Model/CacheModel/UserInfo.cs
View file @
e4105f28
...
@@ -43,5 +43,10 @@ namespace Edu.Model.CacheModel
...
@@ -43,5 +43,10 @@ namespace Edu.Model.CacheModel
/// Token验证
/// Token验证
/// </summary>
/// </summary>
public
string
Token
{
get
;
set
;
}
public
string
Token
{
get
;
set
;
}
/// <summary>
/// 菜单列表
/// </summary>
public
object
MenuList
{
get
;
set
;
}
}
}
}
}
Edu.Model/Entity/System/RB_Menu.cs
View file @
e4105f28
using
Edu.Common.Enum
;
using
Edu.Common.Enum
;
using
System
;
using
System
;
using
System.Collections.Generic
;
using
System.Text
;
using
VT.FW.DB
;
using
VT.FW.DB
;
namespace
Edu.Model.Entity.System
namespace
Edu.Model.Entity.System
...
...
Edu.Model/Entity/System/RB_Role.cs
0 → 100644
View file @
e4105f28
using
Edu.Common.Enum
;
using
System
;
using
VT.FW.DB
;
namespace
Edu.Model.Entity.System
{
/// <summary>
/// 系统角色实体类
/// </summary>
[
Serializable
]
[
DB
(
ConnectionName
=
"DefaultConnection"
)]
public
class
RB_Role
{
/// <summary>
/// 角色编号
/// </summary>
public
int
RoleId
{
get
;
set
;
}
/// <summary>
/// 角色名称
/// </summary>
public
string
RoleName
{
get
;
set
;
}
/// <summary>
/// 备注/描述
/// </summary>
public
string
RoleIntro
{
get
;
set
;
}
/// <summary>
/// 角色权限
/// </summary>
public
string
RoleAuth
{
get
;
set
;
}
/// <summary>
/// 状态(0-正常,1-删除)
/// </summary>
public
DateStateEnum
Status
{
get
;
set
;
}
/// <summary>
/// 创建时间
/// </summary>
public
DateTime
CreateDate
{
get
;
set
;
}
/// <summary>
/// 创建人
/// </summary>
public
int
CreateBy
{
get
;
set
;
}
/// <summary>
/// 集团编号
/// </summary>
public
int
Group_Id
{
get
;
set
;
}
/// <summary>
/// 学校Id
/// </summary>
public
int
School_Id
{
get
;
set
;
}
}
}
\ No newline at end of file
Edu.Model/Entity/User/RB_Group.cs
View file @
e4105f28
...
@@ -71,7 +71,6 @@ namespace Edu.Model.Entity.User
...
@@ -71,7 +71,6 @@ namespace Edu.Model.Entity.User
/// <summary>
/// <summary>
/// 创建时间
/// 创建时间
/// </summary>
/// </summary>
[
JsonConverter
(
typeof
(
DateConvert
))]
public
DateTime
CreateTime
{
get
;
set
;
}
public
DateTime
CreateTime
{
get
;
set
;
}
/// <summary>
/// <summary>
...
@@ -82,7 +81,6 @@ namespace Edu.Model.Entity.User
...
@@ -82,7 +81,6 @@ namespace Edu.Model.Entity.User
/// <summary>
/// <summary>
/// 更新时间
/// 更新时间
/// </summary>
/// </summary>
[
JsonConverter
(
typeof
(
DateConvert
))]
public
DateTime
UpdateTime
{
get
;
set
;
}
public
DateTime
UpdateTime
{
get
;
set
;
}
}
}
}
}
\ No newline at end of file
Edu.Model/ViewModel/System/MenuTree_ViewModel.cs
0 → 100644
View file @
e4105f28
using
System
;
using
System.Collections.Generic
;
using
System.Text
;
namespace
Edu.Model.ViewModel.System
{
/// <summary>
/// 菜单树形结构实体
/// </summary>
public
class
MenuTree_ViewModel
{
/// <summary>
/// 主键(菜单编号)
/// </summary>
public
int
MenuId
{
get
;
set
;
}
/// <summary>
/// 菜单名称
/// </summary>
public
string
MenuName
{
get
;
set
;
}
/// <summary>
/// 菜单链接地址
/// </summary>
public
string
MenuUrl
{
get
;
set
;
}
/// <summary>
/// 菜单图标
/// </summary>
public
string
MenuIcon
{
get
;
set
;
}
/// <summary>
/// 子菜单列表
/// </summary>
public
List
<
MenuTree_ViewModel
>
SubList
{
get
;
set
;
}
}
}
Edu.Model/ViewModel/System/RB_Menu_ViewModel.cs
View file @
e4105f28
...
@@ -9,5 +9,6 @@ namespace Edu.Model.ViewModel.System
...
@@ -9,5 +9,6 @@ namespace Edu.Model.ViewModel.System
/// </summary>
/// </summary>
public
class
RB_Menu_ViewModel
:
Model
.
Entity
.
System
.
RB_Menu
public
class
RB_Menu_ViewModel
:
Model
.
Entity
.
System
.
RB_Menu
{
{
}
}
}
}
\ No newline at end of file
Edu.Model/ViewModel/System/RB_Role_ViewModel.cs
0 → 100644
View file @
e4105f28
using
System
;
using
System.Collections.Generic
;
using
System.Text
;
namespace
Edu.Model.ViewModel.System
{
/// <summary>
/// 系统角色视图实体类
/// </summary>
public
class
RB_Role_ViewModel
:
Model
.
Entity
.
System
.
RB_Role
{
}
}
Edu.Model/ViewModel/User/RB_Group_ViewModel.cs
View file @
e4105f28
...
@@ -10,6 +10,10 @@ namespace Edu.Model.ViewModel.User
...
@@ -10,6 +10,10 @@ namespace Edu.Model.ViewModel.User
[
Serializable
]
[
Serializable
]
public
class
RB_Group_ViewModel
:
Model
.
Entity
.
User
.
RB_Group
public
class
RB_Group_ViewModel
:
Model
.
Entity
.
User
.
RB_Group
{
{
public
string
CreateTimeStr
{
get
{
return
""
;
}
}
public
string
UpdateTimeStr
{
get
;
set
;
}
}
}
}
}
Edu.Model/ViewModel/User/RB_School_ViewModel.cs
View file @
e4105f28
...
@@ -14,5 +14,37 @@ namespace Edu.Model.ViewModel.User
...
@@ -14,5 +14,37 @@ namespace Edu.Model.ViewModel.User
/// 集团名称
/// 集团名称
/// </summary>
/// </summary>
public
string
GroupName
{
get
;
set
;
}
public
string
GroupName
{
get
;
set
;
}
/// <summary>
/// 创建人
/// </summary>
public
string
CreateByName
{
get
;
set
;
}
/// <summary>
/// 创建时间
/// </summary>
public
string
CreateTimeStr
{
get
{
return
Common
.
ConvertHelper
.
FormatTime
(
this
.
CreateTime
);
}
}
/// <summary>
/// 修改人
/// </summary>
public
string
UpdateByName
{
get
;
set
;
}
/// <summary>
/// 更新时间
/// </summary>
public
string
UpdateTimeStr
{
get
{
return
Common
.
ConvertHelper
.
FormatTime
(
this
.
UpdateTime
);
}
}
}
}
}
}
Edu.Module.System/Edu.Module.System.csproj
0 → 100644
View file @
e4105f28
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Edu.Aop\Edu.Aop.csproj" />
<ProjectReference Include="..\Edu.Common\Edu.Common.csproj" />
<ProjectReference Include="..\Edu.Model\Edu.Model.csproj" />
<ProjectReference Include="..\Edu.Repository\Edu.Repository.csproj" />
</ItemGroup>
</Project>
Edu.Module.System/MenuModule.cs
0 → 100644
View file @
e4105f28
using
Edu.Model.ViewModel.System
;
using
Edu.Repository.System
;
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
VT.FW.DB
;
namespace
Edu.Module.System
{
/// <summary>
/// 菜单处理类
/// </summary>
public
class
MenuModule
{
/// <summary>
/// 系统菜单仓储层对象
/// </summary>
private
readonly
RB_MenuRepository
menuRepository
=
new
RB_MenuRepository
();
/// <summary>
/// 获取菜单列表
/// </summary>
/// <param name="query"></param>
/// <returns></returns>
public
List
<
RB_Menu_ViewModel
>
GetMenuListModule
(
RB_Menu_ViewModel
query
)
{
return
menuRepository
.
GetMenuListRepository
(
query
);
}
/// <summary>
/// 获取菜单分页列表
/// </summary>
/// <param name="pageIndex"></param>
/// <param name="pageSize"></param>
/// <param name="rowsCount"></param>
/// <param name="query"></param>
/// <returns></returns>
public
List
<
RB_Menu_ViewModel
>
GetMenuPageListModule
(
int
pageIndex
,
int
pageSize
,
out
long
rowsCount
,
RB_Menu_ViewModel
query
)
{
return
menuRepository
.
GetMenuPageListRepository
(
pageIndex
,
pageSize
,
out
rowsCount
,
query
);
}
/// <summary>
/// 新增修改菜单
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public
virtual
bool
SetMenuModule
(
RB_Menu_ViewModel
model
)
{
bool
flag
;
if
(
model
.
MenuId
>
0
)
{
Dictionary
<
string
,
object
>
fileds
=
new
Dictionary
<
string
,
object
>()
{
{
nameof
(
RB_Menu_ViewModel
.
MenuName
),
model
.
MenuName
.
Trim
()
},
{
nameof
(
RB_Menu_ViewModel
.
ParentId
),
model
.
ParentId
},
{
nameof
(
RB_Menu_ViewModel
.
MenuUrl
),
model
.
MenuUrl
},
{
nameof
(
RB_Menu_ViewModel
.
MenuIcon
),
model
.
MenuIcon
},
{
nameof
(
RB_Menu_ViewModel
.
MenuLevel
),
model
.
MenuLevel
},
{
nameof
(
RB_Menu_ViewModel
.
MenuType
),
model
.
MenuType
},
{
nameof
(
RB_Menu_ViewModel
.
SortNum
),
model
.
SortNum
},
};
flag
=
menuRepository
.
Update
(
fileds
,
new
WhereHelper
(
nameof
(
RB_Menu_ViewModel
.
MenuId
),
model
.
MenuId
));
}
else
{
var
newId
=
menuRepository
.
Insert
(
model
);
model
.
MenuId
=
newId
;
flag
=
newId
>
0
;
}
return
flag
;
}
/// <summary>
/// 根据菜单编号获取菜单实体
/// </summary>
/// <param name="MenuId"></param>
/// <returns></returns>
public
RB_Menu_ViewModel
GetMenuModule
(
object
MenuId
)
{
return
menuRepository
.
GetEntity
<
RB_Menu_ViewModel
>(
MenuId
);
}
/// <summary>
/// 更新菜单状态
/// </summary>
/// <param name="MenuId"></param>
/// <param name="Status"></param>
/// <returns></returns>
public
bool
SetMenuStatusModule
(
int
MenuId
,
int
Status
)
{
Dictionary
<
string
,
object
>
fileds
=
new
Dictionary
<
string
,
object
>()
{
{
nameof
(
RB_Menu_ViewModel
.
Status
),
Status
},
};
bool
flag
=
menuRepository
.
Update
(
fileds
,
new
WhereHelper
(
nameof
(
RB_Menu_ViewModel
.
MenuId
),
MenuId
));
return
flag
;
}
/// <summary>
/// 获取树形菜单
/// </summary>
/// <param name="query"></param>
/// <returns></returns>
public
List
<
MenuTree_ViewModel
>
GetTreeMenuModule
(
RB_Menu_ViewModel
query
)
{
List
<
MenuTree_ViewModel
>
treeList
=
new
List
<
MenuTree_ViewModel
>();
var
list
=
GetMenuListModule
(
query
);
if
(
list
!=
null
&&
list
.
Count
>
0
)
{
//一级菜单
var
firstLevelList
=
list
.
Where
(
qitem
=>
qitem
.
MenuLevel
==
1
).
ToList
();
if
(
firstLevelList
!=
null
&&
firstLevelList
.
Count
>
0
)
{
foreach
(
var
fItem
in
firstLevelList
)
{
MenuTree_ViewModel
fModel
=
new
MenuTree_ViewModel
()
{
MenuId
=
fItem
.
MenuId
,
MenuName
=
fItem
.
MenuName
,
MenuUrl
=
fItem
.
MenuUrl
,
MenuIcon
=
fItem
.
MenuIcon
,
SubList
=
new
List
<
MenuTree_ViewModel
>()
};
//二级菜单
var
secondLevelList
=
list
.
Where
(
qitem
=>
qitem
.
MenuLevel
==
2
&&
qitem
.
ParentId
==
fItem
.
MenuId
).
ToList
();
if
(
secondLevelList
!=
null
&&
secondLevelList
.
Count
>
0
)
{
foreach
(
var
sItem
in
secondLevelList
)
{
MenuTree_ViewModel
sModel
=
new
MenuTree_ViewModel
()
{
MenuId
=
sItem
.
MenuId
,
MenuName
=
sItem
.
MenuName
,
MenuUrl
=
sItem
.
MenuUrl
,
MenuIcon
=
sItem
.
MenuIcon
,
SubList
=
new
List
<
MenuTree_ViewModel
>()
};
//三级菜单
var
thirdLevelList
=
list
.
Where
(
qitem
=>
qitem
.
MenuLevel
==
3
&&
qitem
.
ParentId
==
sItem
.
MenuId
).
ToList
();
if
(
thirdLevelList
!=
null
&&
thirdLevelList
.
Count
>
0
)
{
foreach
(
var
tItem
in
thirdLevelList
)
{
sModel
.
SubList
.
Add
(
new
MenuTree_ViewModel
()
{
MenuId
=
tItem
.
MenuId
,
MenuName
=
tItem
.
MenuName
,
MenuUrl
=
tItem
.
MenuUrl
,
MenuIcon
=
tItem
.
MenuIcon
,
SubList
=
new
List
<
MenuTree_ViewModel
>()
});
}
}
fModel
.
SubList
.
Add
(
sModel
);
}
}
treeList
.
Add
(
fModel
);
}
}
}
return
treeList
;
}
}
}
\ No newline at end of file
Edu.Module.System/RoleModule.cs
0 → 100644
View file @
e4105f28
using
Edu.Common.Enum
;
using
Edu.Model.ViewModel.System
;
using
Edu.Repository.System
;
using
System.Collections.Generic
;
using
VT.FW.DB
;
namespace
Edu.Module.System
{
/// <summary>
/// 角色处理类
/// </summary>
public
class
RoleModule
{
/// <summary>
/// 角色仓储层对象
/// </summary>
private
readonly
RB_RoleRepository
roleRepository
=
new
RB_RoleRepository
();
/// <summary>
/// 获取角色列表
/// </summary>
/// <param name="query"></param>
/// <returns></returns>
public
List
<
RB_Role_ViewModel
>
GetRoleListModule
(
RB_Role_ViewModel
query
)
{
return
roleRepository
.
GetRoleListRepository
(
query
);
}
/// <summary>
/// 获取角色分页列表
/// </summary>
/// <param name="pageIndex"></param>
/// <param name="pageSize"></param>
/// <param name="rowsCount"></param>
/// <param name="query"></param>
/// <returns></returns>
public
List
<
RB_Role_ViewModel
>
GetRolePageListModule
(
int
pageIndex
,
int
pageSize
,
out
long
rowsCount
,
RB_Role_ViewModel
query
)
{
return
roleRepository
.
GetRolePageListRepository
(
pageIndex
,
pageSize
,
out
rowsCount
,
query
);
}
/// <summary>
/// 新增修改角色
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public
bool
SetRoleModule
(
RB_Role_ViewModel
model
)
{
bool
flag
;
if
(
model
.
RoleId
>
0
)
{
Dictionary
<
string
,
object
>
fileds
=
new
Dictionary
<
string
,
object
>()
{
{
nameof
(
RB_Role_ViewModel
.
RoleName
),
model
.
RoleName
.
Trim
()
},
{
nameof
(
RB_Role_ViewModel
.
RoleIntro
),
model
.
RoleIntro
},
{
nameof
(
RB_Role_ViewModel
.
RoleAuth
),
model
.
RoleAuth
},
};
flag
=
roleRepository
.
Update
(
fileds
,
new
WhereHelper
(
nameof
(
RB_Role_ViewModel
.
RoleId
),
model
.
RoleId
));
}
else
{
var
newId
=
roleRepository
.
Insert
(
model
);
model
.
RoleId
=
newId
;
flag
=
newId
>
0
;
}
return
flag
;
}
/// <summary>
/// 获取角色实体
/// </summary>
/// <param name="RoleId"></param>
/// <returns></returns>
public
RB_Role_ViewModel
GetRoleModule
(
object
RoleId
)
{
return
roleRepository
.
GetEntity
<
RB_Role_ViewModel
>(
RoleId
);
}
/// <summary>
/// 删除角色
/// </summary>
/// <param name="RoleId"></param>
/// <returns></returns>
public
bool
RemoveRoleModule
(
object
RoleId
)
{
Dictionary
<
string
,
object
>
fileds
=
new
Dictionary
<
string
,
object
>()
{
{
nameof
(
RB_Role_ViewModel
.
Status
),(
int
)
DateStateEnum
.
Delete
},
};
bool
flag
=
roleRepository
.
Update
(
fileds
,
new
WhereHelper
(
nameof
(
RB_Role_ViewModel
.
RoleId
),
RoleId
));
return
flag
;
}
}
}
\ No newline at end of file
Edu.Repository/System/RB_MenuRepository.cs
0 → 100644
View file @
e4105f28
using
Edu.Common.Enum
;
using
Edu.Model.ViewModel.System
;
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
VT.FW.DB.Dapper
;
namespace
Edu.Repository.System
{
public
class
RB_MenuRepository
:
BaseRepository
<
Model
.
Entity
.
System
.
RB_Menu
>
{
/// <summary>
/// 获取菜单列表
/// </summary>
/// <param name="query"></param>
/// <returns></returns>
public
List
<
RB_Menu_ViewModel
>
GetMenuListRepository
(
RB_Menu_ViewModel
query
)
{
var
parameters
=
new
DynamicParameters
();
StringBuilder
builder
=
new
StringBuilder
();
builder
.
AppendFormat
(
@"
SELECT *
FROM rb_menu
WHERE 1=1
"
);
builder
.
AppendFormat
(
" AND {0}={1} "
,
nameof
(
RB_Menu_ViewModel
.
Status
),
(
int
)
DateStateEnum
.
Normal
);
if
(
query
!=
null
)
{
if
(!
string
.
IsNullOrWhiteSpace
(
query
.
MenuName
))
{
builder
.
AppendFormat
(
" AND {0} LIKE @MenuName "
,
nameof
(
RB_Menu_ViewModel
.
MenuName
));
parameters
.
Add
(
"MenuName"
,
"%"
+
query
.
MenuName
.
Trim
()
+
"%"
);
}
if
(!
string
.
IsNullOrWhiteSpace
(
query
.
MenuUrl
))
{
builder
.
AppendFormat
(
" AND {0} LIKE @MenuUrl "
,
nameof
(
RB_Menu_ViewModel
.
MenuUrl
));
parameters
.
Add
(
"MenuUrl"
,
"%"
+
query
.
MenuUrl
.
Trim
()
+
"%"
);
}
if
(
query
.
MenuLevel
>
0
)
{
builder
.
AppendFormat
(
" AND {0}={1} "
,
nameof
(
RB_Menu_ViewModel
.
MenuLevel
),
query
.
MenuLevel
);
}
if
(
query
.
MenuId
>
0
)
{
builder
.
AppendFormat
(
" AND {0}={1} "
,
nameof
(
RB_Menu_ViewModel
.
MenuLevel
),
query
.
MenuId
);
}
if
(
query
.
ParentId
>
0
)
{
builder
.
AppendFormat
(
" AND {0}={1} "
,
nameof
(
RB_Menu_ViewModel
.
ParentId
),
query
.
ParentId
);
}
if
(
query
.
MenuType
>
0
)
{
builder
.
AppendFormat
(
" AND {0}={1} "
,
nameof
(
RB_Menu_ViewModel
.
MenuType
),
query
.
MenuType
);
}
}
return
Get
<
RB_Menu_ViewModel
>(
builder
.
ToString
(),
parameters
).
ToList
();
}
/// <summary>
/// 获取菜单分页列表
/// </summary>
/// <param name="pageIndex"></param>
/// <param name="pageSize"></param>
/// <param name="rowsCount"></param>
/// <param name="query"></param>
/// <returns></returns>
public
List
<
RB_Menu_ViewModel
>
GetMenuPageListRepository
(
int
pageIndex
,
int
pageSize
,
out
long
rowsCount
,
RB_Menu_ViewModel
query
)
{
var
parameters
=
new
DynamicParameters
();
StringBuilder
builder
=
new
StringBuilder
();
builder
.
AppendFormat
(
@"
SELECT *
FROM rb_menu
WHERE 1=1
"
);
if
(
query
!=
null
)
{
if
(!
string
.
IsNullOrWhiteSpace
(
query
.
MenuName
))
{
builder
.
AppendFormat
(
" AND {0} LIKE @MenuName "
,
nameof
(
RB_Menu_ViewModel
.
MenuName
));
parameters
.
Add
(
"MenuName"
,
"%"
+
query
.
MenuName
.
Trim
()
+
"%"
);
}
if
(!
string
.
IsNullOrWhiteSpace
(
query
.
MenuUrl
))
{
builder
.
AppendFormat
(
" AND {0} LIKE @MenuUrl "
,
nameof
(
RB_Menu_ViewModel
.
MenuUrl
));
parameters
.
Add
(
"MenuUrl"
,
"%"
+
query
.
MenuUrl
.
Trim
()
+
"%"
);
}
if
(
query
.
MenuLevel
>
0
)
{
builder
.
AppendFormat
(
" AND {0}={1} "
,
nameof
(
RB_Menu_ViewModel
.
MenuLevel
),
query
.
MenuLevel
);
}
if
(
query
.
MenuId
>
0
)
{
builder
.
AppendFormat
(
" AND {0}={1} "
,
nameof
(
RB_Menu_ViewModel
.
MenuLevel
),
query
.
MenuId
);
}
if
(
query
.
ParentId
>
0
)
{
builder
.
AppendFormat
(
" AND {0}={1} "
,
nameof
(
RB_Menu_ViewModel
.
ParentId
),
query
.
ParentId
);
}
if
(
query
.
MenuType
>
0
)
{
builder
.
AppendFormat
(
" AND {0}={1} "
,
nameof
(
RB_Menu_ViewModel
.
MenuType
),
query
.
MenuType
);
}
if
((
int
)
query
.
Status
>
-
1
)
{
builder
.
AppendFormat
(
" AND {0}={1} "
,
nameof
(
RB_Menu_ViewModel
.
Status
),
(
int
)
query
.
Status
);
}
}
return
GetPage
<
RB_Menu_ViewModel
>(
pageIndex
,
pageSize
,
out
rowsCount
,
builder
.
ToString
(),
parameters
).
ToList
();
}
}
}
\ No newline at end of file
Edu.Repository/System/RB_RoleRepository.cs
0 → 100644
View file @
e4105f28
using
Edu.Common.Enum
;
using
Edu.Model.ViewModel.System
;
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
VT.FW.DB.Dapper
;
namespace
Edu.Repository.System
{
/// <summary>
/// 系统角色仓储类
/// </summary>
public
class
RB_RoleRepository
:
BaseRepository
<
Model
.
Entity
.
System
.
RB_Role
>
{
/// <summary>
/// 获取角色列表
/// </summary>
/// <param name="query"></param>
/// <returns></returns>
public
List
<
RB_Role_ViewModel
>
GetRoleListRepository
(
RB_Role_ViewModel
query
)
{
var
parameters
=
new
DynamicParameters
();
StringBuilder
builder
=
new
StringBuilder
();
builder
.
AppendFormat
(
@"
SELECT *
FROM rb_role
WHERE 1=1
"
);
builder
.
AppendFormat
(
" AND {0}={1} "
,
nameof
(
RB_Role_ViewModel
.
Status
),
(
int
)
DateStateEnum
.
Normal
);
if
(
query
!=
null
)
{
if
(
query
.
Group_Id
>
0
)
{
builder
.
AppendFormat
(
" AND {0}={1} "
,
nameof
(
RB_Role_ViewModel
.
Group_Id
),
query
.
Group_Id
);
}
if
(
query
.
School_Id
>
0
)
{
builder
.
AppendFormat
(
" AND {0}={1} "
,
nameof
(
RB_Role_ViewModel
.
School_Id
),
query
.
School_Id
);
}
if
(
query
.
RoleId
>
0
)
{
builder
.
AppendFormat
(
" AND {0}={1} "
,
nameof
(
RB_Role_ViewModel
.
RoleId
),
query
.
RoleId
);
}
if
(!
string
.
IsNullOrWhiteSpace
(
query
.
RoleName
))
{
builder
.
AppendFormat
(
" AND {0} LIKE @RoleName "
,
nameof
(
RB_Role_ViewModel
.
RoleName
));
parameters
.
Add
(
"RoleName"
,
"%"
+
query
.
RoleName
.
Trim
()
+
"%"
);
}
}
return
Get
<
RB_Role_ViewModel
>(
builder
.
ToString
(),
parameters
).
ToList
();
}
/// <summary>
/// 获取角色分页列表
/// </summary>
/// <param name="pageIndex"></param>
/// <param name="pageSize"></param>
/// <param name="rowsCount"></param>
/// <param name="query"></param>
/// <returns></returns>
public
List
<
RB_Role_ViewModel
>
GetRolePageListRepository
(
int
pageIndex
,
int
pageSize
,
out
long
rowsCount
,
RB_Role_ViewModel
query
)
{
var
parameters
=
new
DynamicParameters
();
StringBuilder
builder
=
new
StringBuilder
();
builder
.
AppendFormat
(
@"
SELECT *
FROM rb_role
WHERE 1=1
"
);
builder
.
AppendFormat
(
" AND {0}={1} "
,
nameof
(
RB_Role_ViewModel
.
Status
),
(
int
)
DateStateEnum
.
Normal
);
if
(
query
!=
null
)
{
if
(
query
.
Group_Id
>
0
)
{
builder
.
AppendFormat
(
" AND {0}={1} "
,
nameof
(
RB_Role_ViewModel
.
Group_Id
),
query
.
Group_Id
);
}
if
(
query
.
School_Id
>
0
)
{
builder
.
AppendFormat
(
" AND {0}={1} "
,
nameof
(
RB_Role_ViewModel
.
School_Id
),
query
.
School_Id
);
}
if
(
query
.
RoleId
>
0
)
{
builder
.
AppendFormat
(
" AND {0}={1} "
,
nameof
(
RB_Role_ViewModel
.
RoleId
),
query
.
RoleId
);
}
if
(!
string
.
IsNullOrWhiteSpace
(
query
.
RoleName
))
{
builder
.
AppendFormat
(
" AND {0} LIKE @RoleName "
,
nameof
(
RB_Role_ViewModel
.
RoleName
));
parameters
.
Add
(
"RoleName"
,
"%"
+
query
.
RoleName
.
Trim
()
+
"%"
);
}
}
return
GetPage
<
RB_Role_ViewModel
>(
pageIndex
,
pageSize
,
out
rowsCount
,
builder
.
ToString
(),
parameters
).
ToList
();
}
}
}
Edu.WebApi/Controllers/BaseController.cs
View file @
e4105f28
...
@@ -38,7 +38,7 @@ namespace Edu.WebApi.Controllers
...
@@ -38,7 +38,7 @@ namespace Edu.WebApi.Controllers
var
requestMsg
=
Request
.
HttpContext
.
Items
[
GlobalKey
.
UserPostInfo
];
var
requestMsg
=
Request
.
HttpContext
.
Items
[
GlobalKey
.
UserPostInfo
];
if
(
requestMsg
!=
null
)
if
(
requestMsg
!=
null
)
{
{
requestParm
=
JsonConvert
.
DeserializeObject
<
RequestParm
>(
requestMsg
.
ToString
());
requestParm
=
JsonConvert
.
DeserializeObject
<
RequestParm
>(
requestMsg
.
ToString
());
if
(
Request
.
HttpContext
.
Items
[
GlobalKey
.
TokenUserInfo
]
!=
null
)
if
(
Request
.
HttpContext
.
Items
[
GlobalKey
.
TokenUserInfo
]
!=
null
)
{
{
JObject
parms
=
JObject
.
Parse
(
Request
.
HttpContext
.
Items
[
GlobalKey
.
TokenUserInfo
].
ToString
());
JObject
parms
=
JObject
.
Parse
(
Request
.
HttpContext
.
Items
[
GlobalKey
.
TokenUserInfo
].
ToString
());
...
...
Edu.WebApi/Controllers/User/LoginController.cs
View file @
e4105f28
using
System
;
using
System.Linq
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Threading.Tasks
;
using
Castle.DynamicProxy.Generators
;
using
Edu.Cache.User
;
using
Edu.Cache.User
;
using
Edu.Common.API
;
using
Edu.Common.API
;
using
Edu.Common.Plugin
;
using
Edu.Common.Plugin
;
using
Edu.Model.CacheModel
;
using
Edu.Model.CacheModel
;
using
Edu.Model.ViewModel.User
;
using
Edu.Model.ViewModel.User
;
using
Edu.Module.System
;
using
Edu.Module.User
;
using
Edu.Module.User
;
using
Edu.WebApi.Filter
;
using
Edu.WebApi.Filter
;
using
JWT
;
using
Edu.WebApi.Helper
;
using
JWT.Algorithms
;
using
JWT.Serializers
;
using
Microsoft.AspNetCore.Authorization
;
using
Microsoft.AspNetCore.Authorization
;
using
Microsoft.AspNetCore.Cors
;
using
Microsoft.AspNetCore.Cors
;
using
Microsoft.AspNetCore.Http
;
using
Microsoft.AspNetCore.Mvc
;
using
Microsoft.AspNetCore.Mvc
;
using
Newtonsoft.Json.Linq
;
using
Newtonsoft.Json.Linq
;
namespace
Edu.WebApi.Controllers.User
namespace
Edu.WebApi.Controllers.User
{
{
[
Route
(
"api/[controller]/[action]"
)]
[
Route
(
"api/[controller]/[action]"
)]
...
@@ -32,6 +27,11 @@ namespace Edu.WebApi.Controllers.User
...
@@ -32,6 +27,11 @@ namespace Edu.WebApi.Controllers.User
/// </summary>
/// </summary>
private
readonly
AccountModule
accountModule
=
new
AccountModule
();
private
readonly
AccountModule
accountModule
=
new
AccountModule
();
/// <summary>
/// 菜单处理类对象
/// </summary>
private
readonly
MenuModule
menuModule
=
new
MenuModule
();
/// <summary>
/// <summary>
/// 用户登录
/// 用户登录
/// </summary>
/// </summary>
...
@@ -42,7 +42,6 @@ namespace Edu.WebApi.Controllers.User
...
@@ -42,7 +42,6 @@ namespace Edu.WebApi.Controllers.User
public
ApiResult
Login
()
public
ApiResult
Login
()
{
{
JObject
jobj
=
JObject
.
Parse
(
RequestParm
.
Msg
.
ToString
());
JObject
jobj
=
JObject
.
Parse
(
RequestParm
.
Msg
.
ToString
());
string
account
=
jobj
.
GetStringValue
(
"Account"
);
string
account
=
jobj
.
GetStringValue
(
"Account"
);
string
password
=
jobj
.
GetStringValue
(
"Password"
);
string
password
=
jobj
.
GetStringValue
(
"Password"
);
int
accountType
=
jobj
.
GetInt
(
"AccountType"
,
1
);
int
accountType
=
jobj
.
GetInt
(
"AccountType"
,
1
);
...
@@ -69,25 +68,12 @@ namespace Edu.WebApi.Controllers.User
...
@@ -69,25 +68,12 @@ namespace Edu.WebApi.Controllers.User
{
{
return
ApiResult
.
Failed
(
message
:
$"此账号【
{
account
}
】已删除!"
);
return
ApiResult
.
Failed
(
message
:
$"此账号【
{
account
}
】已删除!"
);
}
}
//生成token
TokenUserInfo
userInfo
=
new
TokenUserInfo
{
Uid
=
model
.
Id
.
ToString
(),
RequestFrom
=
Common
.
Enum
.
ApiRequestFromEnum
.
WebAdmin
};
string
token
=
WebApiTokenHelper
.
CreateToken
(
model
.
Id
.
ToString
(),
Common
.
Enum
.
ApiRequestFromEnum
.
WebAdmin
);
var
treeList
=
menuModule
.
GetTreeMenuModule
(
new
Model
.
ViewModel
.
System
.
RB_Menu_ViewModel
()
IDateTimeProvider
provider
=
new
UtcDateTimeProvider
();
{
var
now
=
provider
.
GetNow
().
AddMinutes
(-
1
);
MenuType
=
accountType
var
unixEpoch
=
new
DateTime
(
1970
,
1
,
1
,
0
,
0
,
0
,
DateTimeKind
.
Utc
);
});
var
secondsSinceEpoch
=
Math
.
Round
((
now
-
unixEpoch
).
TotalSeconds
);
var
payload
=
new
Dictionary
<
string
,
object
>
{
{
"iat"
,
secondsSinceEpoch
},
{
"exp"
,
secondsSinceEpoch
+
Common
.
Config
.
JwtExpirTime
},
{
"edu_userInfo"
,
userInfo
}
};
IJwtAlgorithm
algorithm
=
new
HMACSHA256Algorithm
();
IJsonSerializer
serializer
=
new
JsonNetSerializer
();
IBase64UrlEncoder
urlEncoder
=
new
JwtBase64UrlEncoder
();
IJwtEncoder
encoder
=
new
JwtEncoder
(
algorithm
,
serializer
,
urlEncoder
);
string
secret
=
Common
.
Config
.
JwtSecretKey
;
string
token
=
encoder
.
Encode
(
payload
,
secret
);
UserInfo
obj
=
new
UserInfo
UserInfo
obj
=
new
UserInfo
{
{
Id
=
model
.
Id
,
Id
=
model
.
Id
,
...
@@ -97,6 +83,7 @@ namespace Edu.WebApi.Controllers.User
...
@@ -97,6 +83,7 @@ namespace Edu.WebApi.Controllers.User
GroupName
=
model
.
GroupName
,
GroupName
=
model
.
GroupName
,
SchoolName
=
model
.
SchoolName
,
SchoolName
=
model
.
SchoolName
,
Token
=
token
,
Token
=
token
,
MenuList
=
treeList
};
};
UserReidsCache
.
UserInfoSet
(
Cache
.
CacheKey
.
User_Login_Key
+
model
.
Id
,
obj
,
Common
.
Config
.
JwtExpirTime
);
UserReidsCache
.
UserInfoSet
(
Cache
.
CacheKey
.
User_Login_Key
+
model
.
Id
,
obj
,
Common
.
Config
.
JwtExpirTime
);
return
ApiResult
.
Success
(
data
:
obj
);
return
ApiResult
.
Success
(
data
:
obj
);
...
...
Edu.WebApi/Controllers/User/UserController.cs
View file @
e4105f28
...
@@ -3,6 +3,7 @@ using System.Collections.Generic;
...
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using
System.Linq
;
using
System.Linq
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
using
Edu.AOP
;
using
Edu.AOP
;
using
Edu.Cache.User
;
using
Edu.Common.API
;
using
Edu.Common.API
;
using
Edu.Common.Plugin
;
using
Edu.Common.Plugin
;
using
Edu.Model.ViewModel.User
;
using
Edu.Model.ViewModel.User
;
...
@@ -149,9 +150,20 @@ namespace Edu.WebApi.Controllers.User
...
@@ -149,9 +150,20 @@ namespace Edu.WebApi.Controllers.User
var
query
=
Common
.
Plugin
.
JsonHelper
.
DeserializeObject
<
RB_School_ViewModel
>(
RequestParm
.
Msg
.
ToString
());
var
query
=
Common
.
Plugin
.
JsonHelper
.
DeserializeObject
<
RB_School_ViewModel
>(
RequestParm
.
Msg
.
ToString
());
query
.
Group_Id
=
base
.
UserInfo
.
Group_Id
;
query
.
Group_Id
=
base
.
UserInfo
.
Group_Id
;
var
list
=
schoolModule
.
GetSchoolPageListModule
(
pageModel
.
PageIndex
,
pageModel
.
PageSize
,
out
long
rowsCount
,
query
);
var
list
=
schoolModule
.
GetSchoolPageListModule
(
pageModel
.
PageIndex
,
pageModel
.
PageSize
,
out
long
rowsCount
,
query
);
foreach
(
var
item
in
list
)
{
if
(
item
.
CreateBy
>
0
)
{
item
.
CreateByName
=
UserReidsCache
.
GetUserLoginInfo
(
item
.
CreateBy
)?.
AccountName
??
""
;
}
if
(
item
.
UpdateBy
>
0
)
{
item
.
UpdateByName
=
UserReidsCache
.
GetUserLoginInfo
(
item
.
UpdateBy
)?.
AccountName
??
""
;
}
}
pageModel
.
Count
=
rowsCount
;
pageModel
.
Count
=
rowsCount
;
pageModel
.
PageData
=
list
;
pageModel
.
PageData
=
list
;
return
ApiResult
.
Success
(
data
:
list
);
return
ApiResult
.
Success
(
data
:
pageModel
);
}
}
/// <summary>
/// <summary>
...
...
Edu.WebApi/Edu.WebApi.csproj
View file @
e4105f28
...
@@ -22,6 +22,7 @@
...
@@ -22,6 +22,7 @@
<ProjectReference Include="..\Edu.Cache\Edu.Cache.csproj" />
<ProjectReference Include="..\Edu.Cache\Edu.Cache.csproj" />
<ProjectReference Include="..\Edu.Common\Edu.Common.csproj" />
<ProjectReference Include="..\Edu.Common\Edu.Common.csproj" />
<ProjectReference Include="..\Edu.Model\Edu.Model.csproj" />
<ProjectReference Include="..\Edu.Model\Edu.Model.csproj" />
<ProjectReference Include="..\Edu.Module.System\Edu.Module.System.csproj" />
<ProjectReference Include="..\Edu.Module.User\Edu.Module.User.csproj" />
<ProjectReference Include="..\Edu.Module.User\Edu.Module.User.csproj" />
<ProjectReference Include="..\Edu.Repository\Edu.Repository.csproj" />
<ProjectReference Include="..\Edu.Repository\Edu.Repository.csproj" />
</ItemGroup>
</ItemGroup>
...
...
Edu.WebApi/Filter/ApiFilterAttribute.cs
View file @
e4105f28
using
JWT
;
using
JWT
;
using
JWT.Serializers
;
using
Newtonsoft.Json.Linq
;
using
Newtonsoft.Json.Linq
;
using
System
;
using
System
;
using
System.IO
;
using
System.IO
;
...
@@ -12,6 +11,7 @@ using Microsoft.AspNetCore.Http.Features;
...
@@ -12,6 +11,7 @@ using Microsoft.AspNetCore.Http.Features;
using
Edu.Common.Plugin
;
using
Edu.Common.Plugin
;
using
Edu.Common.API
;
using
Edu.Common.API
;
using
Edu.Cache.User
;
using
Edu.Cache.User
;
using
Edu.WebApi.Helper
;
namespace
Edu.WebApi.Filter
namespace
Edu.WebApi.Filter
{
{
...
@@ -36,17 +36,13 @@ namespace Edu.WebApi.Filter
...
@@ -36,17 +36,13 @@ namespace Edu.WebApi.Filter
isCheckToken
=
false
;
isCheckToken
=
false
;
}
}
#
region
Token
校验
//Token校验
if
(
isCheckToken
)
if
(
isCheckToken
)
{
{
JWTValidat
(
actionContext
,
token
);
JWTValidat
(
actionContext
,
token
);
}
}
#
endregion
#
region
验证表单重复提交
#
region
验证表单重复提交
string
controllerName
=
actionContext
.
ActionDescriptor
.
RouteValues
[
"controller"
].
ToString
().
ToLower
();
string
controllerName
=
actionContext
.
ActionDescriptor
.
RouteValues
[
"controller"
].
ToString
().
ToLower
();
string
actionName
=
actionContext
.
ActionDescriptor
.
RouteValues
[
"action"
].
ToString
().
ToLower
();
string
actionName
=
actionContext
.
ActionDescriptor
.
RouteValues
[
"action"
].
ToString
().
ToLower
();
if
(!
actionName
.
ToLower
().
Contains
(
"get"
))
if
(!
actionName
.
ToLower
().
Contains
(
"get"
))
...
@@ -87,6 +83,7 @@ namespace Edu.WebApi.Filter
...
@@ -87,6 +83,7 @@ namespace Edu.WebApi.Filter
{
{
JObject
parm
=
new
JObject
();
JObject
parm
=
new
JObject
();
var
request
=
actionContext
.
HttpContext
.
Request
;
var
request
=
actionContext
.
HttpContext
.
Request
;
var
headers
=
actionContext
.
HttpContext
.
Request
.
Headers
;
#
region
如果参数是
json
实体对象,获取序列化后的数据
#
region
如果参数是
json
实体对象,获取序列化后的数据
request
.
EnableBuffering
();
request
.
EnableBuffering
();
string
responseData
=
""
;
string
responseData
=
""
;
...
@@ -107,7 +104,7 @@ namespace Edu.WebApi.Filter
...
@@ -107,7 +104,7 @@ namespace Edu.WebApi.Filter
{
{
Common
.
Plugin
.
LogHelper
.
Write
(
ex
,
string
.
Format
(
"DoApiMonitorLog:{0}"
,
responseData
));
Common
.
Plugin
.
LogHelper
.
Write
(
ex
,
string
.
Format
(
"DoApiMonitorLog:{0}"
,
responseData
));
}
}
token
=
JsonHelper
.
GetStringValue
(
parm
,
"token"
);
token
=
headers
[
"token"
].
ToString
(
);
}
}
#
endregion
#
endregion
return
parm
;
return
parm
;
...
@@ -125,15 +122,8 @@ namespace Edu.WebApi.Filter
...
@@ -125,15 +122,8 @@ namespace Edu.WebApi.Filter
//解析token,校验是否失效
//解析token,校验是否失效
try
try
{
{
IJsonSerializer
serializer
=
new
JsonNetSerializer
();
JObject
jwtJson
=
WebApiTokenHelper
.
AnalysisToken
(
token
);
IDateTimeProvider
provider
=
new
UtcDateTimeProvider
();
actionContext
.
HttpContext
.
Items
[
Common
.
GlobalKey
.
TokenUserInfo
]
=
jwtJson
[
Common
.
GlobalKey
.
JWT_User_Key
];
IJwtValidator
validator
=
new
JwtValidator
(
serializer
,
provider
);
IBase64UrlEncoder
urlEncoder
=
new
JwtBase64UrlEncoder
();
IJwtDecoder
decoder
=
new
JwtDecoder
(
serializer
,
validator
,
urlEncoder
);
string
secret
=
Common
.
Config
.
JwtSecretKey
;
var
json
=
decoder
.
Decode
(
token
,
secret
,
verify
:
true
);
//token为之前生成的字符串
JObject
jwtJson
=
JObject
.
Parse
(
json
);
actionContext
.
HttpContext
.
Items
[
Common
.
GlobalKey
.
TokenUserInfo
]
=
jwtJson
[
"edu_userInfo"
];
}
}
catch
(
SignatureVerificationException
sve
)
catch
(
SignatureVerificationException
sve
)
{
{
...
...
Edu.WebApi/Helper/WebApiTokenHelper.cs
0 → 100644
View file @
e4105f28
using
Edu.Common.API
;
using
JWT
;
using
JWT.Algorithms
;
using
JWT.Serializers
;
using
Newtonsoft.Json.Linq
;
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Threading.Tasks
;
namespace
Edu.WebApi.Helper
{
/// <summary>
/// Token帮助类
/// </summary>
public
class
WebApiTokenHelper
{
/// <summary>
/// 生成Token
/// </summary>
/// <param name="uid"></param>
/// <param name="requestFromEnum"></param>
/// <returns></returns>
public
static
string
CreateToken
(
string
uid
,
Common
.
Enum
.
ApiRequestFromEnum
requestFromEnum
)
{
TokenUserInfo
userInfo
=
new
TokenUserInfo
{
Uid
=
uid
,
RequestFrom
=
requestFromEnum
};
IDateTimeProvider
provider
=
new
UtcDateTimeProvider
();
var
now
=
provider
.
GetNow
().
AddMinutes
(-
1
);
var
unixEpoch
=
new
DateTime
(
1970
,
1
,
1
,
0
,
0
,
0
,
DateTimeKind
.
Utc
);
var
secondsSinceEpoch
=
Math
.
Round
((
now
-
unixEpoch
).
TotalSeconds
);
var
payload
=
new
Dictionary
<
string
,
object
>
{
{
"iat"
,
secondsSinceEpoch
},
{
"exp"
,
secondsSinceEpoch
+
Common
.
Config
.
JwtExpirTime
},
{
Common
.
GlobalKey
.
JWT_User_Key
,
userInfo
}
};
IJwtAlgorithm
algorithm
=
new
HMACSHA256Algorithm
();
IJsonSerializer
serializer
=
new
JsonNetSerializer
();
IBase64UrlEncoder
urlEncoder
=
new
JwtBase64UrlEncoder
();
IJwtEncoder
encoder
=
new
JwtEncoder
(
algorithm
,
serializer
,
urlEncoder
);
string
secret
=
Common
.
Config
.
JwtSecretKey
;
string
token
=
encoder
.
Encode
(
payload
,
secret
);
return
token
;
}
/// <summary>
/// 解析Token
/// </summary>
/// <param name="token"></param>
/// <returns></returns>
public
static
JObject
AnalysisToken
(
string
token
)
{
IJsonSerializer
serializer
=
new
JsonNetSerializer
();
IDateTimeProvider
provider
=
new
UtcDateTimeProvider
();
IJwtValidator
validator
=
new
JwtValidator
(
serializer
,
provider
);
IBase64UrlEncoder
urlEncoder
=
new
JwtBase64UrlEncoder
();
IJwtDecoder
decoder
=
new
JwtDecoder
(
serializer
,
validator
,
urlEncoder
);
string
secret
=
Common
.
Config
.
JwtSecretKey
;
var
json
=
decoder
.
Decode
(
token
,
secret
,
verify
:
true
);
//token为之前生成的字符串
JObject
jwtJson
=
JObject
.
Parse
(
json
);
return
jwtJson
;
}
}
}
\ No newline at end of file
education.sln
View file @
e4105f28
...
@@ -21,7 +21,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Module", "Module", "{7AC0A4
...
@@ -21,7 +21,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Module", "Module", "{7AC0A4
EndProject
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Edu.Module.User", "Edu.Module.User\Edu.Module.User.csproj", "{1B9D7825-26A9-4F81-B04C-2261CB1F954A}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Edu.Module.User", "Edu.Module.User\Edu.Module.User.csproj", "{1B9D7825-26A9-4F81-B04C-2261CB1F954A}"
EndProject
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Edu.WebApi", "Edu.WebApi\Edu.WebApi.csproj", "{878A03A7-2571-4322-A55E-39A5105296A9}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Edu.WebApi", "Edu.WebApi\Edu.WebApi.csproj", "{878A03A7-2571-4322-A55E-39A5105296A9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Edu.Module.System", "Edu.Module.System\Edu.Module.System.csproj", "{CBA4F637-BB41-4281-BCE8-4BB9BBA3193F}"
EndProject
EndProject
Global
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
GlobalSection(SolutionConfigurationPlatforms) = preSolution
...
@@ -57,6 +59,10 @@ Global
...
@@ -57,6 +59,10 @@ Global
{878A03A7-2571-4322-A55E-39A5105296A9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{878A03A7-2571-4322-A55E-39A5105296A9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{878A03A7-2571-4322-A55E-39A5105296A9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{878A03A7-2571-4322-A55E-39A5105296A9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{878A03A7-2571-4322-A55E-39A5105296A9}.Release|Any CPU.Build.0 = Release|Any CPU
{878A03A7-2571-4322-A55E-39A5105296A9}.Release|Any CPU.Build.0 = Release|Any CPU
{CBA4F637-BB41-4281-BCE8-4BB9BBA3193F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CBA4F637-BB41-4281-BCE8-4BB9BBA3193F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CBA4F637-BB41-4281-BCE8-4BB9BBA3193F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CBA4F637-BB41-4281-BCE8-4BB9BBA3193F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
HideSolutionNode = FALSE
...
@@ -68,6 +74,7 @@ Global
...
@@ -68,6 +74,7 @@ Global
{414497FE-79E2-493F-A7B4-97BEDA956472} = {94CECEE0-E28C-424A-9C8E-8AAE9E4967BD}
{414497FE-79E2-493F-A7B4-97BEDA956472} = {94CECEE0-E28C-424A-9C8E-8AAE9E4967BD}
{539496B1-1377-46AD-A1AB-4473818D6A79} = {94CECEE0-E28C-424A-9C8E-8AAE9E4967BD}
{539496B1-1377-46AD-A1AB-4473818D6A79} = {94CECEE0-E28C-424A-9C8E-8AAE9E4967BD}
{1B9D7825-26A9-4F81-B04C-2261CB1F954A} = {7AC0A4EC-3215-4FF2-96DC-DE8325ED6915}
{1B9D7825-26A9-4F81-B04C-2261CB1F954A} = {7AC0A4EC-3215-4FF2-96DC-DE8325ED6915}
{CBA4F637-BB41-4281-BCE8-4BB9BBA3193F} = {7AC0A4EC-3215-4FF2-96DC-DE8325ED6915}
EndGlobalSection
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {8763B446-FAB1-46BF-9743-F2628533241B}
SolutionGuid = {8763B446-FAB1-46BF-9743-F2628533241B}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment