Guest User

Untitled

a guest
Jan 17th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.28 KB | None | 0 0
  1. [AllowAnonymous]
  2.         [HttpPost]
  3.         public ActionResult Login(LoginUserModel model)
  4.         {
  5.             // Check if the entered credentials are valid against the LoginUserModel
  6.             if (ModelState.IsValid)
  7.             {
  8.                 // Lookup the credentials in the database, do they exist?
  9.                 if (db.Users.Any(u => u.email.Equals(model.email) && u.password.Equals(model.password)))
  10.                 {
  11.  
  12.                     // Find the user and authenticate him
  13.                     Users tmp = db.Users.First(u => u.email.Equals(model.email));
  14.  
  15.                     LogLogin(tmp);
  16.  
  17.                     Account account = Account.CreateAccount(tmp.id, tmp.email, tmp.firstname, tmp.lastname, tmp.registrationDate);
  18.  
  19.  
  20.                     Session.Add("user", account);
  21.                     FormsAuthentication.SetAuthCookie(account.email, true);
  22.  
  23.                     System.Diagnostics.Debug.WriteLine("Logging in " + account.firstname + " " + account.lastname);
  24.                     return RedirectToAction("Index", "Home");
  25.                 }
  26.  
  27.             }
  28.  
  29.             System.Diagnostics.Debug.WriteLine("NOT VALID");
  30.             ModelState.AddModelError("", "The email or password provided is incorrect.");
  31.  
  32.             return View(model);
  33.         }
Add Comment
Please, Sign In to add comment