コード例 #1
0
        public virtual ActionResult ChangeEmail(LocalEmailModel model)
        {
            var user = GetUser();

            if (ModelState.IsValid)
            {
                if (userManager.CheckPassword(user, model.OldPassword))
                {
                    var result = userManager.SetEmail(User.Identity.GetUserId(), model.Email?.Trim());
                    if (result.Succeeded)
                    {
                        user = userManager.FindById(User.Identity.GetUserId());
                        if (user != null)
                        {
                            signInManager.SignIn(user, isPersistent: false, rememberBrowser: false);
                        }

                        return(RedirectToAction(MVC.Account.Manage(ManageMessageId.ChangeEmailSuccess)));
                    }
                    else
                    {
                        AddErrors(result);
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Bad password");
                }
            }
            // If we got this far, something failed, redisplay form
            return(View(MVC.Account.Views.ChangeEmail, model));
        }
コード例 #2
0
        //
        // GET: /Account/ChangeEmail

        public virtual ActionResult ChangeEmail()
        {
            var Email = new LocalEmailModel
            {
                Email = GetUser().Email
            };

            return(View(MVC.Account.Views.ChangeEmail, Email));
        }
コード例 #3
0
ファイル: AccountController.cs プロジェクト: bsrega/Kulti
        public ActionResult ManageEmail(LocalEmailModel model)
        {
            bool hasLocalAccount = OAuthWebSecurity.HasLocalAccount(WebSecurity.GetUserId(User.Identity.Name));

            ViewBag.HasLocalPassword = hasLocalAccount;

            bool changeEmailSucceeded = true;

            if (hasLocalAccount)
            {
                if (ModelState.IsValid)
                {
                    // ChangePassword will throw an exception rather than return false in certain failure scenarios.
                    try
                    {
                        //changeEmailSucceeded = WebSecurity.ChangePassword(User.Identity.Name, model.OldPassword, model.NewPassword);
                        UpdateEmail(model.NewEmail, WebSecurity.GetUserId(User.Identity.Name));
                    }
                    catch (Exception)
                    {
                        changeEmailSucceeded = false;
                    }

                    if (changeEmailSucceeded)
                    {
                        return(RedirectToAction("ManageEmail", new { Message = ManageMessageId.ChangeEmailSuccess }));
                    }
                    else
                    {
                        ModelState.AddModelError("", "The current email is incorrect or the new email is invalid.");
                    }
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
コード例 #4
0
 public ManageViewModel()
 {
     LocalPassword = new LocalPasswordModel();
     LocalEmail    = new LocalEmailModel();
 }