Пример #1
0
        public async Task <ActionResult> ResetPassword(ResetPasswordInputModel model)
        {
            //model.OldPassword = "";
#if DEBUG
            Debug.WriteLine("UserName="******"Password="******"ConfirmPassword="******"OldPassword="******"Id=" + model.Id.ToString());
#endif
            if (ModelState.IsValid)
            {
#if DEBUG
                Debug.WriteLine("Model is valid");
#endif
                var user = await _userManager.FindByNameAsync(model.UserName);

                if (user != null)
                {
#if DEBUG
                    Debug.WriteLine("user is not null");
#endif

                    /*
                     * var checkOldPassword =await _userManager.CheckPasswordAsync(user, model.OldPassword);
                     *
                     * if (checkOldPassword)
                     * { */
                    var result = await _userManager.RemovePasswordAsync(user.UserID);

                    if (result.Succeeded)
                    {
#if DEBUG
                        Debug.WriteLine("Password is removed to succeeded");
#endif
                        var result2 = await _userManager.AddPasswordAsync(user.UserID, model.Password);

                        if (result2.Succeeded)
                        {
#if DEBUG
                            Debug.WriteLine("Password is added to succeeded");
#endif
                            var result3 = await _userManager.SetSigninEndDateAsync(user);

#if DEBUG
                            if (result3)
                            {
                                Debug.WriteLine("SetSigninEndDateAsync is  well done");
                            }
#endif
                            var result4 = await _userManager.ResetAccessFailedCountAsync(user.UserID);

#if DEBUG
                            if (result4.Succeeded)
                            {
                                Debug.WriteLine("ResetAccessFailedCountAsync is executed.");
                            }
#endif

                            /*
                             * result4 = await _userManager.SetChangePasswordEndDateAsync(user);
                             #if DEBUG
                             * if (result4.Succeeded)
                             * {
                             *  Debug.WriteLine("SetChangePasswordEndDateAsync is executed.");
                             * }
                             #endif
                             *
                             * result4 = await _userManager.SetPasswordEnabledAsync(user, false);
                             #if DEBUG
                             * if (result4.Succeeded)
                             * {
                             *  Debug.WriteLine("SetPasswordEnabledAsync is executed.");
                             * }
                             #endif
                             */
                            return(RedirectToAction("List"));
                        }
                    }

                    //      }

                    /*      else
                     *    {
                     *        // Активизирована ли функция  блокировки учётки в системе
                     *        if (_userManager.LockoutEnabled)
                     *        {
                     *
                     #if DEBUG
                     *            Debug.WriteLine("++++ GetLockoutEnabledAsync is enabled");
                     #endif
                     *            // Увелечение счётчика неудачных попыток ввода пароля
                     *            if (await _userManager.AccessFailedAsync(user.UserID) == IdentityResult.Success)
                     *            {
                     #if DEBUG
                     *                Debug.WriteLine("~~~ AccessFailedAsync is working!");
                     #endif
                     *                if (await _userManager.IsLockedOutAsync(user.UserID))
                     *                {
                     #if DEBUG
                     *                    Debug.WriteLine("Account is locked out!");
                     #endif
                     *                    //Заблокировать учётку
                     *                    return View("Lockout");
                     *                }
                     *
                     *
                     *            }
                     *
                     *
                     *        }
                     *
                     *    } */
                }
            }
#if DEBUG
            Debug.WriteLine("Error is occured in ResetPassword");
#endif
            return(View(model));
        }