Example #1
0
 public ActionResult UnlockUser(User u)
 {
     var model = db.Users.Where(x => x.TimesLoginFail > 3).FirstOrDefault();
     if(model != null)
     {
         model.TimesLoginFail = 0;
         db.SaveChanges();
     }
     else
     {
         ViewBag.message = "List banned user is empty";
     }
     return RedirectToAction("UnlockUser", "Account");
 }
Example #2
0
 public ActionResult Login(User u, string returnUrl)
 {
     if (ModelState.IsValid)
     {
         var userSuccess = db.Users.Where(x => x.UserID.Equals(u.UserID) && x.UserPassword.Equals(u.UserPassword)).SingleOrDefault();
         var userFail = db.Users.Where(x => x.UserID.Equals(u.UserID) && x.UserPassword != u.UserPassword).SingleOrDefault();
         if (userSuccess != null && userSuccess.TimesLoginFail < 3)
         {
             //Session["TaiKhoan"] = userSuccess.UserID;
             FormsAuthentication.SetAuthCookie(userSuccess.UserID, false);
             Session["TaiKhoan"] = userSuccess.UserID;
             Session["Email"] = userSuccess.Email;
             var profile = ProfileBase.Create(u.UserID);
             if (userSuccess.DateTimeLogin == null)
             {
                 userSuccess.DateTimeLogin = DateTime.Now;
                 db.SaveChanges();
                 return RedirectToAction("FirstTimeLogin", "Account");
             }
             else
                 return RedirectToAction("Index", "Home");
         }
         else if(userFail != null && userFail.TimesLoginFail <3)
         {
             userFail.TimesLoginFail += 1;
             db.SaveChanges();
             ViewBag.Error = "Incorrect UserID or password, please try again";
             ModelState.AddModelError("", "wrong pass");
         }
         else if( userSuccess != null && userSuccess.TimesLoginFail >= 3)
         {
             ViewBag.Error = "Your account have been banned";
         }
         else if(userFail != null && userFail.TimesLoginFail >= 3)
         {
             ViewBag.Error = "Banned";
         }
     }
     return View();
 }