diff --git a/TIAM.Models/Dtos/Users/ChangePasswordDto.cs b/TIAM.Models/Dtos/Users/ChangePasswordDto.cs new file mode 100644 index 00000000..0ef87597 --- /dev/null +++ b/TIAM.Models/Dtos/Users/ChangePasswordDto.cs @@ -0,0 +1,18 @@ +using AyCode.Models.Users; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TIAM.Models.Dtos.Users +{ + public class ChangePasswordDto : AcChangePasswordDto + { + public ChangePasswordDto() : base() + { } + + public ChangePasswordDto(Guid userId, string oldPassword, string newPassword) : base(userId, oldPassword, newPassword) + {} + } +} diff --git a/TIAM.Services.Server.Tests/LoginServices/LoginServiceServerTests.cs b/TIAM.Services.Server.Tests/LoginServices/LoginServiceServerTests.cs index bde2ddef..0f9dcc23 100644 --- a/TIAM.Services.Server.Tests/LoginServices/LoginServiceServerTests.cs +++ b/TIAM.Services.Server.Tests/LoginServices/LoginServiceServerTests.cs @@ -21,6 +21,7 @@ namespace TIAM.Services.Server.Tests.LoginServices private const string RegisterPassword = "elem'r"; private const string RegisterUserIdString = "1f7e0591-330b-463b-81ad-d01f2e65e23e"; + private const string LoginId = "1DED6045-1278-4B92-A10A-3EB9426E41A3"; private const string LoginEmail = "asdfsdf@ggggg.hu"; private const string LoginPassword = "alad'r"; @@ -50,5 +51,10 @@ namespace TIAM.Services.Server.Tests.LoginServices [DataRow([LoginEmail, LoginPassword])] public override void AcBase_LoginUser_ReturnsUser_WhenUserExist(string[] emailPasswordStrings) => 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); } } \ No newline at end of file diff --git a/TIAM.Services/SignalRTags.cs b/TIAM.Services/SignalRTags.cs index c82ccb90..3029e4a8 100644 --- a/TIAM.Services/SignalRTags.cs +++ b/TIAM.Services/SignalRTags.cs @@ -111,6 +111,7 @@ 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 GetAllLogItemsByFilterText = 1000; } diff --git a/TIAMSharedUI/Pages/User/CardComponents/UserCardComponent.razor b/TIAMSharedUI/Pages/User/CardComponents/UserCardComponent.razor index 8537e692..6b04317a 100644 --- a/TIAMSharedUI/Pages/User/CardComponents/UserCardComponent.razor +++ b/TIAMSharedUI/Pages/User/CardComponents/UserCardComponent.razor @@ -82,6 +82,8 @@ } } + public string OldPassword { get; set; } + private string? _confirmNewPassword; public string? ConfirmNewPassword { @@ -126,8 +128,10 @@ isSaveActive = false; - User userToUpdate = new User(Context.Id, Context.UserDto.EmailAddress, NewPassword); - var result = await AdminSignalRClient.PostDataAsync(SignalRTags.UpdateUser, userToUpdate); + var changePasswordDto = new ChangePasswordDto(Context.Id, OldPassword, NewPassword); + //var changePasswordDto = new ChangePasswordDto(Context.Id, "Asdasd123456", NewPassword); + var result = await AdminSignalRClient.PostDataAsync(SignalRTags.ChangeUserPassword, changePasswordDto); + if (result != null) { msg = $"Password saved"; diff --git a/TIAMWebApp/Server/Controllers/UserAPIController.cs b/TIAMWebApp/Server/Controllers/UserAPIController.cs index 9484a85f..ebd01c5c 100644 --- a/TIAMWebApp/Server/Controllers/UserAPIController.cs +++ b/TIAMWebApp/Server/Controllers/UserAPIController.cs @@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json.Linq; using System.Security.Claims; using System.Text.Json; +using AyCode.Core.Consts; using AyCode.Core.Extensions; using TIAMWebApp.Shared.Application.Models; using TIAMWebApp.Shared.Application.Models.PageModels; @@ -18,9 +19,11 @@ using ILogger = TIAM.Core.Loggers.ILogger; using AyCode.Core.Helpers; using AyCode.Entities; using AyCode.Services.SignalRs; +using TIAM.Models.Server.Logins; using TIAM.Services; using TIAM.Services.Interfaces; using TIAMWebApp.Shared.Application.Services; +using GoogleApi.Entities.Search.Video.Common; namespace TIAMWebApp.Server.Controllers { @@ -337,6 +340,21 @@ namespace TIAMWebApp.Server.Controllers return await userDal.UpdateUserAsync(user); } + [NonAction] + [SignalR(SignalRTags.ChangeUserPassword)] + public async Task ChangeUserPassword([FromBody] ChangePasswordDto changePasswordDto) + { + _logger.Info("ChangeUserPassword called"); + + var errorCode = await _loginService.ChangePasswordAsync(changePasswordDto.UserId, changePasswordDto.OldPassword, changePasswordDto.NewPassword); + + if (errorCode == AcErrorCode.Unset) + return await userDal.GetUserModelDtoByIdAsync(changePasswordDto.UserId, true); + + _logger.Error($"ErrorCode: {errorCode}; userId: {changePasswordDto.UserId}"); + return null; + } + [NonAction] [SignalR(SignalRTags.UpdateUserModelDtoDetail)] public async Task UpdateUserModelDtoDetail(UserModelDtoDetail userModelDtoDetail)