예제 #1
0
        public ActionResult ChangeEmail(ChangeEmailModel model)
        {
            if ((Request.IsAuthenticated) && (User.Identity is UserIdentity))
            {
                ViewBag.ReturnUrl   = Url.Action("ChangeEmail");
                ViewBag.ViewOptions = new ViewOptions
                {
                    IsPrincipal = true,
                    IsFixed     = true,
                };

                var user = CServices.ServiceUser.Find(UserContext.CurrentUserId);
                if (user != null)
                {
                    ViewBag.HasLocalPassword = true;

                    ((ViewOptions)ViewBag.ViewOptions).InfoViewPartial = UsuarioController.GetInfo(user);
                    if (!ModelState.IsValid)
                    {
                        ModelState.AddModelError("", "ErrorInvalidInput");
                    }
                    else
                    {
                        // ChangePassword will throw an exception rather than return false in certain failure scenarios.
                        try
                        {
                            ServiceUser.ChangeEmail(user, model.Email, model.NewEmail);
                            return(RedirectToAction("ChangeEmail", new { Message = ManageMessageId.ChangeEmailSuccess }));
                        }
                        catch (Exception e)
                        {
                            ModelState.AddModelError("", e.Message);
                        }
                    }
                }
                else
                {
                    ViewBag.HasLocalPassword = false;
                }
                // If we got this far, something failed, redisplay form

                return(View(model));
            }
            return(RedirectToAction("Index", "Home"));
        }