Skip to content
This repository was archived by the owner on Aug 1, 2021. It is now read-only.

Commit ecc89b9

Browse files
committed
users claims
1 parent 6942ce0 commit ecc89b9

58 files changed

Lines changed: 13583 additions & 96 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/Backend/Jp.Application/AutoMapper/DomainToViewModelMappingProfile.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using Jp.Domain.Core.Events;
1010
using Jp.Domain.Models;
1111
using System.Globalization;
12+
using System.Security.Claims;
1213

1314
namespace Jp.Application.AutoMapper
1415
{
@@ -24,9 +25,10 @@ public DomainToViewModelMappingProfile()
2425
CreateMap<Client, ClientListViewModel>(MemberList.Destination);
2526
CreateMap<IdentityServer4.EntityFramework.Entities.Secret, SecretViewModel>(MemberList.Destination);
2627
CreateMap<IdentityServer4.EntityFramework.Entities.ClientProperty, ClientPropertyViewModel>();
27-
CreateMap<IdentityServer4.EntityFramework.Entities.ClientClaim, ClientClaimViewModel>();
28+
CreateMap<IdentityServer4.EntityFramework.Entities.ClientClaim, ClaimViewModel>();
2829
CreateMap<IdentityServer4.EntityFramework.Entities.IdentityResource, IdentityResourceListView>(MemberList.Destination);
2930
CreateMap<IdentityServer4.EntityFramework.Entities.ApiScope, ScopeViewModel>(MemberList.Destination);
31+
CreateMap<Claim, ClaimViewModel>(MemberList.Destination);
3032
}
3133
}
3234
}

src/Backend/Jp.Application/AutoMapper/ViewModelToDomainMappingProfile.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
using Jp.Domain.Commands.PersistedGrant;
1212
using Jp.Domain.Commands.User;
1313
using Jp.Domain.Commands.UserManagement;
14-
using System;
1514

