示例#1
0
 public ActionResult Login(LoginModel model)
 {
     if (ModelState.IsValid)
     {
         var lib    = new UserLib();
         var result = lib.Login(model.UserName, Encryptor.MD5Hash(model.Password));
         if (result == 1)
         {
             var user        = lib.GetById(model.UserName);
             var userSession = new UserLogin();
             userSession.UserName = user.UserName;
             userSession.UserID   = user.ID;
             Session.Add(CommonConstants.USER_SESSION, userSession);
             return(Redirect("/"));
         }
         else if (result == 0)
         {
             ModelState.AddModelError("", "Tài khoản không tồn tại.");
         }
         else if (result == -1)
         {
             ModelState.AddModelError("", "Tài khoản đang bị khoá.");
         }
         else if (result == -2)
         {
             ModelState.AddModelError("", "Mật khẩu không đúng.");
         }
         else
         {
             ModelState.AddModelError("", "đăng nhập không đúng.");
         }
     }
     return(View(model));
 }
        public ActionResult Login(LoginModel model)
        {
            if (ModelState.IsValid)
            {
                var lib    = new UserLib();
                var result = lib.Login(model.Username, Encryptor.MD5Hash(model.Password));
                if (result == 1)
                {
                    var user        = lib.GetById(model.Username);
                    var userSession = new UserLogin();
                    userSession.UserName = user.UserName;
                    userSession.UserID   = user.ID;
                    Session.Add(CommonConstants.USER_SESSION, userSession);
                    return(RedirectToAction("Index", "Home"));
                }
                else if (result == 0)
                {
                    ModelState.AddModelError("", "The account doesn not exist.");
                }
                else if (result == -1)
                {
                    ModelState.AddModelError("", "The account has been locked.");
                }
                else if (result == -1)
                {
                    ModelState.AddModelError("", "The account has been locked.");
                }
                else if (result == -2)
                {
                    ModelState.AddModelError("", "The password is incorrect.");
                }
                else
                {
                    ModelState.AddModelError("", "Login fail.");
                }
            }

            return(View("Index"));
        }