示例#1
0
        static void Main(string[] args)
        {
            var staffDbManager    = new StaffManager(Configuration);
            var customerDbManager = new CredentialsManager(Configuration);


            /*
             * Console.WriteLine("--GET 1 staff--");
             * Staff staff = staffDbManager.GetStaff(1);
             * Console.WriteLine("Check db");
             * Console.WriteLine(staff.name);
             */



            Console.WriteLine("Username");
            string usernameC = Console.ReadLine();


            Console.WriteLine("Password");
            string passwordC = Console.ReadLine();


            int idCustomerTryingToConnect = customerDbManager.GetIdCredentials(usernameC);

            //En fonction de l'id du customer
            while (passwordC != customerDbManager.GetPassword(idCustomerTryingToConnect, usernameC))
            {
                Console.WriteLine(passwordC);
                Console.WriteLine("Connection denied. Try again");

                Console.WriteLine("Username");
                usernameC = Console.ReadLine();

                Console.WriteLine("Password");
                passwordC = Console.ReadLine();

                idCustomerTryingToConnect = customerDbManager.GetIdCredentials(usernameC);
            }

            Console.WriteLine("Connection successful");

            //Program.Suite(idCustomerTryingToConnect);
        }
示例#2
0
        public ActionResult Index(Credentials credModel)
        {
            string usernameC = credModel.username;
            string passwordC = credModel.password;

            var credentialsDbManager  = new CredentialsManager(Configuration);
            int idUserTryingToConnect = credentialsDbManager.GetIdCredentials(usernameC);
            int userStatus            = credentialsDbManager.GetStatus(usernameC);

            //Get password using
            if (passwordC == credentialsDbManager.GetPassword(usernameC))
            {
                HttpContext.Session.SetString("username", usernameC);
                HttpContext.Session.SetInt32("id", idUserTryingToConnect);
                HttpContext.Session.SetInt32("userType", userStatus);
                //status 2 means admin, 1=Delivery employee, 0 = customer
                //The view the user will see depends on his status in our DB
                if (userStatus == 2)
                {
                    return(RedirectToAction("Index", "Home"));
                }

                else if (userStatus == 1)
                {
                    StaffManager sManager = new StaffManager(Configuration);
                    int          idStaff  = sManager.GetStaffId(idUserTryingToConnect);
                    HttpContext.Session.SetInt32("idStaff", idStaff);
                    return(RedirectToAction("Index", "DishesOrder"));
                }
                else if (userStatus == 0)
                {
                    CustomerManager cManager = new CustomerManager(Configuration);
                    HttpContext.Session.SetInt32("idCustomer", cManager.GetCustomerIDByCredentials(idUserTryingToConnect));
                    return(RedirectToAction("Index", "Home"));
                }
                //If we did find a username and password but not a status we through an error.
                return(RedirectToAction("LoginError", "Error", new { message = "Your account is not correctly initialized. Please contact our support : [email protected] or connect with another account." }));
            }
            else
            {   //If the credentials did not match we through an error
                return(RedirectToAction("LoginError", "Error", new { message = "Unfortunately your username or password did not match our records. Please try again." }));
            }
        }