Advertisement
Guest User

Untitled

a guest
Aug 12th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.99 KB | None | 0 0
  1.         public ActionResult LogOn(string myCaptcha,string attempt,User userToLogin,string returnUrl)
  2.         {
  3.             if (!CaptchaHelper.VerifyAndExpireSolution(HttpContext, myCaptcha, attempt))
  4.             {
  5.                 // Redisply the view width an error message
  6.                 ModelState.AddModelError("", "验证码错误!");
  7.             }
  8.  
  9.             if (ModelState.IsValid)
  10.             {
  11.                 var users = unitOfWork.UsersRepository.Get(
  12.                 filter: x => x.UserName == userToLogin.UserName && x.Password == userToLogin.Password
  13.                     );
  14.  
  15.                 if (users.Count() > 0) // login succeed
  16.                 {
  17.                     Session["UserID"] = users.First();
  18.  
  19.                     return Redirect(returnUrl??"~/Admin");
  20.                 }
  21.                 else
  22.                 {
  23.                     ModelState.AddModelError(string.Empty, "登入失败,用户名或密码错误");
  24.                 }
  25.             }
  26.  
  27.             return View();
  28.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement