Exemplo n.º 1
0
 public ActionResult Login(Customer model)
 {
     if (ModelState.IsValid)
     {
         //If the input email address does not match any in the database, generate an error message. Otherwise, proceed.
         var db       = new JamesEntities();
         var password = model.Password;
         var check    = db.Customer.Where(u => u.Email == model.Email).FirstOrDefault();
         if (check == null)
         {
             ViewData["Message"] = "Email address not found.";
         }
         else
         {
             //Check if the input password matches the one for the selected record. If it does, proceed. If not, generate an error message.
             bool correct = Salt.Verify(password, check.Password);
             if (correct == true)
             {
                 Session["Name"]    = check.FirstName;
                 Session["Email"]   = check.Email;
                 Session["Message"] = "Welcome, " + check.FirstName + ".";
                 return(RedirectToAction("Customer", "User"));
             }
             else
             {
                 ViewData["Message"] = "Login failed.";
             }
         }
     }
     return(View(model));
 }