예제 #1
0
        public ActionResult SignIn(CustomerViewModel customerViewModel, string ReturnUrl)
        {
            using (NorthwndEntities db = new NorthwndEntities())
            {
                if (ModelState.IsValid)
                {
                    FormData.DataLayer.Customer c = db.Customers.Find(customerViewModel.CustomerId);
                    string hashEnteredPassword    = UserAccount.HashSHA1(customerViewModel.Password + c.UserGuid);

                    if (hashEnteredPassword == c.Password)
                    {
                        FormsAuthentication.SetAuthCookie(c.CustomerID.ToString(), false);
                        HttpCookie httpCookie = new HttpCookie("role");
                        httpCookie.Value = "customer";
                        Response.Cookies.Add(httpCookie);

                        if (ReturnUrl != null)
                        {
                            return(Redirect(ReturnUrl));
                        }
                        return(RedirectToAction("Index", "Home"));
                    }

                    ModelState.AddModelError("Password", "Incorrect Password");
                }


                var companies = db.Customers.OrderBy(x => x.CompanyName).ToList();
                ViewBag.CustomerId = new SelectList(companies, "CustomerId", "CompanyName");

                return(View());
            }
        }
예제 #2
0
        public ActionResult Register(FormData.DataLayer.Customer customer) // FormData.Models
        {
            using (NorthwndEntities db = new NorthwndEntities())
            {
                // verify not duplicate

                // will check if customer name is exist
                if (db.Customers.Any(c => c.CompanyName == customer.CompanyName))
                {
                    // if it exist - return the same view...
                    return(View());
                }
                // encrypt the password
                customer.UserGuid = System.Guid.NewGuid();
                customer.Password = UserAccount.HashSHA1(customer.Password + customer.UserGuid);

                // save the password
                db.Customers.Add(customer);
                db.SaveChanges();
                return(RedirectToAction("Index", "Home"));
            }
        }