File tree 7 files changed +76
-8
lines changed
LeaveManagement.Common/Constants
7 files changed +76
-8
lines changed Original file line number Diff line number Diff line change
1
+ using System ;
2
+ using System . Collections . Generic ;
3
+ using System . Linq ;
4
+ using System . Text ;
5
+ using System . Threading . Tasks ;
6
+
7
+ namespace LeaveManagement . Common . Constants
8
+ {
9
+ public static class UserClaims
10
+ {
11
+ public const string Email = "email" ;
12
+ public const string FullName = "fullName" ;
13
+ }
14
+ }
Original file line number Diff line number Diff line change
1
+ {
2
+ "version" : 1 ,
3
+ "isRoot" : true ,
4
+ "tools" : {
5
+ "dotnet-ef" : {
6
+ "version" : " 7.0.7" ,
7
+ "commands" : [
8
+ " dotnet-ef"
9
+ ]
10
+ }
11
+ }
12
+ }
Original file line number Diff line number Diff line change 7
7
using Microsoft . AspNetCore . Identity . UI . Services ;
8
8
using Microsoft . EntityFrameworkCore ;
9
9
using Serilog ;
10
+ using LeaveManagement . Web . Services . Identity ;
10
11
11
12
var builder = WebApplication . CreateBuilder ( args ) ;
12
13
18
19
19
20
builder . Services . AddDefaultIdentity < Employee > ( options => options . SignIn . RequireConfirmedAccount = true )
20
21
. AddRoles < IdentityRole > ( )
21
- . AddEntityFrameworkStores < ApplicationDbContext > ( ) ;
22
+ . AddEntityFrameworkStores < ApplicationDbContext > ( )
23
+ . AddClaimsPrincipalFactory < CustomClaimService > ( ) ;
22
24
23
25
builder . Services . AddHttpContextAccessor ( ) ;
24
26
Original file line number Diff line number Diff line change
1
+ using LeaveManagement . Common . Constants ;
2
+ using LeaveManagement . Data ;
3
+ using Microsoft . AspNetCore . Identity ;
4
+ using Microsoft . Extensions . Options ;
5
+ using System . Security . Claims ;
6
+
7
+ namespace LeaveManagement . Web . Services . Identity
8
+ {
9
+ public class CustomClaimService : UserClaimsPrincipalFactory < Employee >
10
+ {
11
+
12
+ public CustomClaimService (
13
+ UserManager < Employee > userManager ,
14
+ IOptions < IdentityOptions > optionsAccessor ) : base ( userManager , optionsAccessor )
15
+ {
16
+ }
17
+
18
+ protected override async Task < ClaimsIdentity > GenerateClaimsAsync ( Employee user )
19
+ {
20
+ var identity = await base . GenerateClaimsAsync ( user ) ;
21
+ identity . AddClaim ( new Claim ( UserClaims . FullName , $ "{ user . FirstName } { user . LastName } ") ) ;
22
+ identity . AddClaim ( new Claim ( UserClaims . Email , user . Email ) ) ;
23
+ foreach ( var role in await UserManager . GetRolesAsync ( user ) )
24
+ {
25
+ identity . AddClaim ( new Claim ( ClaimTypes . Role , role ) ) ;
26
+ }
27
+ return identity ;
28
+ }
29
+ }
30
+
31
+ }
Original file line number Diff line number Diff line change 80
80
<li >
81
81
@if (SignInManager .IsSignedIn (User ))
82
82
{
83
- var user = await UserManager .GetUserAsync (User );
84
83
<div class =" user-profile d-flex no-block dropdown m-t-20" >
85
84
<div class =" user-pic" >
86
85
<img src =" ~/images/users/1.jpg" alt =" users"
87
86
class =" rounded-circle" width =" 40" />
88
87
</div >
89
88
<div class =" user-content hide-menu m-l-10" >
90
- <h5 class =" m-b-0 user-name font-medium" >
91
- @user.FirstName @user.LastName
92
- </h5 >
93
- <span style =" display : block " class =" op-5 user-email" >
94
- @user.Email </span >
95
- <span style =" display : block " class =" op-5 user-email" >@User.FindFirstValue(ClaimTypes.Role) </span >
89
+ <h5 class =" m-b-0 user-name font-medium" >
90
+ @User.FindFirstValue(UserClaims.FullName)
91
+ </h5 >
92
+ <span style =" display : block " class =" op-5 user-email" >
93
+ @User.FindFirstValue(UserClaims.Email)
94
+ </span >
95
+ <span style =" display : block " class =" op-5 user-email" >@User.FindFirstValue(ClaimTypes.Role) </span >
96
96
</div >
97
97
</div >
98
98
}
Original file line number Diff line number Diff line change 1
1
{
2
+ "ConnectionStrings" : {
3
+ "DefaultConnection" : " Server=(localdb)\\ mssqllocaldb;Database=LeaveManagementNet7;Trusted_Connection=True;MultipleActiveResultSets=true"
4
+ }
2
5
}
Original file line number Diff line number Diff line change
1
+ {
2
+ "ConnectionStrings" : {
3
+ "DefaultConnection" : " Server=localhost\\ SQLEXPRESS;Database=LeaveManagementNet7;Trusted_Connection=True;MultipleActiveResultSets=true;Encrypt=False"
4
+ //"DefaultConnection": "Server=localhost\SQLEXPRESS;Database=master;Trusted_Connection=True;"
5
+ }
6
+ }
You can’t perform that action at this time.
0 commit comments