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

Commit 3fdaa90

Browse files
committed
admin ui 1.0
1 parent 9b225cc commit 3fdaa90

84 files changed

Lines changed: 24327 additions & 277 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/ViewModelToDomainMappingProfile.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ public ViewModelToDomainMappingProfile()
4949
CreateMap<RemoveUserRoleViewModel, RemoveUserRoleCommand>().ConstructUsing(c => new RemoveUserRoleCommand(c.Username, c.Role));
5050
CreateMap<SaveUserRoleViewModel, SaveUserRoleCommand>().ConstructUsing(c => new SaveUserRoleCommand(c.Username, c.Role));
5151
CreateMap<RemoveUserLoginViewModel, RemoveUserLoginCommand>().ConstructUsing(c => new RemoveUserLoginCommand(c.Username, c.LoginProvider, c.ProviderKey));
52-
52+
CreateMap<AdminChangePasswordViewodel, AdminChangePasswordCommand>().ConstructUsing(c => new AdminChangePasswordCommand(c.Password, c.ConfirmPassword, c.Username));
53+
5354
/*
5455
* Client commands
5556
*/

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public interface IUserManageAppService : IDisposable
1717
Task CreatePassword(SetPasswordViewModel model);
1818
Task RemoveAccount(RemoveAccountViewModel model);
1919
Task<bool> HasPassword(Guid userId);
20-
IEnumerable<EventHistoryData> GetHistoryLogs(Guid value);
20+
Task<IEnumerable<EventHistoryData>> GetHistoryLogs(string username);
2121
Task<IEnumerable<UserListViewModel>> GetUsers();
2222
Task<UserViewModel> GetUserDetails(string username);
2323
Task<UserViewModel> GetUserAsync(Guid value);
@@ -32,5 +32,6 @@ public interface IUserManageAppService : IDisposable
3232
Task<IEnumerable<UserLoginViewModel>> GetLogins(string userName);
3333
Task RemoveLogin(RemoveUserLoginViewModel model);
3434
Task<IEnumerable<UserListViewModel>> GetUsersInRole(string[] role);
35+
Task ResetPassword(AdminChangePasswordViewodel model);
3536
}
3637
}

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Jp.Application.EventSourcedNormalizers;
33
using Jp.Application.Interfaces;
44
using Jp.Application.ViewModels;
5+
using Jp.Application.ViewModels.RoleViewModels;
56
using Jp.Application.ViewModels.UserViewModels;
67
using Jp.Domain.Commands.User;
78
using Jp.Domain.Commands.UserManagement;
@@ -11,7 +12,6 @@
1112
using System.Collections.Generic;
1213
using System.Linq;
1314
using System.Threading.Tasks;
14-
using Jp.Application.ViewModels.RoleViewModels;
1515

1616
namespace Jp.Application.Services
1717
{
@@ -79,10 +79,10 @@ public Task<bool> HasPassword(Guid userId)
7979
return _userService.HasPassword(userId);
8080
}
8181

82-
public IEnumerable<EventHistoryData> GetHistoryLogs(Guid id)
82+
public async Task<IEnumerable<EventHistoryData>> GetHistoryLogs(string username)
8383
{
84-
var history = _mapper.Map<IEnumerable<EventHistoryData>>(_eventStoreRepository.All(id));
85-
return history;
84+
var history = await _eventStoreRepository.All(username);
85+
return _mapper.Map<IEnumerable<EventHistoryData>>(history);
8686
}
8787

8888
public async Task<IEnumerable<UserListViewModel>> GetUsers()
@@ -159,6 +159,12 @@ public async Task<IEnumerable<UserListViewModel>> GetUsersInRole(string[] role)
159159
{
160160
return _mapper.Map<IEnumerable<UserListViewModel>>(await _userService.GetUserFromRole(role));
161161
}
162+
163+
public Task ResetPassword(AdminChangePasswordViewodel model)
164+
{
165+
var registerCommand = _mapper.Map<AdminChangePasswordCommand>(model);
166+
return Bus.SendCommand(registerCommand);
167+
}
162168
}
163169
}
164170

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System.ComponentModel.DataAnnotations;
2+
3+
namespace Jp.Application.ViewModels.UserViewModels
4+
{
5+
public class AdminChangePasswordViewodel
6+
{
7+
[Required]
8+
[Display(Name = "Username")]
9+
public string Username { get; set; }
10+
11+
[Required]
12+
[StringLength(100, ErrorMessage = "The {0} must be at least {2} and at max {1} characters long.", MinimumLength = 6)]
13+
[DataType(DataType.Password)]
14+
[Display(Name = "New password")]
15+
public string Password { get; set; }
16+
17+
[DataType(DataType.Password)]
18+
[Display(Name = "Confirm new password")]
19+
[Compare("Password", ErrorMessage = "The new password and confirmation password do not match.")]
20+
public string ConfirmPassword { get; set; }
21+
}
22+
}

