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

Commit be6c3a8

Browse files
committed
editing user
refactor user and Identity
1 parent d604440 commit be6c3a8

39 files changed

Lines changed: 7044 additions & 110 deletions

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Jp.Domain.Models;
99
using System.Globalization;
1010
using Jp.Application.ViewModels.ApiResouceViewModels;
11+
using Jp.Application.ViewModels.UserViewModels;
1112

1213
namespace Jp.Application.AutoMapper
1314
{
@@ -16,7 +17,7 @@ public class DomainToViewModelMappingProfile : Profile
1617
public DomainToViewModelMappingProfile()
1718
{
1819
CreateMap<ApiResource, ApiResourceListViewModel>();
19-
CreateMap<User, UserViewModel>().ForMember(a => a.Password, o => o.Ignore()).ForMember(a => a.ConfirmPassword, o => o.Ignore());
20+
CreateMap<User, UserViewModel>(MemberList.Destination);
2021
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 });
2122
CreateMap<Client, ClientListViewModel>(MemberList.Destination);
2223
CreateMap<IdentityServer4.EntityFramework.Entities.Secret, SecretViewModel>(MemberList.Destination);

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Jp.Application.ViewModels.ApiResouceViewModels;
55
using Jp.Application.ViewModels.ClientsViewModels;
66
using Jp.Application.ViewModels.IdentityResourceViewModels;
7+
using Jp.Application.ViewModels.UserViewModels;
78
using Jp.Domain.Commands.ApiResource;
89
using Jp.Domain.Commands.Client;
910
using Jp.Domain.Commands.IdentityResource;
@@ -25,9 +26,9 @@ public ViewModelToDomainMappingProfile()
2526
/*
2627
* User Creation Commands
2728
*/
28-
CreateMap<UserViewModel, RegisterNewUserCommand>().ConstructUsing(c => new RegisterNewUserCommand(c.Username, c.Email, c.Name, c.PhoneNumber, c.Password, c.ConfirmPassword));
29+
CreateMap<RegisterUserViewModel, RegisterNewUserCommand>().ConstructUsing(c => new RegisterNewUserCommand(c.Username, c.Email, c.Name, c.PhoneNumber, c.Password, c.ConfirmPassword));
2930
CreateMap<SocialViewModel, RegisterNewUserWithoutPassCommand>(MemberList.Source).ConstructUsing(c => new RegisterNewUserWithoutPassCommand(c.Email, c.Email, c.Name, c.Picture, c.Provider, c.ProviderId));
30-
CreateMap<UserViewModel, RegisterNewUserWithProviderCommand>().ConstructUsing(c => new RegisterNewUserWithProviderCommand(c.Username, c.Email, c.Name, c.PhoneNumber, c.Password, c.ConfirmPassword, c.Picture, c.Provider, c.ProviderId));
31+
CreateMap<RegisterUserViewModel, RegisterNewUserWithProviderCommand>().ConstructUsing(c => new RegisterNewUserWithProviderCommand(c.Username, c.Email, c.Name, c.PhoneNumber, c.Password, c.ConfirmPassword, c.Picture, c.Provider, c.ProviderId));
3132
CreateMap<ForgotPasswordViewModel, SendResetLinkCommand>().ConstructUsing(c => new SendResetLinkCommand(c.UsernameOrEmail, c.UsernameOrEmail));
3233
CreateMap<ResetPasswordViewModel, ResetPasswordCommand>().ConstructUsing(c => new ResetPasswordCommand(c.Password, c.ConfirmPassword, c.Code, c.Email));
3334
CreateMap<ConfirmEmailViewModel, ConfirmEmailCommand>().ConstructUsing(c => new ConfirmEmailCommand(c.Code, c.Email));
@@ -36,7 +37,7 @@ public ViewModelToDomainMappingProfile()
3637
/*
3738
* User Management commands
3839
*/
39-
CreateMap<ProfileViewModel, UpdateProfileCommand>().ConstructUsing(c => new UpdateProfileCommand(c.Id, c.Url, c.Bio, c.Company, c.JobTitle, c.Name, c.PhoneNumber));
40+
CreateMap<UserViewModel, UpdateProfileCommand>().ConstructUsing(c => new UpdateProfileCommand(c.Id, c.Url, c.Bio, c.Company, c.JobTitle, c.Name, c.PhoneNumber));
4041
CreateMap<ProfilePictureViewModel, UpdateProfilePictureCommand>().ConstructUsing(c => new UpdateProfilePictureCommand(c.Id));
4142

