public async Task<ActionResult> LogIn(LogInModel model) { if (!ModelState.IsValid) { return View(); } using (var session = _store.OpenSession()) { using (var userManager = Startup.UserManagerFactory.Invoke(session)) { var user = await userManager.FindAsync(model.Email, model.Password); if (user != null) { var identity = await userManager.CreateIdentityAsync( user, DefaultAuthenticationTypes.ApplicationCookie); identity.AddClaim(new Claim(ClaimTypes.Email, user.Email)); GetAuthenticationManager().SignIn(identity); return Redirect(GetRedirectUrl(model.ReturnUrl)); } // user auth failed ModelState.AddModelError("", "Invalid email or password"); return View(); } } }
public ActionResult LogIn(string returnUrl) { var model = new LogInModel { ReturnUrl = returnUrl }; return View(model); }