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

Commit b3e7cb5

Browse files
committed
Users
1 parent 379b6cd commit b3e7cb5

68 files changed

Lines changed: 19321 additions & 255 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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public DomainToViewModelMappingProfile()
3030
CreateMap<IdentityServer4.EntityFramework.Entities.ApiScope, ScopeViewModel>(MemberList.Destination);
3131
CreateMap<Claim, ClaimViewModel>(MemberList.Destination);
3232
CreateMap<Role, RoleViewModel>(MemberList.Destination);
33+
CreateMap<UserLogin, UserLoginViewModel>(MemberList.Destination);
3334
}
3435
}
3536
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public ViewModelToDomainMappingProfile()
4646
CreateMap<RemoveUserClaimViewModel, RemoveUserClaimCommand>().ConstructUsing(c => new RemoveUserClaimCommand(c.Username, c.Type));
4747
CreateMap<RemoveUserRoleViewModel, RemoveUserRoleCommand>().ConstructUsing(c => new RemoveUserRoleCommand(c.Username, c.Role));
4848
CreateMap<SaveUserRoleViewModel, SaveUserRoleCommand>().ConstructUsing(c => new SaveUserRoleCommand(c.Username, c.Role));
49+
CreateMap<RemoveUserLoginViewModel, RemoveUserLoginCommand>().ConstructUsing(c => new RemoveUserLoginCommand(c.Username, c.LoginProvider, c.ProviderKey));
4950

5051
/*
5152
* Client commands
@@ -55,7 +56,6 @@ public ViewModelToDomainMappingProfile()
5556
CreateMap<RemovePropertyViewModel, RemovePropertyCommand>().ConstructUsing(c => new RemovePropertyCommand(c.Id, c.ClientId));
5657
CreateMap<SaveClientSecretViewModel, SaveClientSecretCommand>().ConstructUsing(c => new SaveClientSecretCommand(c.ClientId, c.Description, c.Value, c.Type, c.Expiration, (int)c.Hash.GetValueOrDefault(HashType.Sha256)));
5758
CreateMap<SaveClientPropertyViewModel, SaveClientPropertyCommand>().ConstructUsing(c => new SaveClientPropertyCommand(c.ClientId, c.Key, c.Value));
58-
5959
CreateMap<SaveClientClaimViewModel, SaveClientClaimCommand>().ConstructUsing(c => new SaveClientClaimCommand(c.ClientId, c.Type, c.Value));
6060
CreateMap<RemoveClientClaimViewModel, RemoveClientClaimCommand>().ConstructUsing(c => new RemoveClientClaimCommand(c.Id, c.ClientId));
6161
CreateMap<RemoveClientViewModel, RemoveClientCommand>().ConstructUsing(c => new RemoveClientCommand(c.ClientId));
@@ -70,8 +70,8 @@ public ViewModelToDomainMappingProfile()
7070
CreateMap<RemoveIdentityResourceViewModel, RemoveIdentityResourceCommand>().ConstructUsing(c => new RemoveIdentityResourceCommand(c.Name));
7171

7272
/*
73-
* Api Resource commands
74-
*/
73+
* Api Resource commands
74+
*/
7575
CreateMap<ApiResource, RegisterApiResourceCommand>().ConstructUsing(c => new RegisterApiResourceCommand(c));
7676
CreateMap<ApiResource, UpdateApiResourceCommand>().ConstructUsing(c => new UpdateApiResourceCommand(c));
7777
CreateMap<RemoveApiResourceViewModel, RemoveApiResourceCommand>().ConstructUsing(c => new RemoveApiResourceCommand(c.Name));

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@ public interface IClientAppService: IDisposable
2525
Task Save(SaveClientViewModel client);
2626
Task Remove(RemoveClientViewModel client);
2727
Task Copy(CopyClientViewModel client);
28+
Task<Client> GetClientDefaultDetails(string clientId);
2829
}
2930
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,7 @@ public interface IUserManageAppService : IDisposable
2828
Task<IEnumerable<RoleViewModel>> GetRoles(string userName);
2929
Task RemoveRole(RemoveUserRoleViewModel model);
3030
Task SaveRole(SaveUserRoleViewModel model);
31+
Task<IEnumerable<UserLoginViewModel>> GetLogins(string userName);
32+
Task RemoveLogin(RemoveUserLoginViewModel model);
3133
}
3234
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,12 @@ public Task Copy(CopyClientViewModel client)
127127
return Bus.SendCommand(command);
128128
}
129129

