/// <summary> /// Authenticates the specified model. /// </summary> /// <param name="model">The model.</param> /// <param name="redirect">if set to <c>true</c> a redirect will be performed when the user is logged on.</param> /// <returns><c>true</c> if the model could be authenticated; otherwise <c>false</c>.</returns> protected virtual bool Authenticate(LogonModel model, bool redirect = true) { bool authenticated = FormsAuthentication.Authenticate(model.UserName, model.Password); if (!authenticated) { return(false); } var user = new GenericIdentity(model.UserName); var principal = new SimpleConfigurationPrincipal(user); SimpleConfigurationPrincipal.SetAuthenticatedPrincipal(principal); if (redirect) { FormsAuthentication.RedirectFromLoginPage(model.UserName, false); } return(true); }
public virtual ActionResult Index(LogonModel model) { Authenticate(model); return(View(model)); }