예제 #1
0
        public ActionResult Manage(LocalPasswordModel model)
        {
            ViewBag.ViewOptions = new ViewOptions
            {
                IsPrincipal = true,
                IsFixed     = true,
            };

            if (User.Identity is UserIdentity)
            {
                var user = CServices.ServiceUser.Find((User.Identity as UserIdentity).UserId);
                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.ChangePass(user, model.OldPassword, model.NewPassword);
                            return(RedirectToAction("Manage", new { Message = ManageMessageId.ChangePasswordSuccess }));
                        }
                        catch (Exception e)
                        {
                            ModelState.AddModelError("", e.Message);
                        }
                    }
                }
                else
                {
                    ViewBag.HasLocalPassword = false;
                }
                ViewBag.ReturnUrl = Url.Action("Manage");
                // If we got this far, something failed, redisplay form
            }
            return(View(model));
        }