4243
CreateMap<ChangePasswordViewModel, ChangePasswordCommand>().ConstructUsing(c => new ChangePasswordCommand(c.Id, c.OldPassword, c.NewPassword, c.ConfirmPassword));
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
using System;
22
using System.Threading.Tasks;
33
using Jp.Application.ViewModels;
4+
using Jp.Application.ViewModels.UserViewModels;
5+
using Jp.Domain.Models;
46

57
namespace Jp.Application.Interfaces
68
{
79
public interface IUserAppService : IDisposable
810
{
9-
Task Register(UserViewModel model);
11+
Task Register(RegisterUserViewModel model);
1012
Task RegisterWithoutPassword(SocialViewModel model);
1113
Task<bool> CheckUsername(string userName);
1214
Task<bool> CheckEmail(string email);
13-
Task<UserViewModel> FindByLoginAsync(string provider, string providerUserId);
14-
Task RegisterWithProvider(UserViewModel model);
15+
Task<RegisterUserViewModel> FindByLoginAsync(string provider, string providerUserId);
16+
Task RegisterWithProvider(RegisterUserViewModel model);
1517
Task SendResetLink(ForgotPasswordViewModel model);
1618
Task ResetPassword(ResetPasswordViewModel model);
1719
Task ConfirmEmail(ConfirmEmailViewModel model);
20+
Task<UserViewModel> FindByNameAsync(string username);
21+
Task<UserViewModel> FindByEmailAsync(string username);
22+
Task<UserViewModel> FindByProviderAsync(string provider, string providerUserId);
1823
}
1924
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,22 @@
33
using System.Threading.Tasks;
44
using Jp.Application.EventSourcedNormalizers;
55
using Jp.Application.ViewModels;
6+
using Jp.Application.ViewModels.UserViewModels;
7+
using Jp.Domain.Models;
68

79
namespace Jp.Application.Interfaces
810
{
911
public interface IUserManageAppService : IDisposable
1012
{
11-
Task UpdateProfile(ProfileViewModel model);
13+
Task UpdateProfile(UserViewModel model);
1214
Task UpdateProfilePicture(ProfilePictureViewModel model);
1315
Task ChangePassword(ChangePasswordViewModel model);
1416
Task CreatePassword(SetPasswordViewModel model);
1517
Task RemoveAccount(RemoveAccountViewModel model);
1618
Task<bool> HasPassword(Guid userId);
1719
IEnumerable<EventHistoryData> GetHistoryLogs(Guid value);
20+
Task<IEnumerable<UserViewModel>> GetUsers();
21+
Task<UserViewModel> GetUserDetails(string username);
22+
Task<UserViewModel> GetUserAsync(Guid value);
1823
}
1924
}

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

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
using System;
2-
using System.Threading.Tasks;
3-
using AutoMapper;
1+
using AutoMapper;
42
using Jp.Application.Interfaces;
53
using Jp.Application.ViewModels;
4+
using Jp.Application.ViewModels.UserViewModels;
65
using Jp.Domain.Commands.User;
76
using Jp.Domain.Core.Bus;
87
using Jp.Domain.Interfaces;
8+
using Jp.Domain.Models;
9+
using System;
10+
using System.Threading.Tasks;
911

1012
namespace Jp.Application.Services
1113
{
@@ -27,7 +29,7 @@ public UserAppService(IMapper mapper,
2729
_eventStoreRepository = eventStoreRepository;
2830
}
2931

30-
public Task Register(UserViewModel model)
32+
public Task Register(RegisterUserViewModel model)
3133
{
3234
var registerCommand = _mapper.Map<RegisterNewUserCommand>(model);
3335
return Bus.SendCommand(registerCommand);
@@ -38,7 +40,7 @@ public Task RegisterWithoutPassword(SocialViewModel model)
3840
var registerCommand = _mapper.Map<RegisterNewUserWithoutPassCommand>(model);
3941
return Bus.SendCommand(registerCommand);
4042
}
41-
public Task RegisterWithProvider(UserViewModel model)
43+
public Task RegisterWithProvider(RegisterUserViewModel model)
4244
{
4345
var registerCommand = _mapper.Map<RegisterNewUserWithProviderCommand>(model);
4446
return Bus.SendCommand(registerCommand);
@@ -62,6 +64,24 @@ public Task ConfirmEmail(ConfirmEmailViewModel model)
6264
return Bus.SendCommand(registerCommand);
6365
}
6466

67+
public async Task<UserViewModel> FindByNameAsync(string username)
68+
{
69+
var user = await _userService.FindByNameAsync(username);
70+
return _mapper.Map<UserViewModel>(user);
71+
}
72+
73+
public async Task<UserViewModel> FindByEmailAsync(string username)
74+
{
75+
var user = await _userService.FindByEmailAsync(username);
76+
return _mapper.Map<UserViewModel>(user);
77+
}
78+
79+
public async Task<UserViewModel> FindByProviderAsync(string provider, string providerUserId)
80+
{
81+
var user = await _userService.FindByProviderAsync(provider, providerUserId);
82+
return _mapper.Map<UserViewModel>(user);
83+
}
84+
6585
public Task<bool> CheckUsername(string userName)
6686
{
6787
return _userService.UsernameExist(userName);
@@ -72,10 +92,10 @@ public Task<bool> CheckEmail(string email)
7292
return _userService.EmailExist(email);
7393
}
7494

75-
public async Task<UserViewModel> FindByLoginAsync(string provider, string providerUserId)
95+
public async Task<RegisterUserViewModel> FindByLoginAsync(string provider, string providerUserId)
7696
{
7797
var model = await _userService.FindByLoginAsync(provider, providerUserId);
78-
return _mapper.Map<UserViewModel>(model);
98+
return _mapper.Map<RegisterUserViewModel>(model);
7999
}
80100

81101

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
using Jp.Application.EventSourcedNormalizers;
66
using Jp.Application.Interfaces;
77
using Jp.Application.ViewModels;
8+
using Jp.Application.ViewModels.UserViewModels;
89
using Jp.Domain.Commands.UserManagement;
910
using Jp.Domain.Core.Bus;
1011
using Jp.Domain.Interfaces;
12+
using Jp.Domain.Models;
1113

1214
namespace Jp.Application.Services
1315
{
@@ -39,7 +41,7 @@ public void Dispose()
3941
GC.SuppressFinalize(this);
4042
}
4143

42-
public Task UpdateProfile(ProfileViewModel model)
44+
public Task UpdateProfile(UserViewModel model)
4345
{
4446
var registerCommand = _mapper.Map<UpdateProfileCommand>(model);
4547
return Bus.SendCommand(registerCommand);
@@ -80,6 +82,24 @@ public IEnumerable<EventHistoryData> GetHistoryLogs(Guid id)
8082
var history = _mapper.Map<IEnumerable<EventHistoryData>>(_eventStoreRepository.All(id));
8183
return history;
8284
}
85+
86+
public async Task<IEnumerable<UserViewModel>> GetUsers()
87+
{
88+
var users = await _userService.GetUsers();
89+
return _mapper.Map<IEnumerable<UserViewModel>>(users);
90+
}
91+
92+
public async Task<UserViewModel> GetUserDetails(string username)
93+
{
94+
var users = await _userService.FindByNameAsync(username);
95+
return _mapper.Map<UserViewModel>(users);
96+
}
97+
98+
public async Task<UserViewModel> GetUserAsync(Guid value)
99+
{
100+
var users = await _userService.GetUserAsync(value);
101+
return _mapper.Map<UserViewModel>(users);
102+
}
83103
}
84104
}
85105

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System;
22
using System.ComponentModel.DataAnnotations;
33

