ChangePassword
This commit is contained in:
parent
a7bee0bd1d
commit
67ae0e18e0
|
|
@ -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)
|
||||
{}
|
||||
}
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -79,6 +79,8 @@
|
|||
}
|
||||
}
|
||||
|
||||
public string OldPassword { get; set; }
|
||||
|
||||
private string? _confirmNewPassword;
|
||||
public string? ConfirmNewPassword
|
||||
{
|
||||
|
|
@ -123,8 +125,10 @@
|
|||
|
||||
isSaveActive = false;
|
||||
|
||||
User userToUpdate = new User(Context.Id, Context.UserDto.EmailAddress, NewPassword);
|
||||
var result = await AdminSignalRClient.PostDataAsync<User>(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";
|
||||
|
|
|
|||
|
|
@ -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<UserModelDtoDetail?> 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<UserModelDtoDetail>(changePasswordDto.UserId, true);
|
||||
|
||||
_logger.Error($"ErrorCode: {errorCode}; userId: {changePasswordDto.UserId}");
|
||||
return null;
|
||||
}
|
||||
|
||||
[NonAction]
|
||||
[SignalR(SignalRTags.UpdateUserModelDtoDetail)]
|
||||
public async Task<UserModelDtoDetail?> UpdateUserModelDtoDetail(UserModelDtoDetail userModelDtoDetail)
|
||||
|
|
|
|||
Loading…
Reference in New Issue