Ejemplo n.º 1
0
        /*
         * Handles login for the class
         *
         * @param:
         * @return: If successful
         */
        public bool doLogin()
        {
            // Holds the state of the login
            LoggedIn result = null;

            if (username != null && password != null)
            {
                // Establishes model for login
                LoginModel loginControl = new LoginModel();

                // Creates a new user with the specified details
                User newUser = new User();
                newUser.username = username;
                newUser.password = password;

                // Passes the user to the login model
                result = loginControl.Login(newUser);

                // Returns bool. State of the login attempt
                return result.State;

            }
            else
            {
                // Failure to login
                return false;
            }
        }
Ejemplo n.º 2
0
        public ActionResult loginpost()
        {
            LoginModel loginModel = new LoginModel();
            ClientUserModel clientmModel = new ClientUserModel();

            // To store login details
            String username;
            String password;

            // Acquire login details from front-end
            username = Request.Form[0];
            password = Request.Form[1];

            // Composes object
            User thisUser = new User();
            thisUser.username = username;
            thisUser.password = password;
            ClientUser client = new ClientUser();
            client.Username = username;
            client.Password = password;

            // get Account Type / Access levels from Database
            LoggedIn logState;
            logState = loginModel.Login(thisUser);

            if (logState.State)
            {
                Session["loggedInState"] = logState.State;
                Session["username"] = thisUser.username;
                Session["userID"] = logState.UserID;
                Session["Type"] = "Employee";
            }
            else
            {
                logState = clientmModel.Login(client);

                Session["loggedInState"] = logState.State;
                Session["username"] = client.Username;
                Session["userID"] = logState.UserID;
                Session["Type"] = "Client";
            }

            // Sets the Session variables

            // Acquire type of user from Ryan
            // Redirect based on user:
                // Admin (Staff)
                // User (Client)

            // variable to store the path to redirect to
            String pageToDirectTo = "/index.html";

            try {
                bool state = (bool)Session["loggedInState"];
                if (state == true)
                {
                    if (Session["Type"].ToString() == "Employee")
                    {
                        pageToDirectTo = "/Index/";
                        if (logState.AccessLevel.Equals("Admin"))
                        {
                            pageToDirectTo = "/Index/adminIndex";
                        }
                    }
                    else
                    {
                        pageToDirectTo = "/Index/clientIndex"; // doesn't work
                    }
                }
                else
                {
                    pageToDirectTo = "/login.html";
                }
            }catch(Exception e){
                pageToDirectTo = "/403.html";
            }

            // redirect the user to the relevant page
            return Redirect(pageToDirectTo);
        }