// GET: /Auth/LogIn public ActionResult LogIn(string returnUrl) { var model = new AuthLogInViewModel { ReturnUrl = returnUrl }; return View(model); }
public ActionResult LogIn(AuthLogInViewModel model) { if (!ModelState.IsValid) { return View(); } // Using UserManager (no async) var user = userManager.Find(model.UserName, model.Password); if (user != null) { var identity = userManager.CreateIdentity( user, DefaultAuthenticationTypes.ApplicationCookie); GetAuthenticationManager().SignIn(identity); return Redirect(GetRedirectUrl(model.ReturnUrl)); } // user authN failed ModelState.AddModelError("", "Invalid username or password"); return View(); /* // Don't do this in production! // Hardcode an Admin user if (model.UserName == "admin" && model.Password == "password") { var identity = new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, "Admin"), new Claim(ClaimTypes.Email, "*****@*****.**"), new Claim(ClaimTypes.Country, "USA") }, "ApplicationCookie"); var ctx = Request.GetOwinContext(); var authManager = ctx.Authentication; authManager.SignIn(identity); return Redirect(GetRedirectUrl(model.ReturnUrl)); } // user authN failed ModelState.AddModelError("", "Invalid username or password"); return View(); */ }