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

Commit 6942ce0

Browse files
committed
logins
1 parent be6c3a8 commit 6942ce0

36 files changed

Lines changed: 11257 additions & 68 deletions

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
using IdentityServer4.Models;
33
using Jp.Application.EventSourcedNormalizers;
44
using Jp.Application.ViewModels;
5+
using Jp.Application.ViewModels.ApiResouceViewModels;
56
using Jp.Application.ViewModels.ClientsViewModels;
67
using Jp.Application.ViewModels.IdentityResourceViewModels;
8+
using Jp.Application.ViewModels.UserViewModels;
79
using Jp.Domain.Core.Events;
810
using Jp.Domain.Models;
911
using System.Globalization;
10-
using Jp.Application.ViewModels.ApiResouceViewModels;
11-
using Jp.Application.ViewModels.UserViewModels;
1212

1313
namespace Jp.Application.AutoMapper
1414
{
@@ -17,7 +17,9 @@ public class DomainToViewModelMappingProfile : Profile
1717
public DomainToViewModelMappingProfile()
1818
{
1919
CreateMap<ApiResource, ApiResourceListViewModel>();
20-
CreateMap<User, UserViewModel>(MemberList.Destination);
20+
CreateMap<User, UserViewModel>(MemberList.Destination);//.ForMember(x => x.LockoutEnd, opt => opt.MapFrom(src => src.LockoutEnd != null ? src.LockoutEnd.Value.DateTime.ToShortDateString() : string.Empty));
21+
CreateMap<User, UserListViewModel>(MemberList.Destination);
22+
2123
CreateMap<StoredEvent, EventHistoryData>().ConstructUsing(a => new EventHistoryData() { Action = a.MessageType, Id = a.Id.ToString(), Details = a.Data, When = a.Timestamp.ToString(CultureInfo.InvariantCulture), Who = a.User });
2224
CreateMap<Client, ClientListViewModel>(MemberList.Destination);
2325
CreateMap<IdentityServer4.EntityFramework.Entities.Secret, SecretViewModel>(MemberList.Destination);

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

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

1516
namespace Jp.Application.AutoMapper
1617
{
@@ -38,6 +39,7 @@ public ViewModelToDomainMappingProfile()
3839
* User Management commands
3940
*/
4041
CreateMap<UserViewModel, UpdateProfileCommand>().ConstructUsing(c => new UpdateProfileCommand(c.Id, c.Url, c.Bio, c.Company, c.JobTitle, c.Name, c.PhoneNumber));
42+
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));
4143
CreateMap<ProfilePictureViewModel, UpdateProfilePictureCommand>().ConstructUsing(c => new UpdateProfilePictureCommand(c.Id));
4244

4345
CreateMap<ChangePasswordViewModel, ChangePasswordCommand>().ConstructUsing(c => new ChangePasswordCommand(c.Id, c.OldPassword, c.NewPassword, c.ConfirmPassword));

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
using System;
2-
using System.Threading.Tasks;
3-
using Jp.Application.ViewModels;
1+
using Jp.Application.ViewModels;
42
using Jp.Application.ViewModels.UserViewModels;
5-
using Jp.Domain.Models;
3+
using System;
4+
using System.Threading.Tasks;
65

76
namespace Jp.Application.Interfaces
87
{

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ public interface IUserManageAppService : IDisposable
1717
Task RemoveAccount(RemoveAccountViewModel model);
1818
Task<bool> HasPassword(Guid userId);
1919
IEnumerable<EventHistoryData> GetHistoryLogs(Guid value);
20-
Task<IEnumerable<UserViewModel>> GetUsers();
20+
Task<IEnumerable<UserListViewModel>> GetUsers();
2121
Task<UserViewModel> GetUserDetails(string username);
2222
Task<UserViewModel> GetUserAsync(Guid value);
23+
Task UpdateUser(UserViewModel model);
24+
2325
}
2426
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ public async Task<RegisterUserViewModel> FindByLoginAsync(string provider, strin
9898
return _mapper.Map<RegisterUserViewModel>(model);
9999
}
100100

101+
101102

102103
public void Dispose()
103104
{

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Jp.Application.Interfaces;
77
using Jp.Application.ViewModels;
88
using Jp.Application.ViewModels.UserViewModels;
9+
using Jp.Domain.Commands.User;
910
using Jp.Domain.Commands.UserManagement;
1011
using Jp.Domain.Core.Bus;
1112
using Jp.Domain.Interfaces;
@@ -83,10 +84,10 @@ public IEnumerable<EventHistoryData> GetHistoryLogs(Guid id)
8384
return history;
8485
}
8586

86-
public async Task<IEnumerable<UserViewModel>> GetUsers()
87+
public async Task<IEnumerable<UserListViewModel>> GetUsers()
8788
{
8889
var users = await _userService.GetUsers();
89-
return _mapper.Map<IEnumerable<UserViewModel>>(users);
90+
return _mapper.Map<IEnumerable<UserListViewModel>>(users);
9091
}
9192

9293
public async Task<UserViewModel> GetUserDetails(string username)
@@ -100,6 +101,12 @@ public async Task<UserViewModel> GetUserAsync(Guid value)
100101
var users = await _userService.GetUserAsync(value);
101102
return _mapper.Map<UserViewModel>(users);
102103
}
104+
105+
public Task UpdateUser(UserViewModel model)
106+
{
107+
var command = _mapper.Map<UpdateUserCommand>(model);
108+
return Bus.SendCommand(command);
109+
}
103110
}
104111
}
105112

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System.ComponentModel.DataAnnotations;
2+
3+
namespace Jp.Application.ViewModels.UserViewModels
4+
{
5+
public class UserListViewModel
6+
{
7+
[Required]
8+
[EmailAddress]
9+
[Display(Name = "Email")]
10+
public string Email { get; set; }
11+
12+
public string Name { get; set; }
13+
14+
[Display(Name = "Picture")]
15+
public string Picture { get; set; }
16+
17+
[Display(Name = "UserName")]
18+
public string UserName { get; set; }
19+
}
20+
}

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,19 @@ public class UserViewModel
1010
[Display(Name = "Email")]
1111
public string Email { get; set; }
1212

