This commit is contained in:
Adam 2024-08-04 19:19:00 +02:00
commit 332c0a2d56
7 changed files with 40 additions and 9 deletions

View File

@ -8,6 +8,7 @@ namespace TIAM.Entities.Users;
public interface IUser : IAcUser<Profile, Company, UserToCompany, Address>, IUserDto<Profile, Company, UserToCompany>, IUserBase
{
public string? ConfirmToken { get; set; }
public List<Product> Products { get; }
//public ServiceProvider ServiceProvider { get; set; }

View File

@ -10,10 +10,12 @@ namespace TIAM.Entities.Users
[Table("Users")]
public class User : AcUser<Profile, Company, UserToCompany, Address>, IUser, IUserDtoDetail
{
public virtual List<Product> Products { get; set; } = new();
public string? ConfirmToken { get; set; }
public virtual List<Product> Products { get; set; } = [];
//public virtual ServiceProvider ServiceProvider { get; set; } = new();
public virtual List<UserProductMapping> UserProductMappings { get; set; } = new();
public virtual List<UserProductMapping> UserProductMappings { get; set; } = [];
public User() { }
public User(string email, string password) : this(Guid.NewGuid(), email, password) { }

View File

@ -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)
{}
}

View File

@ -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);
}
}

View File

@ -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;
}

View File

@ -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)
{

View File

@ -341,8 +341,8 @@ namespace TIAMWebApp.Server.Controllers
}
[NonAction]
[SignalR(SignalRTags.ChangeUserPassword)]
public async Task<UserModelDtoDetail?> ChangeUserPassword([FromBody] ChangePasswordDto changePasswordDto)
[SignalR(SignalRTags.UserChangePassword)]
public async Task<UserModelDtoDetail?> 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<UserModelDtoDetail?> 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<UserModelDtoDetail>(forgotPasswordDto.Email, true);
_logger.Error($"ErrorCode: {errorCode}; email: {forgotPasswordDto.Email}");
return null;
}
[NonAction]
[SignalR(SignalRTags.UpdateUserModelDtoDetail)]
public async Task<UserModelDtoDetail?> UpdateUserModelDtoDetail(UserModelDtoDetail userModelDtoDetail)