public ActionResult ChangePassword(ChangePasswordFormModel form) { if (ModelState.IsValid) { EFMVCUser efmvcUser = HttpContext.User.GetEFMVCUser(); var command = new ChangePasswordCommand { UserId = efmvcUser.UserId, OldPassword = form.OldPassword, NewPassword = form.NewPassword }; IEnumerable <ValidationResult> errors = commandBus.Validate(command); ModelState.AddModelErrors(errors); if (ModelState.IsValid) { var result = commandBus.Submit(command); if (result.Success) { return(RedirectToAction("ChangePasswordSuccess")); } else { ModelState.AddModelError("", "The current password is incorrect or the new password is invalid."); } } } // If we got this far, something failed, redisplay form return(View(form)); }
private void PostAuthenticateRequestHandler(object sender, EventArgs e) { HttpCookie authCookie = this.Context.Request.Cookies[FormsAuthentication.FormsCookieName]; if (IsValidAuthCookie(authCookie)) { var formsAuthentication = DependencyResolver.Current.GetService <IFormsAuthentication>(); var ticket = formsAuthentication.Decrypt(authCookie.Value); var efmvcUser = new EFMVCUser(ticket); string[] userRoles = { efmvcUser.RoleName }; this.Context.User = new GenericPrincipal(efmvcUser, userRoles); formsAuthentication.SetAuthCookie(this.Context, ticket); } }
public override void OnActionExecuted(ActionExecutedContext filterContext) { UserModel userModel; if (filterContext.Controller.ViewBag.UserModel == null) { userModel = new UserModel(); filterContext.Controller.ViewBag.UserModel = userModel; } else { userModel = filterContext.Controller.ViewBag.UserModel as UserModel; } if (filterContext.HttpContext.User.Identity.IsAuthenticated) { EFMVCUser efmvcUser = filterContext.HttpContext.User.GetEFMVCUser(); userModel.IsUserAuthenticated = efmvcUser.IsAuthenticated; userModel.UserName = efmvcUser.DisplayName; userModel.RoleName = efmvcUser.RoleName; } base.OnActionExecuted(filterContext); }