コード例 #1
0
ファイル: UserService.cs プロジェクト: rogeriobatista/users
        public async Task <string> Recover(RecoverUserPasswordDto recoverDto)
        {
            if (!await _userRepository.Exist(recoverDto.Email))
            {
                throw new Exception(StringResource.ValidationMessageUserDontExists);
            }

            User user = await _userRepository.GetByEmailAsync(recoverDto.Email);

            user.UpdatePassword(recoverDto.Password);

            if (!user.Validate())
            {
                throw new ArgumentException(StringResource.ValidationMessageInvalidUser);
            }

            _userRepository.Update(user);

            return(StringResource.RecoverMessageSuccess);
        }
コード例 #2
0
        public async Task <ActionResult> Recover([FromServices] ITokenHelper tokenHelper, [FromBody] RecoverUserPasswordDto recoverDto, string token)
        {
            try
            {
                if (string.IsNullOrEmpty(token) || !tokenHelper.Validate(token))
                {
                    return(Unauthorized());
                }

                return(Ok(await _userService.Recover(recoverDto)));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }