コード例 #1
0
        public static void AddLecturer()
        {
            String   k   = "";
            var      str = DateTime.Now.ToLongTimeString();
            Lecturer lec = new Lecturer();

            lec.Email    = "*****@*****.**" + str;
            lec.Name     = "lectest";
            lec.Password = "******";
            bool b = LecturerManager.AddLecturer(lec, out k);

            var student = LecturerManager.getLecturerById(LecturerManager.GetLecturerIdByEmail("*****@*****.**" + str));

            Assert.IsTrue(student.Name == "lectest");
            Assert.IsTrue(student.Email == ("*****@*****.**" + str));
            Assert.IsTrue(CommonManager.Hash("123456") == student.Password);
        }
コード例 #2
0
        public ActionResult Login(Login login)
        {
            string errorMessage = String.Empty;
            var    status       = CommonManager.Login(login, out errorMessage);

            if (!ModelState.IsValid)
            {
                return(View());
            }
            else if (status == CommonManager.LoginStatus.Lecturer)
            {
                Session["IsStudent"]      = false;
                Session["Email"]          = login.Email;
                Session["TimeOfCreation"] = DateTime.Now;
                Session["Id"]             = LecturerManager.GetLecturerIdByEmail(login.Email);
                return(RedirectToAction("Manager", "Dashboard"));
            }
            else if (status == CommonManager.LoginStatus.Student)
            {
                Session["IsStudent"]      = true;
                Session["Email"]          = login.Email;
                Session["TimeOfCreation"] = DateTime.Now;
                Session["Id"]             = StudentManager.GetStudentIdByEmail(login.Email);
                return(RedirectToAction("Manager", "Dashboard"));
            }

            if (errorMessage != "")
            {
                ViewBag.Error = errorMessage;
            }
            else if (status == CommonManager.LoginStatus.DoesntExist)
            {
                ViewBag.Error = "Invalid credentials";
            }

            return(RedirectToAction("Login", new { errorMessage = ViewBag.Error }));
        }