Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [AllowAnonymous]
- [HttpPost]
- public ActionResult Login(LoginUserModel model)
- {
- // Check if the entered credentials are valid against the LoginUserModel
- if (ModelState.IsValid)
- {
- // Lookup the credentials in the database, do they exist?
- if (db.Users.Any(u => u.email.Equals(model.email) && u.password.Equals(model.password)))
- {
- // Find the user and authenticate him
- Users tmp = db.Users.First(u => u.email.Equals(model.email));
- LogLogin(tmp);
- Account account = Account.CreateAccount(tmp.id, tmp.email, tmp.firstname, tmp.lastname, tmp.registrationDate);
- Session.Add("user", account);
- FormsAuthentication.SetAuthCookie(account.email, true);
- System.Diagnostics.Debug.WriteLine("Logging in " + account.firstname + " " + account.lastname);
- return RedirectToAction("Index", "Home");
- }
- }
- System.Diagnostics.Debug.WriteLine("NOT VALID");
- ModelState.AddModelError("", "The email or password provided is incorrect.");
- return View(model);
- }
Add Comment
Please, Sign In to add comment