protected override Task <RequestStatus> HandleCommand(ChangePasswordCommand request, CancellationToken cancellationToken) { var userAuthData = _authenticationDataRepository.FindUserAuthById(request.SignedInUser.UserId); if (userAuthData == null) { throw new UserNotFoundException($"Cannot find {request.SignedInUser.UserId} user"); } userAuthData.Password = request.NewPassword; _authenticationDataRepository.UpdateUserAuth(userAuthData); _logger.LogDebug("User {user} has changed password", request.SignedInUser.UserId); var response = RequestStatus.CreateFromCommandContext(request.CommandContext, Status.COMPLETED); return(Task.FromResult(response)); }
protected override Task <RequestStatus> HandleCommand(ResetPasswordCommand request, CancellationToken cancellationToken) { var resetCode = FindResetCode(request); var user = FindUserAuthenticationData(resetCode, request); if (resetCode.IsExpired) { _resetPasswordCodeRepository.RemoveResetPasswordCode(resetCode.ResetCode, resetCode.Email); return(Task.FromResult(RequestStatus.CreateFromCommandContext(request.CommandContext, Status.FAILED))); } if (!resetCode.Checked) { throw new InvalidCommandException("ResetCode must be checked first"); } user.Password = request.NewPassword; _userAuthenticationDataRepository.UpdateUserAuth(user); _logger.LogInformation("User with email {email} and reset code {@resetCode} has changed password", request.Email, resetCode); return(Task.FromResult(RequestStatus.CreateFromCommandContext(request.CommandContext, Status.COMPLETED))); }