示例#1
0
        public IActionResult Login()
        {
            if (!DAL.TestConnection())
            {
                SessionVariables.SetErrorMessageStay("Unable to make a connection with the database. Please check with an administrator.");
            }
            User currentUser = SessionVariables.GetCurrentUser(HttpContext);

            if (currentUser != null && currentUser.Role != null && currentUser.Role.Sections.CanView)
            {
                return(RedirectToAction("Index", "Section"));
            }
            return(View());
        }
示例#2
0
 public IActionResult Login([Bind("Username, Password")] User user)
 {
     if (!DAL.TestConnection())
     {
         SessionVariables.SetErrorMessageStay("Unable to make a connection with the database. Please check with an administrator.");
         return(View());
     }
     if (ModelState.IsValid)
     {
         User currentUser = DAL.GetUser(user.Username, user.Password);
         if (currentUser != null)
         {
             SessionVariables.SetCurrentUserID(HttpContext, currentUser.ID);
             SessionVariables.SetSuccessMessage("Logged in");
             return(RedirectToAction("Index", "Section"));
         }
         SessionVariables.SetErrorMessage("Error logging in, Check username and password");
         user.Password = "";
         return(View(user));
     }
     return(View());
 }