public async Task <ActionResult> ChangePassword(ChangePasswordViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var result = await UserManageService.ChangePasswordAsync(User.Identity.GetUserId(), model.OldPassword, model.NewPassword);

            if (result.Succeeded)
            {
                var user = await UserManageService.FindByIdAsync(User.Identity.GetUserId());

                if (user != null)
                {
                    await SignInManageService.SignInAsync(user, isPersistent : false, rememberBrowser : false);
                }
                return(RedirectToAction("Index", new { Message = ManageMessageId.ChangePasswordSuccess }));
            }
            AddErrors(result);
            return(View(model));
        }
        public async Task <ActionResult> SetPassword(SetPasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                var result = await UserManageService.AddPasswordAsync(User.Identity.GetUserId(), model.NewPassword);

                if (result.Succeeded)
                {
                    var user = await UserManageService.FindByIdAsync(User.Identity.GetUserId());

                    if (user != null)
                    {
                        await SignInManageService.SignInAsync(user, isPersistent : false, rememberBrowser : false);
                    }
                    return(RedirectToAction("Index", new { Message = ManageMessageId.SetPasswordSuccess }));
                }
                AddErrors(result);
            }

            // Это сообщение означает наличие ошибки; повторное отображение формы
            return(View(model));
        }
        //
        // GET: /Manage/ManageLogins
        public async Task <ActionResult> ManageLogins(ManageMessageId?message)
        {
            ViewBag.StatusMessage =
                message == ManageMessageId.RemoveLoginSuccess ? "Внешнее имя входа удалено."
                : message == ManageMessageId.Error ? "Произошла ошибка."
                : "";
            var user = await UserManageService.FindByIdAsync(User.Identity.GetUserId());

            if (user == null)
            {
                return(View("Error"));
            }
            var userLogins = await UserManageService.GetLoginsAsync(User.Identity.GetUserId());

            var otherLogins = AuthenticationManager.GetExternalAuthenticationTypes().Where(auth => userLogins.All(ul => auth.AuthenticationType != ul.LoginProvider)).ToList();

            ViewBag.ShowRemoveButton = user.PasswordHash != null || userLogins.Count > 1;
            return(View(new ManageLoginsViewModel
            {
                CurrentLogins = userLogins,
                OtherLogins = otherLogins
            }));
        }