Ejemplo n.º 1
0
            public override void OnActionExecuting(ActionExecutingContext filterContext)
            {
                filterContext.Controller.ViewBag.UpdateSucceed = "0";
                if (!filterContext.Controller.ViewData.ModelState.IsValid)
                {
                    filterContext.Controller.ViewData.ModelState.AddModelError("", "Invalid update information");
                    return;
                }

                var modelList = filterContext.ActionParameters.Where(ap => ap.Key == "model").ToList();

                if (modelList.IsNullOrEmpty())
                {
                    filterContext.Controller.ViewData.ModelState.AddModelError("", "Invalid update information");
                    return;
                }
                if (!modelList.Any() || modelList.Count != 1)
                {
                    filterContext.Controller.ViewData.ModelState.AddModelError("", "Invalid update information");
                    return;
                }

                var model = modelList[0].Value as UserPasswordContract;

                if (model == null)
                {
                    filterContext.Controller.ViewData.ModelState.AddModelError("", "Invalid update information");
                    return;
                }
                string msg;

                if (!UserAuthentication.ChangePassword(model.UserName, model.OldPassword, model.NewPassword, out msg))
                {
                    filterContext.Controller.ViewData.ModelState.AddModelError("", msg.Length > 0 ? msg : "Process Failed! Unable to update password");
                    return;
                }

                filterContext.Controller.ViewBag.UpdateSucceed = "1";
                base.OnActionExecuting(filterContext);
            }