public async Task <IActionResult> ConfirmResettingPassword([FromBody] ConfirmResetPasswordModel model)
        {
            var user = await _accountService.ConfirmResetPassword(model);

            var token = await _tokenService.GenerateToken(user);

            var response = new
            {
                access_token = token,
                user         = _mapper.Map <CurrentUserViewModel>(user)
            };

            return(Json(response));
        }
Exemple #2
0
        public ActionResult ConfirmResetPassword(ConfirmResetPasswordModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to reset password
                bool succeed = UserAuthenticationService.ConfirmResetPassword(model.Username, model.VerifyToken, model.NewPassword);

                if (succeed)
                {
                    FormsService.SignIn(model.Username, false /* createPersistentCookie */);
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "Unable to reset password. Please contact administrator.");
                }
            }
            return(View(model));
        }
Exemple #3
0
        public async Task <User> ConfirmResetPassword(ConfirmResetPasswordModel model)
        {
            var user = await _userManager.FindByIdAsync(model.Id.ToString());

            if (user == null)
            {
                throw new ApiException(404, "User id not found", ErrorCode.NotFound);
            }

            if (model.NewPassword != model.PasswordConfirmation)
            {
                throw new ApiException(400, "Passwords don't match", ErrorCode.ValidationError);
            }

            var correctToken = Url.DecodeQueryParamValue(model.Token);
            var result       = await _userManager.ResetPasswordAsync(user, correctToken, model.NewPassword);

            ErrorResultsHandler.ThrowIfIdentityError(result);
            return(user);
        }