public ActionResult SignInHandler(AuthAttempt authAttempt) { if (ModelState.IsValid) { // check if the credentials are right // and store user in session using (var ctx = new CarAuctionContext()) { try { User existingUser = ctx.Users.FirstOrDefault( u => u.Email == authAttempt.Email && u.Password == authAttempt.Password ); if (existingUser != null) { HttpContext.Session["User"] = existingUser; Response.Redirect("/Panel"); return(null); } } catch (InvalidOperationException ignored) { } } } ViewBag.FailureMessage = "Incorrect email or password"; return(View()); }
public ActionResult SignUpHandler(User user) { if (!ModelState.IsValid) { ViewBag.FailureMessage = "Something went wrong"; return(View()); } using (var ctx = new CarAuctionContext()) { ctx.Users.Add(user); ctx.SaveChanges(); } ViewBag.SuccessMessage = "You successfully signed up"; return(View()); }