13-
[Phone]
14-
[Display(Name = "Telephone")]
15-
public string PhoneNumber { get; set; }
13+
[Phone] [Display(Name = "Telephone")] public string PhoneNumber { get; set; }
1614

1715
[Required]
1816
[Display(Name = "Username")]
1917
public string Name { get; set; }
2018

2119

22-
[Display(Name = "Picture")]
23-
public string Picture { get; set; }
20+
[Display(Name = "Picture")] public string Picture { get; set; }
2421

2522
[Required]
2623
[Display(Name = "Username")]
2724
public string UserName { get; set; }
25+
2826
public string Url { get; set; }
2927
public string Company { get; set; }
3028
public string Bio { get; set; }

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ public async Task Handle(ConfirmEmailCommand request, CancellationToken cancella
137137
if (result.HasValue)
138138
await Bus.RaiseEvent(new EmailConfirmedEvent(request.Email, request.Code, result.Value));
139139
}
140+
140141
}
141142

142143

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

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Threading;
22
using System.Threading.Tasks;
3+
using Jp.Domain.Commands.User;
34
using Jp.Domain.Commands.UserManagement;
45
using Jp.Domain.Core.Bus;
56
using Jp.Domain.Core.Notifications;
@@ -14,7 +15,8 @@ public class UserManagementCommandHandler : CommandHandler,
1415
IRequestHandler<UpdateProfilePictureCommand>,
1516
IRequestHandler<SetPasswordCommand>,
1617
IRequestHandler<ChangePasswordCommand>,
17-
IRequestHandler<RemoveAccountCommand>
18+
IRequestHandler<RemoveAccountCommand>,
19+
IRequestHandler<UpdateUserCommand>
1820
{
1921
private readonly IUserService _userService;
2022

@@ -92,5 +94,32 @@ public async Task Handle(RemoveAccountCommand request, CancellationToken cancell
9294
if (result)
9395
await Bus.RaiseEvent(new AccountRemovedEvent(request.Id.Value));
9496
}
97+
98+
99+
public async Task Handle(UpdateUserCommand request, CancellationToken cancellationToken)
100+
{
101+
if (!request.IsValid())
102+
{
103+
NotifyValidationErrors(request);
104+
return;
105+
}
106+
107+
var user = await _userService.FindByNameAsync(request.Username);
108+
if (user == null)
109+
{
110+
await Bus.RaiseEvent(new DomainNotification("1", "User not found"));
111+
return;
112+
}
113+
user.Email = request.Email;
114+
user.EmailConfirmed = request.EmailConfirmed;
115+
user.AccessFailedCount = request.AccessFailedCount;
116+
user.LockoutEnabled = request.LockoutEnabled;
117+
user.LockoutEnd = request.LockoutEnd;
118+
user.Name = request.Name;
119+
user.TwoFactorEnabled = request.TwoFactorEnabled;
120+
user.PhoneNumber = request.PhoneNumber;
121+
user.PhoneNumberConfirmed = request.PhoneNumberConfirmed;
122+
await _userService.UpdateUserAsync(user);
123+
}
95124
}
96125
}

0 commit comments

Comments
 (0)