4-
namespace Jp.Application.ViewModels
4+
namespace Jp.Application.ViewModels.UserViewModels
55
{
66
public class ChangePasswordViewModel
77
{

src/Backend/Jp.Application/ViewModels/ConfirmEmailViewModel.cs renamed to src/Backend/Jp.Application/ViewModels/UserViewModels/ConfirmEmailViewModel.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System.ComponentModel.DataAnnotations;
2-
using Jp.Domain.Core.Models;
32

4-
namespace Jp.Application.ViewModels
3+
namespace Jp.Application.ViewModels.UserViewModels
54
{
65
public class ConfirmEmailViewModel
76
{

src/Backend/Jp.Application/ViewModels/ForgotPasswordViewModel.cs renamed to src/Backend/Jp.Application/ViewModels/UserViewModels/ForgotPasswordViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System.ComponentModel.DataAnnotations;
22

3-
namespace Jp.Application.ViewModels
3+
namespace Jp.Application.ViewModels.UserViewModels
44
{
55
public class ForgotPasswordViewModel
66
{

src/Backend/Jp.Application/ViewModels/UserViewModel.cs renamed to src/Backend/Jp.Application/ViewModels/UserViewModels/RegisterUserViewModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
using System;
22
using System.ComponentModel.DataAnnotations;
33

4-
namespace Jp.Application.ViewModels
4+
namespace Jp.Application.ViewModels.UserViewModels
55
{
6-
public class UserViewModel
6+
public class RegisterUserViewModel
77
{
88
public Guid Id { get; set; }
99

0 commit comments

Comments
 (0)