示例#1
0
        public async Task <IActionResult> ResetPassword(
            [FromBody] ResetPasswordDTO resetPasswordModel)
        {
            if (string.IsNullOrWhiteSpace(resetPasswordModel.Token) ||
                string.IsNullOrWhiteSpace(resetPasswordModel.Email))
            {
                return(BadRequest("Can not reset password, invalid token or email"));
            }

            var user = await accountBusiness.FindUserAsync(resetPasswordModel.Email);

            if (user is null)
            {
                return(BadRequest("Can not reset password for invalid user."));
            }

            // reset password
            var response =
                await accountBusiness.ResetPasswordAsync(resetPasswordModel.NewPassword,
                                                         resetPasswordModel.Token,
                                                         user);

            if (!response.Succeeded)
            {
                var errors = response.Errors.Select(x => x.Description).ToList();

                return(BadRequest(errors));
            }

            return(Ok());
        }