130+
public async Task<Client> GetClientDefaultDetails(string clientId)
131+
{
132+
var resultado = await _clientRepository.GetClientDefaultDetails(clientId);
133+
return _mapper.Map<Client>(resultado);
134+
}
135+
130136
public void Dispose()
131137
{
132138
GC.SuppressFinalize(this);

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,18 @@ public Task SaveRole(SaveUserRoleViewModel model)
142142
var registerCommand = _mapper.Map<SaveUserRoleCommand>(model);
143143
return Bus.SendCommand(registerCommand);
144144
}
145+
146+
public async Task<IEnumerable<UserLoginViewModel>> GetLogins(string userName)
147+
{
148+
return _mapper.Map<IEnumerable<UserLoginViewModel>>(await _userService.GetUserLogins(userName));
149+
}
150+
151+
public Task RemoveLogin(RemoveUserLoginViewModel model)
152+
{
153+
var registerCommand = _mapper.Map<RemoveUserLoginCommand>(model);
154+
return Bus.SendCommand(registerCommand);
155+
}
156+
145157
}
146158
}
147159

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System.ComponentModel.DataAnnotations;
2+
3+
namespace Jp.Application.ViewModels.UserViewModels
4+
{
5+
public class RemoveUserLoginViewModel
6+
{
7+
[Required]
8+
public string Username { get; set; }
9+
[Required]
10+
public string LoginProvider { get; set; }
11+
[Required]
12+
public string ProviderKey { get; set; }
13+
}
14+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace Jp.Application.ViewModels.UserViewModels
2+
{
3+
public class UserLoginViewModel
4+
{
5+
public string LoginProvider { get; set; }
6+
public string ProviderDisplayName { get; set; }
7+
public string ProviderKey { get; set; }
8+
}
9+
}

src/Backend/Jp.Domain/CommandHandlers/UserManagementCommandHandler.cs

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ public class UserManagementCommandHandler : CommandHandler,
2121
IRequestHandler<UpdateUserCommand>,
2222
IRequestHandler<SaveUserClaimCommand>,
2323
IRequestHandler<RemoveUserClaimCommand>,
24-
IRequestHandler<RemoveUserRoleCommand>
24+
IRequestHandler<RemoveUserRoleCommand>,
25+
IRequestHandler<SaveUserRoleCommand>
2526
{
2627
private readonly IUserService _userService;
2728
private readonly ISystemUser _user;
@@ -200,5 +201,51 @@ public async Task Handle(RemoveUserRoleCommand request, CancellationToken cancel
200201
await Bus.RaiseEvent(new UserRoleRemovedEvent(_user.UserId, request.Username, request.Role));
201202
}
202203
}
204+
205+
public async Task Handle(SaveUserRoleCommand request, CancellationToken cancellationToken)
206+
{
207+
if (!request.IsValid())
208+
{
209+
NotifyValidationErrors(request);
210+
return;
211+
}
212+
213+
var user = await _userService.FindByNameAsync(request.Username);
214+
if (user == null)
215+
{
216+
await Bus.RaiseEvent(new DomainNotification("1", "User not found"));
217+
return;
218+
}
219+
220+
var success = await _userService.SaveRole(user.Id, request.Role);
221+
222+
if (success)
223+
{
224+
await Bus.RaiseEvent(new UserRoleSavedEvent(_user.UserId, request.Username, request.Role));
225+
}
226+
}
227+
228+
public async Task Handle(RemoveUserLoginCommand request, CancellationToken cancellationToken)
229+
{
230+
if (!request.IsValid())
231+
{
232+
NotifyValidationErrors(request);
233+
return;
234+
}
235+
236+
var user = await _userService.FindByNameAsync(request.Username);
237+
if (user == null)
238+
{
239+
await Bus.RaiseEvent(new DomainNotification("1", "User not found"));
240+
return;
241+
}
242+
243+
var success = await _userService.RemoveLogin(user.Id, request.LoginProvider, request.ProviderKey);
244+
245+
if (success)
246+
{
247+
await Bus.RaiseEvent(new UserLoginRemovedEvent(_user.UserId, request.Username, request.LoginProvider, request.ProviderKey));
248+
}
249+
}
203250
}
204251
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using Jp.Domain.Validations.User;
2+
3+
namespace Jp.Domain.Commands.User
4+
{
5+
public class RemoveUserLoginCommand : UserLoginCommand
6+
{
7+
public RemoveUserLoginCommand(string username, string loginProvider, string providerKey)
8+
{
9+
LoginProvider = loginProvider;
10+
ProviderKey = providerKey;
11+
Username = username;
12+
}
13+
public override bool IsValid()
14+
{
15+
ValidationResult = new RemoveUserLoginCommandValidation().Validate(this);
16+
return ValidationResult.IsValid;
17+
}
18+
}
19+
}

0 commit comments

Comments
 (0)