public IActionResult Login(LoginViewModel model, IFormCollection form) { if (ModelState.IsValid) { try { if (_session.GetObject <CustomerSs>("Customer") != null) { return(Redirect(Url.RouteUrl(new { controller = "Home", action = "Index" }))); } var cus = db.Customers.Where(u => u.Email == model.Email).SingleOrDefault(); if (cus == null) { Danger(string.Format("<b>Sai email </b> .", ""), true); return(View(model)); } else { var descrypt = Security_D_E.DecryptString(cus.Password, Security_D_E.key_e_d); if (descrypt == model.Password) { var cus_ = new CustomerSs() { Id = cus.Id, Fullname = cus.Fullname, Email = cus.Email, Activated = cus.Activated }; _session.SetObject("Customer", cus_); return(Redirect(Url.RouteUrl(new { controller = "Home", action = "Index" }))); } else { Danger(string.Format("<b>Sai password </b> .", ""), true); return(View(model)); } } } catch (Exception e) { Danger(string.Format("<b>Lỗi {0}</b> .", e.Message + e.InnerException), false); } } Danger(string.Format("<b>Lỗi đăng nhập</b> .", ""), false); return(View(model)); }
public void setCustomerSession(string email) { var cus = db.Customers.Include(u => u.Orders).Single(u => u.Email == email); var cus__ = new CustomerSs() { Id = cus.Id, Fullname = cus.Fullname, Email = cus.Email, Activated = cus.Activated, Address = cus.Address }; _session.SetObject("Customer", cus__); }
public IActionResult Register(CustomerRegisterView model) { try { var cus_ = db.Customers.Count(u => u.Email == model.Email.Trim()); if (cus_ > 0) { Danger(string.Format("<b>Email đã tồn tại</b> .", ""), false); return(View(model)); } else { Customer cus = new Customer() { Id = model.Email, Fullname = model.Fullname, Email = model.Email, Password = Security_D_E.EncryptString(model.Password, Security_D_E.key_e_d), Activated = true, Address = model.Address }; db.Customers.Add(cus); db.SaveChanges(); var cus__ = new CustomerSs() { Id = cus.Id, Fullname = cus.Fullname, Email = cus.Email, Activated = cus.Activated, Address = cus.Address }; _session.SetObject("Customer", cus__); } } catch (Exception e) { Danger(string.Format("<b>Lỗi {0}</b> .", e.Message + e.InnerException), true); return(View(model)); } return(Redirect(Url.RouteUrl(new { controller = "Home", action = "Index" }))); }