Exemplo n.º 1
0
        public ActionResult Login(User user)
        {
            if (ModelState.IsValid)
            {

                if (user.loginUser(user))
                {
                    String loginName = user.username;
                    String account = user.acctype.ToString();
                    String loggedIn = user.loggedIn.ToString();

                    //Store in session
                    Session["loginName"] = loginName;
                    Session["account"] = account;
                    Session["loggedIn"] = loggedIn;
                    Session["lg"] = user;

                    Debug.WriteLine("account type " + user.username);
                    if (account.Equals("Administrator"))
                    {
                        return RedirectToAction("Admin", "Home");
                    }
                    if (account.Equals("Manager"))
                    {
                        return RedirectToAction("Whisky", "Manager");
                    }
                    if (account.Equals("Shipper"))
                    {
                        return RedirectToAction("Orders", "Shipping");
                    }
                    if (account.Equals("Warehouse"))
                    {
                        return RedirectToAction("Orders", "Warehouse");
                    }
                    return View();
                }

                else
                {

                    ModelState.AddModelError("", "The username or password is incorrect.");
                    return View(user);
                }
            }
            else
            {
                return View(user);
            }
        }
Exemplo n.º 2
0
        public Boolean loginUser(User user)
        {
            using (MySqlConnection con = new MySqlConnection(con_str))
            {
                if (checkLogin(user))
                {
                    loggedIn = true;

                    return true;
                }
                else
                    return false;

            }
        }
        public ActionResult Index()
        {
            //Debug.WriteLine("this is in" + Session["loginName"].ToString());
            //Debug.WriteLine("this is in" + Session["account"].ToString());
            //var model = (User) Session["lg"] ?? new User();
            var model = new User();
            //model.
            if ( System.Web.HttpContext.Current.Session["account"].ToString() == "Administrator")
            {
                var adminData = new AdminNavBar();
                return PartialView("_AdminNav", adminData.navbarItems().ToList());
            }

            var data = new Data();
            return PartialView("_Navbar", data.navbarItems().ToList());
        }
        public ActionResult Index()
        {
            //Debug.WriteLine("this is in" + Session["loginName"].ToString());
            //Debug.WriteLine("this is in" + Session["account"].ToString());
            //var model = (User) Session["lg"] ?? new User();
            var model = new User();
            //model.
            if (System.Web.HttpContext.Current.Session["account"] != null)
            {
                if (System.Web.HttpContext.Current.Session["account"].ToString() == "Administrator")
                {
                    var adminData = new AdminNavBar();
                    return PartialView("_AdminNav", adminData.navbarItems().ToList());
                }

                else if (System.Web.HttpContext.Current.Session["account"].ToString() == "Manager")
                {
                    var managerData = new ManagerNavBar();
                    return PartialView("_ManagerNav", managerData.navbarItems().ToList());
                }

                else if (System.Web.HttpContext.Current.Session["account"].ToString() == "Shipper")
                {
                    var ShipperData = new ShipperNavBar();
                    return PartialView("_ShipperNav", ShipperData.navbarItems().ToList());
                }

                else if (System.Web.HttpContext.Current.Session["account"].ToString() == "Warehouse")
                {
                    var WarehouseData = new ShipperNavBar();
                    return PartialView("_WarehouseNav", WarehouseData.navbarItems().ToList());
                }

                return RedirectToRoute("Default"); ;
            }

            else
            {
                System.Diagnostics.Debug.WriteLine("retudirecting to route");
                return RedirectToRoute("Default", new { controller = "Home", action = "Login", id = UrlParameter.Optional });
            }
        }
Exemplo n.º 5
0
        public Boolean checkLogin(User user)
        {
            String checkedUsername = "";
            String checkedPassword = "";

            using (MySqlConnection con = new MySqlConnection(con_str))
            {
                con.Open();
                using (MySqlCommand cmd = new MySqlCommand("getUserDetails", con))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@username", username);
                    MySqlDataReader reader = null;
                    reader = cmd.ExecuteReader();

                    while (reader.Read())
                    {
                        checkedUsername = reader.GetString("username");
                        checkedPassword = Encryption.Decrypt(reader.GetString("password"));
                        Debug.WriteLine("PASSWORD " + password);
                        string s = reader.GetString("accountType");
                        acctype = (AccountType)Enum.Parse(typeof(AccountType), s);
                    }

                    reader.Close();
                    con.Close();

                }
            }
            if (password.Equals(checkedPassword))
            {
                password = checkedPassword;
                username = checkedUsername;

                return true;
            }
            else
                return false;

        }