public ActionResult Login(AccessModel model) { if (!ModelState.IsValid) { string sError = ""; foreach (var item in ModelState) { if (sError.Length > 0) { sError += ", "; } if (item.Value.Errors.Count > 0 && !item.Value.Errors[0].ErrorMessage.Contains("mail")) { sError += item.Value; } } if (sError.Length > 0) { model.ErrorMessage = sError; return(View(model)); } } bool bRet = model.LogIn(); if (bRet) { UserCache.RemoveFromCache(0, model.User.IPAddress); UserCache.AddToCache(model.User); model.GoHome = true; } //if you made it this far, the login didn't work return(View(model)); }
public ActionResult LogOff(int userID) { string ip = ""; if (ViewBag.IPAddress != null) { ip = ViewBag.IPAddress.StringSafe(); } UserType user = UserCache.GetFromCache(userID, ip); AccessModel model = new AccessModel(); UserType _user = new UserType(); if (user != null) { _user = new UserType { UserName = "******", UserID = -1, SessionStart = DateTime.Now }; } bool bRet = model.LogOff(user); if (bRet) { UserCache.RemoveFromCache(user.UserID, ""); UserCache.AddToCache(_user); } return(RedirectToAction("index", "home")); }
public ActionResult ProcessPassword(int UserID, string Token) { AccessModel model = new AccessModel(); string _token = model.GetPasswordToken(UserID); if (_token == Token || _token.ToUpper() == Token) { UserType user = model.GetUserByUserID(UserID); UserCache.AddToCache(user); return(RedirectToAction("Manage", new { UserID = UserID })); } else { model.ErrorMessage = "The token did not match"; return(View("Login", model)); } }
public ActionResult Confirmation(int UserID, string token) { AccessModel model = new AccessModel(); token = token.StringSafe(); //eliminate nulls model.UserID = UserID; model.UserToken = token; bool bRet = false; model.ErrorMessage = "If you no longer have a code, click the 'Resend' button"; if (token.Length > 0) { bRet = model.Confirm(); } if (bRet) { UserType user = new AccessModel().GetUserByUserID(UserID); if (user != null) { UserCache.AddToCache(user); UserCache.findInCache(ViewBag.IPAddress.StringSafe()); } return(RedirectToAction("index", "home")); } else if (model.UserToken.Length > 0) { model.ErrorMessage = "Confirmation Code Failed!"; } else { model.ErrorMessage = "Click Resend to receive a new confirmation message"; } return(View(model)); }