Exemplo n.º 1
0
        public async Task EditPassword(UserEditPasswordUICommand command)
        {
            var userId = _userAuthenticationManager.CurrentUser.UserId;

            var user = await _userRepository.Get(userId);

            var originHashedPassword =
                PasswordHasher.Hash(Guid.Parse(user.Salt).ToByteArray(), command.UserPassword.OriginPassword);

            if (user.Password != originHashedPassword)
            {
                throw new LogicServiceException(ErrorMessage.OriginPasswordInvalidate);
            }
            if (command.UserPassword.NewPassword != command.UserPassword.ConfirmedNewPassword)
            {
                throw new LogicServiceException(ErrorMessage.ConfirmedNewPasswordError);
            }

            var newHashedPassword = PasswordHasher.HashedPassword(command.UserPassword.NewPassword);

            user.EditPassword(newHashedPassword.Salt, newHashedPassword.Hash,
                              userId, _timeSource.GetCurrentTime());

            using var unitOfWork = _unitOfWorkFactory.GetCurrentUnitOfWork();
            _userRepository.Edit(user);
            await unitOfWork.Commit();
        }
 public async Task UpdatePassword([FromBody] UserEditPasswordUICommand command)
 {
     await _userLogicService.EditPassword(command);
 }