public ActionResult Login(ViewLogin login) { if (ModelState.IsValid) { int status = usersDAO.Login(login.Email, login.Password); switch (status) { case 1: var user = db.Users.FirstOrDefault(t => t.user_email == login.Email && t.user_pass == login.Password); HttpCookie cookie = new HttpCookie("user_id", user.user_id.ToString()); cookie.Expires.AddDays(10); Response.Cookies.Set(cookie); return(Redirect("/")); case -1: TempData["noti_login"] = "******"; break; case -2: TempData["noti_login"] = "******"; break; case -3: TempData["noti_login"] = "******"; break; default: TempData["noti_login"] = "******"; break; } } return(View(login)); }
public ActionResult Login(User user) { if (ModelState.IsValid) { var dao = new UsersDao(); var result = dao.Login(user.UserName, Encryptor.MD5Hash(user.Password)); if (result == 1) { var usr = dao.UserGetById(user.UserName); var userSession = new Common.UserLogin(); userSession.UserName = usr.UserName; userSession.UserID = usr.ID; Session.Add(Common.CommonConstant.User_Session, userSession); return(RedirectToAction("Index", "Users")); } else if (result == 0) { ModelState.AddModelError("", "Username or Password is incorrect!"); } else if (result == -1) { ModelState.AddModelError("", "Account is locked!"); } else { ModelState.AddModelError("", "Account is not sign up!"); } } return(View("Login")); }
public ActionResult Login(LoginModel model) { if (ModelState.IsValid) { var dao = new UsersDao(); var result = dao.Login(model.UserName, Md5Encryptor.Md5Hash(model.Password)); if (result == 0) { var user = dao.GetById(model.UserName); var userSession = new UserLogin(); userSession.UserName = user.UserName; Session.Add(CommonConstants.USER_SESSION, userSession); return(RedirectToAction("Index", "Home")); } else if (result == 1) { ModelState.AddModelError("", "Username is not exist"); TempData["AlertMessage"] = "Username is not exist"; TempData["AlertType"] = "alert-danger"; } else { ModelState.AddModelError("", "Wrong Password"); TempData["AlertMessage"] = "Wrong password"; TempData["AlertType"] = "alert-danger"; } } return(View("Index")); }
public ActionResult Index(LoginModel model) { var dao = new UsersDao(); string Password = Encryptor.MD5Hash(model.Password); var result = dao.Login(model.UserName, Password); if (result) { var user = dao.GetById(model.UserName); var userSession = new UserLogin(); userSession.UserName = user.UserName; userSession.UserID = user.UserId; Session.Add(CommonConstants.USER_SESSION, userSession); return(RedirectToAction("Index", "Index")); } else { ModelState.AddModelError("", "Đăng nhập không đúng."); } return(View()); }