Пример #1
0
        public async Task <IActionResult> ResetPasswordAsync([FromBody] ResetUserViewModel resetUser)
        {
            var id = _authService.GetUserIdFromRequest(Request.HttpContext.User.Claims);

            resetUser.Id = id;
            var result = await _authService.ResetPasswordAsync(resetUser);

            switch (result.Error)
            {
            case AuthResultType.Wrong:
                return(new ObjectResult(result)
                {
                    StatusCode = StatusCodes.Status401Unauthorized
                });

            case AuthResultType.Error:
                return(BadRequest(result));

            case AuthResultType.Ok:
                return(Ok(result));

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Пример #2
0
        public async Task <ApiResult> ResetPasswordAsync(ResetUserViewModel resetUser)
        {
            var user = await _context.Users.FindAsync(resetUser.Id);

            if (user == null)
            {
                return new ApiResult {
                           Error = AuthResultType.Wrong
                }
            }
            ;
            if (_passwordHasher.VerifyHashedPassword(user, user.PasswordHash, resetUser.Password) !=
                PasswordVerificationResult.Success)
            {
                return new ApiResult {
                           Error = AuthResultType.Wrong
                }
            }
            ;
            user.PasswordHash = _passwordHasher.HashPassword(user, resetUser.NewPassword);
            await _context.SaveChangesAsync();

            return(new ApiResult {
                Error = AuthResultType.Ok
            });
        }