Exemple #1
0
        public async Task <IActionResult> ChangePassword([FromBody] UserDtoChangePassword userDtoChangePassword)
        {
            var authorizationResult = await GetAuthorizationResult(userDtoChangePassword.Id);

            if (authorizationResult.Succeeded)
            {
                await _userService.ChangePassword(userDtoChangePassword);

                return(Ok());
            }

            return(Forbid());
        }
Exemple #2
0
        public async Task ChangePassword(UserDtoChangePassword changePasswordDto)
        {
            var user = await _userRepository.FindByIdFirstAsync(changePasswordDto.Id);

            if (user == null)
            {
                throw new ResourceNotFoundException("User with id: " + changePasswordDto.Id + " not found");
            }

            ValidatePasswordsAreTheSameFromForm(changePasswordDto.Password, changePasswordDto.RepeatedPassword);

            user = ChangePasswordForUser(user, changePasswordDto.OldPassword, changePasswordDto.Password);

            _userRepository.Edit(user);

            await _userRepository.SaveAsync();
        }