public virtual ActionResult Login(string returnUrl) { var model = new LoginModel() { ReturnUrl = returnUrl }; return View(model); }
public virtual async Task<ActionResult> Login(LoginModel model) { if (!ModelState.IsValid) { return View(model); } var user = await _userManager.FindAsync(model.UserName, model.Password); if (user != null) { var identity = await _userManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie); var context = Request.GetOwinContext(); var authManager = context.Authentication; authManager.SignIn(identity); return Redirect(GetRedirectUrl(model.ReturnUrl)); } ModelState.AddModelError("UserNotFound", "Invalid email or password"); return View(model); }