public ActionResult Login(CustomerLogin customerLogin)
 {
     using(CustomerLoginEntities clEntity = new CustomerLoginEntities())
     {
         //hashing user entry password
         customerLogin.password = HashKey.GetHashKey(customerLogin.password);
         //checking database if user is valid
         bool userIsValid = clEntity.CustomerLogins.Any(loginTable=>loginTable.email == customerLogin.email && loginTable.password == customerLogin.password);
         //checking if user is valid
         if (userIsValid)
         {
             CustomerLogin customer = clEntity.CustomerLogins.Where(loginTable => loginTable.email == customerLogin.email && loginTable.password == customerLogin.password).FirstOrDefault<CustomerLogin>();
             customer.dateCreated = DateTime.Now;
             customer.password = customerLogin.password;
             clEntity.Entry(customer).State = EntityState.Modified;
             clEntity.SaveChanges();
             Session["customerID"] = customer.customer_ID;
             Session["customerEmail"] = customer.email;
             return RedirectToAction("Index", "Home", new{customer_ID = customer.customer_ID});
         }
         else
         { ModelState.AddModelError("", "Email or Password provided is incorrect!"); }
     }
     return RedirectToAction("Index", "Registration");
 }
Exemplo n.º 2
0
 public static CustomerLogin ConvertToProperty(DataRow dr)
 {
     CustomerLogin _customerLogin = new CustomerLogin();
     _customerLogin.customerLogin_ID = Convert.ToInt32(dr["customerLogin_ID"]);
     _customerLogin.customer_ID = Convert.ToInt32(dr["customer_ID"]);
     _customerLogin.email = dr["email"].ToString();
     _customerLogin.password = dr["password"].ToString();
     return _customerLogin;
 }
 public ActionResult Register(Customer customer, CustomerAddress customerAddress, CustomerLogin customerLogin)
 {
     string viewChange = "";
     try
     {
         if (ModelState.IsValid)
         {
             //encrypt the password
             customerLogin.password = HashKey.GetHashKey(customerLogin.password);
             //inserting into customers table
             using (CustomerEntities cEntityy = new CustomerEntities())
             {
                 cEntityy.Customers.Add(customer);
                 cEntityy.SaveChanges();
             }
             using (CustomerAddressEntities caEntity = new CustomerAddressEntities())
             {
                 customerAddress.customer_ID = customer.customer_ID;
                 //inserting into customer address table
                 caEntity.CustomerAddresses.Add(customerAddress);
                 caEntity.SaveChanges();
             }
             using (CustomerLoginEntities clEntity = new CustomerLoginEntities())
             {
                 customerLogin.customer_ID = customer.customer_ID;
                 customerLogin.email = customer.email;
                 customerLogin.dateCreated = DateTime.Now;
                 //inserting into customer login table
                 clEntity.CustomerLogins.Add(customerLogin);
                 clEntity.SaveChanges();
                 return RedirectToAction("Index", "Customer");
             }
         }
         else
         {
             viewChange = "LoginRegister";
         }
     }
     catch(EntryPointNotFoundException ex){}
     catch (Exception ex) { viewChange = "LoginRegister"; }
     return View(viewChange);
 }