Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
performance
Overview
Overview
Details
Activity
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zry
performance
Commits
7833a327
Commit
7833a327
authored
Aug 16, 2023
by
ruyun.zhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
登录token信息补充
parent
aae2e5af
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
9 deletions
+45
-9
performance/Performance.Api/Controllers/AccountController.cs
+41
-9
performance/Performance.Api/Util/JwtToken.cs
+4
-0
No files found.
performance/Performance.Api/Controllers/AccountController.cs
View file @
7833a327
using
FluentValidation.AspNetCore
;
using
AngleSharp.Dom
;
using
FluentValidation.AspNetCore
;
using
MassTransit.Internals.Extensions
;
using
Microsoft.AspNetCore.Authorization
;
using
Microsoft.AspNetCore.Authorization
;
using
Microsoft.AspNetCore.Mvc
;
using
Microsoft.AspNetCore.Mvc
;
using
Microsoft.Extensions.Caching.Memory
;
using
Microsoft.Extensions.Caching.Memory
;
using
Microsoft.Extensions.Options
;
using
Microsoft.Extensions.Options
;
using
Newtonsoft.Json
;
using
Performance.DtoModels
;
using
Performance.DtoModels
;
using
Performance.DtoModels.AppSettings
;
using
Performance.DtoModels.AppSettings
;
using
Performance.EntityModels
;
using
Performance.EntityModels
;
...
@@ -66,7 +69,7 @@ public ApiResponse<JwtToken> Login([FromBody] LoginRequest request)
...
@@ -66,7 +69,7 @@ public ApiResponse<JwtToken> Login([FromBody] LoginRequest request)
if
(
user
==
null
)
if
(
user
==
null
)
return
new
ApiResponse
<
JwtToken
>(
ResponseType
.
Fail
,
"用户不存在"
);
return
new
ApiResponse
<
JwtToken
>(
ResponseType
.
Fail
,
"用户不存在"
);
var
claims
=
new
Claim
[]
var
claims
=
new
List
<
Claim
>
{
{
new
Claim
(
JwtClaimTypes
.
Id
,
user
.
UserID
.
ToString
()),
new
Claim
(
JwtClaimTypes
.
Id
,
user
.
UserID
.
ToString
()),
new
Claim
(
JwtClaimTypes
.
Login
,
user
.
Login
),
new
Claim
(
JwtClaimTypes
.
Login
,
user
.
Login
),
...
@@ -75,10 +78,19 @@ public ApiResponse<JwtToken> Login([FromBody] LoginRequest request)
...
@@ -75,10 +78,19 @@ public ApiResponse<JwtToken> Login([FromBody] LoginRequest request)
new
Claim
(
JwtClaimTypes
.
AppName
,
request
.
AppName
??
""
),
new
Claim
(
JwtClaimTypes
.
AppName
,
request
.
AppName
??
""
),
new
Claim
(
JwtClaimTypes
.
Device
,
request
.
Device
??
""
),
new
Claim
(
JwtClaimTypes
.
Device
,
request
.
Device
??
""
),
new
Claim
(
JwtClaimTypes
.
Department
,
user
.
Department
??
""
),
new
Claim
(
JwtClaimTypes
.
Department
,
user
.
Department
??
""
),
new
Claim
(
JwtClaimTypes
.
AccountingUnit
,
user
.
Department
??
""
),
new
Claim
(
JwtClaimTypes
.
JobNumber
,
user
.
Login
??
""
),
new
Claim
(
JwtClaimTypes
.
PersonnelNumber
,
user
.
Login
??
""
),
new
Claim
(
JwtClaimTypes
.
QuickLogin
,
EQuickLogin
.
NO
.
ToString
()),
new
Claim
(
JwtClaimTypes
.
QuickLogin
,
EQuickLogin
.
NO
.
ToString
()),
};
};
var
roles
=
_roleService
.
GetUserRole
(
user
.
UserID
);
if
(
roles
?.
Any
()
==
true
)
{
var
unitTypes
=
UnitTypeUtil
.
Maps
.
GetOrAdd
(
roles
.
First
().
RoleID
,
(
key
)
=>
Array
.
Empty
<
string
>());
claims
.
Add
(
new
Claim
(
JwtClaimTypes
.
UnitType
,
JsonConvert
.
SerializeObject
(
unitTypes
)));
}
var
jwtToken
=
JwtTokenHelper
.
GenerateToken
(
claims
,
_options
.
ExpirationMinutes
);
var
jwtToken
=
JwtTokenHelper
.
GenerateToken
(
claims
.
ToArray
()
,
_options
.
ExpirationMinutes
);
return
new
ApiResponse
<
JwtToken
>(
ResponseType
.
OK
,
jwtToken
);
return
new
ApiResponse
<
JwtToken
>(
ResponseType
.
OK
,
jwtToken
);
}
}
...
@@ -96,7 +108,7 @@ public ApiResponse<JwtToken> QuickLogin([FromBody] ResetPwdRequest request)
...
@@ -96,7 +108,7 @@ public ApiResponse<JwtToken> QuickLogin([FromBody] ResetPwdRequest request)
if
(
user
==
null
)
if
(
user
==
null
)
return
new
ApiResponse
<
JwtToken
>(
ResponseType
.
Fail
,
"用户不存在"
);
return
new
ApiResponse
<
JwtToken
>(
ResponseType
.
Fail
,
"用户不存在"
);
var
claims
=
new
Claim
[]
var
claims
=
new
List
<
Claim
>
{
{
new
Claim
(
JwtClaimTypes
.
Id
,
user
.
UserID
.
ToString
()),
new
Claim
(
JwtClaimTypes
.
Id
,
user
.
UserID
.
ToString
()),
new
Claim
(
JwtClaimTypes
.
Login
,
user
.
Login
),
new
Claim
(
JwtClaimTypes
.
Login
,
user
.
Login
),
...
@@ -105,10 +117,18 @@ public ApiResponse<JwtToken> QuickLogin([FromBody] ResetPwdRequest request)
...
@@ -105,10 +117,18 @@ public ApiResponse<JwtToken> QuickLogin([FromBody] ResetPwdRequest request)
new
Claim
(
JwtClaimTypes
.
AppName
,
request
.
AppName
??
""
),
new
Claim
(
JwtClaimTypes
.
AppName
,
request
.
AppName
??
""
),
new
Claim
(
JwtClaimTypes
.
Device
,
request
.
Device
??
""
),
new
Claim
(
JwtClaimTypes
.
Device
,
request
.
Device
??
""
),
new
Claim
(
JwtClaimTypes
.
Department
,
user
.
Department
??
""
),
new
Claim
(
JwtClaimTypes
.
Department
,
user
.
Department
??
""
),
new
Claim
(
JwtClaimTypes
.
AccountingUnit
,
user
.
Department
??
""
),
new
Claim
(
JwtClaimTypes
.
JobNumber
,
user
.
Login
??
""
),
new
Claim
(
JwtClaimTypes
.
PersonnelNumber
,
user
.
Login
??
""
),
new
Claim
(
JwtClaimTypes
.
QuickLogin
,
EQuickLogin
.
YES
.
ToString
()),
new
Claim
(
JwtClaimTypes
.
QuickLogin
,
EQuickLogin
.
YES
.
ToString
()),
};
};
var
roles
=
_roleService
.
GetUserRole
(
user
.
UserID
);
var
jwtToken
=
JwtTokenHelper
.
GenerateToken
(
claims
,
_options
.
ExpirationMinutes
);
if
(
roles
?.
Any
()
==
true
)
{
var
unitTypes
=
UnitTypeUtil
.
Maps
.
GetOrAdd
(
roles
.
First
().
RoleID
,
(
key
)
=>
Array
.
Empty
<
string
>());
claims
.
Add
(
new
Claim
(
JwtClaimTypes
.
UnitType
,
JsonConvert
.
SerializeObject
(
unitTypes
)));
}
var
jwtToken
=
JwtTokenHelper
.
GenerateToken
(
claims
.
ToArray
(),
_options
.
ExpirationMinutes
);
return
new
ApiResponse
<
JwtToken
>(
ResponseType
.
OK
,
jwtToken
);
return
new
ApiResponse
<
JwtToken
>(
ResponseType
.
OK
,
jwtToken
);
}
}
...
@@ -130,6 +150,10 @@ public ApiResponse<JwtToken> Refresh()
...
@@ -130,6 +150,10 @@ public ApiResponse<JwtToken> Refresh()
new
Claim
(
JwtClaimTypes
.
AppName
,
userClaim
.
FirstOrDefault
(
t
=>
t
.
Type
==
JwtClaimTypes
.
AppName
)?.
Value
??
""
),
new
Claim
(
JwtClaimTypes
.
AppName
,
userClaim
.
FirstOrDefault
(
t
=>
t
.
Type
==
JwtClaimTypes
.
AppName
)?.
Value
??
""
),
new
Claim
(
JwtClaimTypes
.
Device
,
userClaim
.
FirstOrDefault
(
t
=>
t
.
Type
==
JwtClaimTypes
.
Device
)?.
Value
??
""
),
new
Claim
(
JwtClaimTypes
.
Device
,
userClaim
.
FirstOrDefault
(
t
=>
t
.
Type
==
JwtClaimTypes
.
Device
)?.
Value
??
""
),
new
Claim
(
JwtClaimTypes
.
Department
,
userClaim
.
FirstOrDefault
(
t
=>
t
.
Type
==
JwtClaimTypes
.
Department
)?.
Value
??
""
),
new
Claim
(
JwtClaimTypes
.
Department
,
userClaim
.
FirstOrDefault
(
t
=>
t
.
Type
==
JwtClaimTypes
.
Department
)?.
Value
??
""
),
new
Claim
(
JwtClaimTypes
.
AccountingUnit
,
userClaim
.
FirstOrDefault
(
t
=>
t
.
Type
==
JwtClaimTypes
.
AccountingUnit
)?.
Value
??
""
),
new
Claim
(
JwtClaimTypes
.
JobNumber
,
userClaim
.
FirstOrDefault
(
t
=>
t
.
Type
==
JwtClaimTypes
.
JobNumber
)?.
Value
??
""
),
new
Claim
(
JwtClaimTypes
.
PersonnelNumber
,
userClaim
.
FirstOrDefault
(
t
=>
t
.
Type
==
JwtClaimTypes
.
PersonnelNumber
)?.
Value
??
""
),
new
Claim
(
JwtClaimTypes
.
UnitType
,
userClaim
.
FirstOrDefault
(
t
=>
t
.
Type
==
JwtClaimTypes
.
UnitType
)?.
Value
??
""
),
};
};
var
jwtToken
=
JwtTokenHelper
.
GenerateToken
(
claims
,
_options
.
ExpirationMinutes
);
var
jwtToken
=
JwtTokenHelper
.
GenerateToken
(
claims
,
_options
.
ExpirationMinutes
);
...
@@ -260,7 +284,7 @@ public ApiResponse<JwtToken> DemoUsers(int userId)
...
@@ -260,7 +284,7 @@ public ApiResponse<JwtToken> DemoUsers(int userId)
var
user
=
_userService
.
GetDemoUserIdentity
(
userId
);
var
user
=
_userService
.
GetDemoUserIdentity
(
userId
);
var
userClaim
=
_claim
.
GetUserClaim
();
var
userClaim
=
_claim
.
GetUserClaim
();
var
claims
=
new
Claim
[]
var
claims
=
new
List
<
Claim
>
{
{
new
Claim
(
JwtClaimTypes
.
Id
,
user
.
UserID
.
ToString
()),
new
Claim
(
JwtClaimTypes
.
Id
,
user
.
UserID
.
ToString
()),
new
Claim
(
JwtClaimTypes
.
Login
,
user
.
Login
),
new
Claim
(
JwtClaimTypes
.
Login
,
user
.
Login
),
...
@@ -269,9 +293,17 @@ public ApiResponse<JwtToken> DemoUsers(int userId)
...
@@ -269,9 +293,17 @@ public ApiResponse<JwtToken> DemoUsers(int userId)
new
Claim
(
JwtClaimTypes
.
AppName
,
userClaim
.
FirstOrDefault
(
t
=>
t
.
Type
==
JwtClaimTypes
.
AppName
)?.
Value
??
""
),
new
Claim
(
JwtClaimTypes
.
AppName
,
userClaim
.
FirstOrDefault
(
t
=>
t
.
Type
==
JwtClaimTypes
.
AppName
)?.
Value
??
""
),
new
Claim
(
JwtClaimTypes
.
Device
,
userClaim
.
FirstOrDefault
(
t
=>
t
.
Type
==
JwtClaimTypes
.
Device
)?.
Value
??
""
),
new
Claim
(
JwtClaimTypes
.
Device
,
userClaim
.
FirstOrDefault
(
t
=>
t
.
Type
==
JwtClaimTypes
.
Device
)?.
Value
??
""
),
new
Claim
(
JwtClaimTypes
.
Department
,
user
.
Department
??
""
),
new
Claim
(
JwtClaimTypes
.
Department
,
user
.
Department
??
""
),
new
Claim
(
JwtClaimTypes
.
AccountingUnit
,
user
.
Department
??
""
),
new
Claim
(
JwtClaimTypes
.
JobNumber
,
user
.
Login
??
""
),
new
Claim
(
JwtClaimTypes
.
PersonnelNumber
,
user
.
Login
??
""
),
};
};
var
roles
=
_roleService
.
GetUserRole
(
user
.
UserID
);
var
jwtToken
=
JwtTokenHelper
.
GenerateToken
(
claims
,
_options
.
ExpirationMinutes
);
if
(
roles
?.
Any
()
==
true
)
{
var
unitTypes
=
UnitTypeUtil
.
Maps
.
GetOrAdd
(
roles
.
First
().
RoleID
,
(
key
)
=>
Array
.
Empty
<
string
>());
claims
.
Add
(
new
Claim
(
JwtClaimTypes
.
UnitType
,
JsonConvert
.
SerializeObject
(
unitTypes
)));
}
var
jwtToken
=
JwtTokenHelper
.
GenerateToken
(
claims
.
ToArray
(),
_options
.
ExpirationMinutes
);
return
new
ApiResponse
<
JwtToken
>(
ResponseType
.
OK
,
jwtToken
);
return
new
ApiResponse
<
JwtToken
>(
ResponseType
.
OK
,
jwtToken
);
}
}
...
...
performance/Performance.Api/Util/JwtToken.cs
View file @
7833a327
...
@@ -98,6 +98,10 @@ public static class JwtClaimTypes
...
@@ -98,6 +98,10 @@ public static class JwtClaimTypes
public
const
string
Mail
=
"mail"
;
public
const
string
Mail
=
"mail"
;
public
const
string
AppName
=
"appname"
;
public
const
string
AppName
=
"appname"
;
public
const
string
Device
=
"device"
;
public
const
string
Device
=
"device"
;
public
const
string
JobNumber
=
"jobnumber"
;
public
const
string
PersonnelNumber
=
"personnelnumber"
;
public
const
string
UnitType
=
"unittype"
;
public
const
string
AccountingUnit
=
"accountingunit"
;
public
const
string
Department
=
"department"
;
public
const
string
Department
=
"department"
;
public
const
string
QuickLogin
=
"quicklogin"
;
public
const
string
QuickLogin
=
"quicklogin"
;
}
}
...
...
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