Beispiel #1
0
        public IActionResult ChangePassword(ChangePasswordViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            UserData user = _authentication.GetUserByAssociatedUser(User);

            if (user == null)
            {
                throw new ApplicationException($"Unable to load user with ID '{_authentication.GetUserId(User)}'.");
            }

            AuthResult changePasswordResult = _authentication.ChangedPassword(User, model.OldPassword, model.NewPassword);

            if (!changePasswordResult.Succeded)
            {
                AddErrors(changePasswordResult);
                return(View(model));
            }

            _logger.LogInformation("User changed their password successfully.");
            StatusMessage = "Your password has been changed.";

            return(RedirectToAction(nameof(ChangePassword)));
        }