Exemple #1
0
        public async Task <ActionResult> ResetPassword(UserPasswordEditorVM vm)
        {
            CheckPasswordAuth();

            try
            {
                await _users.ResetPasswordAsync(vm);

                return(RedirectToSuccess("Пароль изменен"));
            }
            catch (ValidationException ex)
            {
                SetModelState(ex);
                return(await ViewResetPasswordFormAsync(vm.Id));
            }
        }
Exemple #2
0
        /// <summary>
        /// Resets the user's password.
        /// </summary>
        public async Task ResetPasswordAsync(UserPasswordEditorVM vm)
        {
            ValidatePasswordForm(vm);

            var user = await _db.Users.GetAsync(x => x.Id == vm.Id, "Пользователь не найден");

            var token = await _userMgr.GeneratePasswordResetTokenAsync(user);

            var result = await _userMgr.ResetPasswordAsync(user, token, vm.Password);

            if (!result.Succeeded)
            {
                throw new OperationException("Не удалось сменить пароль, попробуйте еще раз.");
            }

            await _userMgr.SetLockoutEndDateAsync(user, null);
        }