diff --git a/TIAM.Entities/Users/IUser.cs b/TIAM.Entities/Users/IUser.cs index be979b7a..18a204f9 100644 --- a/TIAM.Entities/Users/IUser.cs +++ b/TIAM.Entities/Users/IUser.cs @@ -8,6 +8,7 @@ namespace TIAM.Entities.Users; public interface IUser : IAcUser, IUserDto, IUserBase { + public string? ConfirmToken { get; set; } public List Products { get; } //public ServiceProvider ServiceProvider { get; set; } diff --git a/TIAM.Entities/Users/User.cs b/TIAM.Entities/Users/User.cs index e87f542a..3249bf1d 100644 --- a/TIAM.Entities/Users/User.cs +++ b/TIAM.Entities/Users/User.cs @@ -10,10 +10,12 @@ namespace TIAM.Entities.Users [Table("Users")] public class User : AcUser, IUser, IUserDtoDetail { - public virtual List Products { get; set; } = new(); + public string? ConfirmToken { get; set; } + + public virtual List Products { get; set; } = []; //public virtual ServiceProvider ServiceProvider { get; set; } = new(); - public virtual List UserProductMappings { get; set; } = new(); + public virtual List UserProductMappings { get; set; } = []; public User() { } public User(string email, string password) : this(Guid.NewGuid(), email, password) { } diff --git a/TIAM.Models/Dtos/Users/ForgotPasswordDto.cs b/TIAM.Models/Dtos/Users/ForgotPasswordDto.cs new file mode 100644 index 00000000..72fff76f --- /dev/null +++ b/TIAM.Models/Dtos/Users/ForgotPasswordDto.cs @@ -0,0 +1,12 @@ +using AyCode.Models.Users; + +namespace TIAM.Models.Dtos.Users; + +public class ForgotPasswordDto : AcForgotPasswordDto +{ + public ForgotPasswordDto() : base() + { } + + public ForgotPasswordDto(string email, string newPassword) : base(email, newPassword) + {} +} \ No newline at end of file diff --git a/TIAM.Services.Server.Tests/LoginServices/LoginServiceServerTests.cs b/TIAM.Services.Server.Tests/LoginServices/LoginServiceServerTests.cs index 0f9dcc23..f9e918a3 100644 --- a/TIAM.Services.Server.Tests/LoginServices/LoginServiceServerTests.cs +++ b/TIAM.Services.Server.Tests/LoginServices/LoginServiceServerTests.cs @@ -53,8 +53,8 @@ namespace TIAM.Services.Server.Tests.LoginServices => base.AcBase_LoginUser_ReturnsUser_WhenUserExist(emailPasswordStrings); [DataTestMethod] - [DataRow([LoginId, LoginPassword, "asdfgh123", "$bcrypt$v=1$salt=JwptfNI6bXd7qKOJDChlvQ==$hash=j4CEfDeibKFWFGUOzxGICyHm3/hA+71j7qoyPDUk1qY="])] - public override void AcBase_ChangePassword_ReturnUser_WhenUserLoggedInWithNewPassword(string[] userIdOldPasswordNewPasswordDbBackupHashStrings) - => base.AcBase_ChangePassword_ReturnUser_WhenUserLoggedInWithNewPassword(userIdOldPasswordNewPasswordDbBackupHashStrings); + [DataRow([LoginId, LoginPassword, "asdfgh123456"])]//, "$bcrypt$v=1$salt=JwptfNI6bXd7qKOJDChlvQ==$hash=j4CEfDeibKFWFGUOzxGICyHm3/hA+71j7qoyPDUk1qY="])] + public override void AcBase_ChangePassword_ReturnUser_WhenUserLoggedInWithNewPassword(string[] userIdOriginalPasswordNewPasswordStrings) + => base.AcBase_ChangePassword_ReturnUser_WhenUserLoggedInWithNewPassword(userIdOriginalPasswordNewPasswordStrings); } } \ No newline at end of file diff --git a/TIAM.Services/SignalRTags.cs b/TIAM.Services/SignalRTags.cs index 3029e4a8..32bb6e69 100644 --- a/TIAM.Services/SignalRTags.cs +++ b/TIAM.Services/SignalRTags.cs @@ -111,7 +111,8 @@ public class SignalRTags : AcSignalRTags public const int AddUserModelDtoDetail = 131; public const int UpdateUser = 135; public const int UpdateUserModelDtoDetail = 136; - public const int ChangeUserPassword = 139; + public const int UserChangePassword = 139; + public const int UserForgotPassword = 140; public const int GetAllLogItemsByFilterText = 1000; } diff --git a/TIAMSharedUI/Pages/User/CardComponents/UserCardComponent.razor b/TIAMSharedUI/Pages/User/CardComponents/UserCardComponent.razor index b53b4c8f..51822316 100644 --- a/TIAMSharedUI/Pages/User/CardComponents/UserCardComponent.razor +++ b/TIAMSharedUI/Pages/User/CardComponents/UserCardComponent.razor @@ -129,7 +129,7 @@ var changePasswordDto = new ChangePasswordDto(Context.Id, OldPassword, NewPassword); //var changePasswordDto = new ChangePasswordDto(Context.Id, "Asdasd123456", NewPassword); - var result = await AdminSignalRClient.PostDataAsync(SignalRTags.ChangeUserPassword, changePasswordDto); + var result = await AdminSignalRClient.PostDataAsync(SignalRTags.UserChangePassword, changePasswordDto); if (result != null) { diff --git a/TIAMWebApp/Server/Controllers/UserAPIController.cs b/TIAMWebApp/Server/Controllers/UserAPIController.cs index ebd01c5c..c78f519a 100644 --- a/TIAMWebApp/Server/Controllers/UserAPIController.cs +++ b/TIAMWebApp/Server/Controllers/UserAPIController.cs @@ -341,8 +341,8 @@ namespace TIAMWebApp.Server.Controllers } [NonAction] - [SignalR(SignalRTags.ChangeUserPassword)] - public async Task ChangeUserPassword([FromBody] ChangePasswordDto changePasswordDto) + [SignalR(SignalRTags.UserChangePassword)] + public async Task UserChangePassword([FromBody] ChangePasswordDto changePasswordDto) { _logger.Info("ChangeUserPassword called"); @@ -355,6 +355,21 @@ namespace TIAMWebApp.Server.Controllers return null; } + [NonAction] + [SignalR(SignalRTags.UserForgotPassword)] + public async Task UserForgotPassword([FromBody] ForgotPasswordDto forgotPasswordDto) + { + _logger.Info("UserForgotPassword called"); + + var errorCode = await _loginService.ForgotPasswordAsync(forgotPasswordDto.Email, forgotPasswordDto.NewPassword); + + if (errorCode == AcErrorCode.Unset) + return await userDal.GetUserModelDtoByEmailAsync(forgotPasswordDto.Email, true); + + _logger.Error($"ErrorCode: {errorCode}; email: {forgotPasswordDto.Email}"); + return null; + } + [NonAction] [SignalR(SignalRTags.UpdateUserModelDtoDetail)] public async Task UpdateUserModelDtoDetail(UserModelDtoDetail userModelDtoDetail)