コード例 #1
0
        public ActionResult Index(LoginModel model)
        {
            if (ModelState.IsValid)
            {
                var user = Db.Users.Where(i => i.FirstName == model.Username && i.Password == model.Password);

                if (user.Any())  //Simulate data store call where Username/Password
                {
                    //Creates an authentication ticket for the supplied user name and adds it to the cookies collection.
                    //false will log off automatically when browser close.
                    FormsAuthentication.SetAuthCookie(model.Username, false);

                    // checks if the user is the College Secretary if so then redirect to HomeSecretary
                    if (model.Username == "Secretary" && model.Password == "1111")
                    {
                        return RedirectToAction("index", "HomeSecretary");
                    }
                    else  // else the user is one of the lecturers then redirect to Home
                    {
                        return RedirectToAction("index", "Home");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Invalid username or password");
                }
            }
            return View();
        }
コード例 #2
0
 public void TestMethod4()
 {
     LoginController lg = new LoginController();
     LoginModel model = new LoginModel();
     model.Username = "******";
     model.Password = "******";
     var res = lg.Index(model) as ActionResult;
     Assert.AreEqual("System.Web.Mvc.ViewResult", res.ToString());
 }
コード例 #3
0
 public void TestMethod2()
 {
     LoginController lg = new LoginController();
     LoginModel model = new LoginModel();
     model.Username = "******";
     model.Password = "******";
     var res = lg.isUserValid(model);
     Assert.AreEqual("User is invalid", res);
 }
コード例 #4
0
 public String isUserValid(LoginModel model)
 {
     //Simulate data store call where Username/Password
     if (model.Username == "a" && model.Password == "a")
     {
         return "User is valid";
     }
     else
     {
         return "User is invalid";
     }
 }