// Check login credentials and show dashboard
        public ActionResult Dashboard()
        {
            CinemaViewModel model = (CinemaViewModel)TempData["model"];
            // Request input from cash register login
            string username = Request["username"];
            string password = Request["password"];

            // No user input
            if (username == "" || password == "")
            {
                return(RedirectToAction("BackOfficeLogin", "Login", new { error = "Vul a.u.b. beide velden in" }));
            }
            else
            {
                // Get all logins
                IEnumerable <BackOfficeLogin> allLogins = repo.GetLogins();

                // Check if username and password exist in database
                bool exists = LoginLogic.CheckBackOfficeLogin(username, password, allLogins);

                if (exists == true)
                {
                    model.LoggedInUser       = username;
                    model.LoggedInBackOffice = true;
                    TempData["model"]        = model;
                    return(View("Dashboard", model));
                }
                // No right username - password combination
                else
                {
                    return(RedirectToAction("BackOfficeLogin", "Login",
                                            new { error = "Deze combinatie van gebruikersnaam en wachtwoord kon niet gevonden worden" }));
                }
            }
        }
Example #2
0
        public void TestBackOfficeLogin()
        {
            // Arrange
            // create username, password and list of logins
            string existingusername           = "******";
            string existingpassword           = "******";
            List <BackOfficeLogin> loginslist = new List <BackOfficeLogin>
            {
                new BackOfficeLogin {
                    Password = "******", Username = "******"
                }
            };
            IEnumerable <BackOfficeLogin> logins = loginslist.ToEnumerable();

            // Act
            bool expectedResult = true;
            bool result         = LoginLogic.CheckBackOfficeLogin(existingusername, existingpassword, logins);

            // Assert
            Assert.AreEqual(expectedResult, result);
        }