コード例 #1
0
 public ActionResult Login(LoginUser u, bool captchaValid)
 {
     if (ModelState.IsValid)
     {
         using (LogInService ls = new LogInService())
         {
             User user = ls.Login(u.Username, u.Password);
             if (user != null)
             {
                 String userType = ls.GetUserType(user.UserId);
                 int    id       = user.UserId;
                 Session["Id"]       = id;
                 Session["Username"] = user.Username;
                 Session["UserType"] = userType;
                 return(RedirectToAction("Index", "Home"));
             }
             else
             {
                 ViewBag.LoginError = "Invalid username or password";
                 return(View(u));
             }
         }
     }
     return(View(u));
 }