1615
namespace Jp.Application.AutoMapper
1716
{
@@ -34,17 +33,17 @@ public ViewModelToDomainMappingProfile()
3433
CreateMap<ResetPasswordViewModel, ResetPasswordCommand>().ConstructUsing(c => new ResetPasswordCommand(c.Password, c.ConfirmPassword, c.Code, c.Email));
3534
CreateMap<ConfirmEmailViewModel, ConfirmEmailCommand>().ConstructUsing(c => new ConfirmEmailCommand(c.Code, c.Email));
3635

37-
3836
/*
3937
* User Management commands
4038
*/
4139
CreateMap<UserViewModel, UpdateProfileCommand>().ConstructUsing(c => new UpdateProfileCommand(c.Id, c.Url, c.Bio, c.Company, c.JobTitle, c.Name, c.PhoneNumber));
4240
CreateMap<UserViewModel, UpdateUserCommand>().ConstructUsing(c => new UpdateUserCommand(c.Email, c.UserName, c.Name, c.PhoneNumber, c.EmailConfirmed, c.PhoneNumberConfirmed, c.TwoFactorEnabled, c.LockoutEnd, c.LockoutEnabled, c.AccessFailedCount));
4341
CreateMap<ProfilePictureViewModel, UpdateProfilePictureCommand>().ConstructUsing(c => new UpdateProfilePictureCommand(c.Id));
44-
4542
CreateMap<ChangePasswordViewModel, ChangePasswordCommand>().ConstructUsing(c => new ChangePasswordCommand(c.Id, c.OldPassword, c.NewPassword, c.ConfirmPassword));
4643
CreateMap<SetPasswordViewModel, SetPasswordCommand>().ConstructUsing(c => new SetPasswordCommand(c.Id, c.NewPassword, c.ConfirmPassword));
4744
CreateMap<RemoveAccountViewModel, RemoveAccountCommand>().ConstructUsing(c => new RemoveAccountCommand(c.Id));
45+
CreateMap<SaveUserClaimViewModel, SaveUserClaimCommand>().ConstructUsing(c => new SaveUserClaimCommand(c.Username, c.Type, c.Value));
46+
CreateMap<RemoveUserClaimViewModel, RemoveUserClaimCommand>().ConstructUsing(c => new RemoveUserClaimCommand(c.Username, c.Type));
4847

4948
/*
5049
* Client commands

src/Backend/Jp.Application/Interfaces/IClientAppService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public interface IClientAppService: IDisposable
1818
Task<IEnumerable<ClientPropertyViewModel>> GetProperties(string clientId);
1919
Task RemoveProperty(RemovePropertyViewModel model);
2020
Task SaveProperty(SaveClientPropertyViewModel model);
21-
Task<IEnumerable<ClientClaimViewModel>> GetClaims(string clientId);
21+
Task<IEnumerable<ClaimViewModel>> GetClaims(string clientId);
2222
Task RemoveClaim(RemoveClientClaimViewModel model);
2323
Task SaveClaim(SaveClientClaimViewModel model);
2424
//Task Save(SaveClientViewModel client);

src/Backend/Jp.Application/Interfaces/IUserManageAppService.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,8 @@ public interface IUserManageAppService : IDisposable
2222
Task<UserViewModel> GetUserAsync(Guid value);
2323
Task UpdateUser(UserViewModel model);
2424

25+
Task<IEnumerable<ClaimViewModel>> GetClaims(string userName);
26+
Task SaveClaim(SaveUserClaimViewModel model);
27+
Task RemoveClaim(RemoveUserClaimViewModel model);
2528
}
2629
}

src/Backend/Jp.Application/Services/ClientAppService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ public Task SaveProperty(SaveClientPropertyViewModel model)
9292
return Bus.SendCommand(registerCommand);
9393
}
9494

95-
public async Task<IEnumerable<ClientClaimViewModel>> GetClaims(string clientId)
95+
public async Task<IEnumerable<ClaimViewModel>> GetClaims(string clientId)
9696
{
97-
return _mapper.Map<IEnumerable<ClientClaimViewModel>>(await _clientClaimRepository.GetByClientId(clientId));
97+
return _mapper.Map<IEnumerable<ClaimViewModel>>(await _clientClaimRepository.GetByClientId(clientId));
9898
}
9999

100100
public Task RemoveClaim(RemoveClientClaimViewModel model)

src/Backend/Jp.Application/Services/UserManagerAppService.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
using Jp.Domain.Commands.UserManagement;
1111
using Jp.Domain.Core.Bus;
1212
using Jp.Domain.Interfaces;
13-
using Jp.Domain.Models;
1413

1514
namespace Jp.Application.Services
1615
{
@@ -107,6 +106,23 @@ public Task UpdateUser(UserViewModel model)
107106
var command = _mapper.Map<UpdateUserCommand>(model);
108107
return Bus.SendCommand(command);
109108
}
109+
110+
public async Task<IEnumerable<ClaimViewModel>> GetClaims(string userName)
111+
{
112+
return _mapper.Map<IEnumerable<ClaimViewModel>>(await _userService.GetClaimByName(userName));
113+
}
114+
115+
public Task SaveClaim(SaveUserClaimViewModel model)
116+
{
117+
var registerCommand = _mapper.Map<SaveUserClaimCommand>(model);
118+
return Bus.SendCommand(registerCommand);
119+
}
120+
121+
public Task RemoveClaim(RemoveUserClaimViewModel model)
122+
{
123+
var registerCommand = _mapper.Map<RemoveUserClaimCommand>(model);
124+
return Bus.SendCommand(registerCommand);
125+
}
110126
}
111127
}
112128

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace Jp.Application.ViewModels
2+
{
3+
public class ClaimViewModel
4+
{
5+
public int Id { get; set; }
6+
public string Type { get; set; }
7+
public string Value { get; set; }
8+
}
9+
}

src/Backend/Jp.Application/ViewModels/ClientsViewModels/ClientClaimViewModel.cs

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System;
2+
3+
namespace Jp.Application.ViewModels.UserViewModels
4+
{
5+
public class RemoveAccountViewModel
6+
{
7+
public Guid? Id { get; set; }
8+
}
9+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System.ComponentModel.DataAnnotations;
2+
3+
namespace Jp.Application.ViewModels.UserViewModels
4+
{
5+
public class RemoveUserClaimViewModel
6+
{
7+
[Required]
8+
public string Type { get; set; }
9+
[Required]
10+
public string Username { get; set; }
11+
}
12+
}

0 commit comments

Comments
 (0)