示例#1
0
        public ActionResult RemoveAccountList()
        {
            var linkedAccounts = userManager.GetLogins(User.Identity.GetUserId());

            ViewBag.ShowRemoveButton = ControllerUtils.HasPassword(userManager, User) || linkedAccounts.Count > 1;
            return(PartialView("_RemoveAccountPartial", linkedAccounts));
        }
示例#2
0
 public ActionResult Index()
 {
     if (User.Identity.GetUserId() == null || ControllerUtils.HasPassword(userManager, User))
     {
         return(View());
     }
     return(RedirectToAction("Manage", "Account"));
 }
示例#3
0
        public async Task <ActionResult> Manage(ManageUserViewModel model)
        {
            var hasPassword = ControllerUtils.HasPassword(userManager, User);

            ViewBag.HasLocalPassword = hasPassword;
            ViewBag.ReturnUrl        = Url.Action("Manage");
            if (hasPassword)
            {
                if (ModelState.IsValid)
                {
                    var result = await userManager.ChangePasswordAsync(User.Identity.GetUserId(), model.OldPassword, model.NewPassword);

                    if (result.Succeeded)
                    {
                        return(RedirectToAction("Manage", new { Message = ManageMessageId.PasswordChanged }));
                    }

                    this.AddErrors(result);
                }
                else
                {
                    ModelState.AddModelError("", "Есть ошибки, давай поправим");
                }
            }
            else
            {
                // User does not have a password so remove any validation errors caused by a missing OldPassword field
                var state = ModelState["OldPassword"];
                state?.Errors.Clear();

                if (ModelState.IsValid)
                {
                    var result = await userManager.AddPasswordAsync(User.Identity.GetUserId(), model.NewPassword);

                    if (result.Succeeded)
                    {
                        return(RedirectToAction("Manage", new { Message = ManageMessageId.PasswordSet }));
                    }

                    this.AddErrors(result);
                }
                else
                {
                    ModelState.AddModelError("", "Есть ошибки, давай поправим");
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
示例#4
0
        public async Task <ActionResult> Manage(ManageMessageId?message, string provider = "", string otherUserId = "")
        {
            ViewBag.StatusMessage = message?.GetAttribute <DisplayAttribute>().GetName();
            if (message == ManageMessageId.AlreadyLinkedToOtherUser)
            {
                var otherUser = await userManager.FindByIdAsync(otherUserId);

                ViewBag.StatusMessage += $" {provider ?? ""}. Аккаунт уже привязан к пользователю {otherUser?.UserName ?? ""}.";
            }
            ViewBag.IsStatusError    = message?.GetAttribute <IsErrorAttribute>()?.IsError ?? IsErrorAttribute.DefaultValue;
            ViewBag.HasLocalPassword = ControllerUtils.HasPassword(userManager, User);
            ViewBag.ReturnUrl        = Url.Action("Manage");
            return(View());
        }
示例#5
0
        public PartialViewResult ChangeDetailsPartial()
        {
            var user        = userManager.FindByName(User.Identity.Name);
            var hasPassword = ControllerUtils.HasPassword(userManager, User);

            return(PartialView(new UserViewModel
            {
                Name = user.UserName,
                UserId = user.Id,
                HasPassword = hasPassword,
                FirstName = user.FirstName,
                LastName = user.LastName,
                Email = user.Email
            }));
        }
示例#6
0
 //
 // GET: /Account/Manage
 public ActionResult Manage(ManageMessageId?message)
 {
     ViewBag.StatusMessage =
         message == ManageMessageId.ChangePasswordSuccess
                                 ? "Пароль был изменен."
                                 : message == ManageMessageId.SetPasswordSuccess
                                         ? "Пароль установлен."
                                         : message == ManageMessageId.RemoveLoginSuccess
                                                 ? "Внешний логин удален."
                                                 : message == ManageMessageId.Error
                                                         ? "Ошибка."
                                                         : "";
     ViewBag.HasLocalPassword = ControllerUtils.HasPassword(userManager, User);
     ViewBag.ReturnUrl        = Url.Action("Manage");
     return(View());
 }