Ejemplo n.º 1
0
 public ActionResult CreateStaffAccount(Account item)
 {
     item.role = "staff";
     Database.Accounts.Add(item);
     Database.SaveChanges();
     return RedirectToAction("StaffCreate", "Home", new { userName = item.userName });
 }
Ejemplo n.º 2
0
 public ActionResult CreateManAccount(Account item)
 {
     item.role = "admin";
     Database.Accounts.Add(item);
     Database.SaveChanges();
     return RedirectToAction("Login");
 }
Ejemplo n.º 3
0
 public ActionResult CreateCustAccount(Account item)
 {
     item.role = "unassigned";
     Database.Accounts.Add(item);
     Database.SaveChanges();
     return RedirectToAction("CustCreate", "Home", new { username = item.userName });
 }
Ejemplo n.º 4
0
        public ActionResult Login(Account model, string returnUrl)
        {
            // Lets first check if the Model is valid or not
            if (ModelState.IsValid)
            {
                using (EasyHouseEntities1 entities = new EasyHouseEntities1())
                {
                    string username = model.userName;
                    string password = model.password;

                    // Now if our password was enctypted or hashed we would have done the
                    // same operation on the user entered password here, But for now
                    // since the password is in plain text lets just authenticate directly

                    var userValid = entities.Accounts.FirstOrDefault(user => user.userName == username && user.password == password);

                    // User found in the database
                    if (userValid != null)
                    {
                        Session["username"] = username.ToString();
                        registerLogin(username, userValid.role);

                        //FormsAuthentication.SetAuthCookie(username, false);
                        if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/")
                            && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
                        {
                            return Redirect(returnUrl);
                        }
                        else
                        {
                            if (userValid.role == "admin")
                                return RedirectToAction("ManLanding", "Home");
                            else if (userValid.role == "customer")
                                return RedirectToAction("CustLanding", "Home");
                            else if (userValid.role == "unassigned")
                                return RedirectToAction("UnassignedCustLanding", "Home");
                            else if (userValid.role == "staff")
                                return RedirectToAction("StaffLanding", "Home");
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", "The user name or password provided is incorrect.");
                    }
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
Ejemplo n.º 5
0
 public ActionResult CreateStaffAccount()
 {
     var model = new Account();
     return View("CreateStaffAccount", model);
 }