src/Backend/Jp.Application/ViewModels/UserViewModels/ChangePasswordViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class ChangePasswordViewModel
1818

1919
[DataType(DataType.Password)]
2020
[Display(Name = "Confirm new password")]
21-
[Compare("NewPassword", ErrorMessage = "The new password and confirmation password do not match.")]
21+
[Compare("Password", ErrorMessage = "The new password and confirmation password do not match.")]
2222
public string ConfirmPassword { get; set; }
2323

2424
public string StatusMessage { get; set; }

src/Backend/Jp.Application/ViewModels/UserViewModels/SetPasswordViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class SetPasswordViewModel
1313

1414
[DataType(DataType.Password)]
1515
[Display(Name = "Confirm new password")]
16-
[Compare("NewPassword", ErrorMessage = "The new password and confirmation password do not match.")]
16+
[Compare("Password", ErrorMessage = "The new password and confirmation password do not match.")]
1717
public string ConfirmPassword { get; set; }
1818

1919
public string StatusMessage { get; set; }

src/Backend/Jp.Domain.Core/Events/Message.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace Jp.Domain.Core.Events
66
public abstract class Message : IRequest
77
{
88
public string MessageType { get; protected set; }
9-
public Guid AggregateId { get; protected set; }
9+
public string AggregateId { get; protected set; }
1010

1111
protected Message()
1212
{

src/Backend/Jp.Domain.Core/Events/StoredEvent.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ namespace Jp.Domain.Core.Events
44
{
55
public class StoredEvent : Event
66
{
7-
public StoredEvent(Event theEvent, string data, string user)
7+
public StoredEvent(Event theEvent, string data, string userId)
88
{
99
Id = Guid.NewGuid();
1010
AggregateId = theEvent.AggregateId;
1111
MessageType = theEvent.MessageType;
1212
Data = data;
13-
User = user;
13+
User = userId;
1414
}
1515

1616
// EF Constructor

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ public class UserManagementCommandHandler : CommandHandler,
2222
IRequestHandler<SaveUserClaimCommand>,
2323
IRequestHandler<RemoveUserClaimCommand>,
2424
IRequestHandler<RemoveUserRoleCommand>,
25-
IRequestHandler<SaveUserRoleCommand>
25+
IRequestHandler<SaveUserRoleCommand>,
26+
IRequestHandler<AdminChangePasswordCommand>
2627
{
2728
private readonly IUserService _userService;
2829
private readonly ISystemUser _user;
@@ -247,5 +248,28 @@ public async Task Handle(RemoveUserLoginCommand request, CancellationToken cance
247248
await Bus.RaiseEvent(new UserLoginRemovedEvent(_user.UserId, request.Username, request.LoginProvider, request.ProviderKey));
248249
}
249250
}
251+
252+
public async Task Handle(AdminChangePasswordCommand request, CancellationToken cancellationToken)
253+
{
254+
if (!request.IsValid())
255+
{
256+
NotifyValidationErrors(request);
257+
return;
258+
}
259+
260+
var user = await _userService.FindByNameAsync(request.Username);
261+
if (user == null)
262+
{
263+
await Bus.RaiseEvent(new DomainNotification("1", "User not found"));
264+
return;
265+
}
266+
267+
var success = await _userService.ResetPasswordAsync(request.Username, request.Password);
268+
269+
if (success)
270+
{
271+
await Bus.RaiseEvent(new AdminChangedPasswordEvent(user.Id, request.Username));
272+
}
273+
}
250274
}
251275
}
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 AdminChangePasswordCommand : UserCommand
6+
{
7+
public AdminChangePasswordCommand(string password, string changePassword, string username)
8+
{
9+
Username = username;
10+
Password = password;
11+
ConfirmPassword = changePassword;
12+
}
13+
public override bool IsValid()
14+
{
15+
ValidationResult = new AdminChangePasswordCommandValidation().Validate(this);
16+
return ValidationResult.IsValid;
17+
}
18+
}
19+
}

0 commit comments

Comments
 (0)