public void BlockedClientUser(UpdateClientUserBlockStatusViewModel model) { try { if (model != null) { int ClientUserRowID = db.PQClientLogins.Where(w => w.UserID.Trim() == model.UserID).FirstOrDefault().ClientUserRowID; if (ClientUserRowID > 0) { db.PQClientLogins.Single(w => w.ClientUserRowID == ClientUserRowID).BlockedDate = model.BlockedDate; db.PQClientLogins.Single(w => w.ClientUserRowID == ClientUserRowID).Status = model.Status; } } else { throw new Exception("Invalid block user details!"); } } catch (Exception) { throw; } }
public ActionResult ClientLogin(ClientLoginViewModel model) { try { if (ModelState.IsValid) { if (string.Compare(model.CRPUserName, "", false) == 0 && string.Compare(model.CRPPassWord, "", false) == 0) { ModelState.AddModelError("", "Enter User Name and Password"); } else if (string.Compare(model.CRPUserName, "", false) == 0 && string.Compare(model.CRPPassWord, "", false) != 0) { ModelState.AddModelError("", "Enter User Name"); } else if (!(string.Compare(model.CRPUserName, "", false) != 0 && string.Compare(model.CRPPassWord, "", false) == 0)) { DateTime today = DateTime.Today; string str = model.CRPUserName.Trim().ToLower(); string str1 = model.CRPPassWord.Trim().ToLower(); string[] strArrays1 = str.Split(' '); string[] strArrays2 = str1.Split(' '); string str2 = strArrays1[0]; string str3 = strArrays2[0]; if (!(string.Compare(str2, "select", false) == 0 || string.Compare(str2, "exec", false) == 0 || string.Compare(str2, "execute", false) == 0 || string.Compare(str2, "drop", false) == 0 || string.Compare(str2, "truncate", false) == 0 || string.Compare(str2, "insert", false) == 0 || string.Compare(str2, "update", false) == 0 || string.Compare(str2, "delete", false) == 0 || string.Compare(str2, "union", false) == 0 || string.Compare(str2, "create", false) == 0) ) { if (!(string.Compare(str3, "select", false) == 0 || string.Compare(str3, "exec", false) == 0 || string.Compare(str3, "execute", false) == 0 || string.Compare(str3, "drop", false) == 0 || string.Compare(str3, "truncate", false) == 0 || string.Compare(str3, "insert", false) == 0 || string.Compare(str3, "update", false) == 0 || string.Compare(str3, "delete", false) == 0 || string.Compare(str2, "union", false) == 0 || string.Compare(str2, "create", false) == 0) ) { string UserName = model.CRPUserName.Trim(); string UserPassword = model.CRPPassWord.Trim(); string encPassword = clsCommonMethods.PasswordEncrypt(model.CRPPassWord.Trim()); ClientUserLoggedViewModel loggedUser = new ClientUserLoggedViewModel(); try { loggedUser = repoAccount.GetClientUserLoggedDetails(UserName, encPassword); } catch (Exception exception1) { ViewBag.ErrorMsg = exception1.Message; clsCommonMethods.ErrorLog(Server.MapPath("~\\ErrorLogs\\Logfiles"), exception1.Message, exception1.StackTrace); } if (loggedUser == null) { var activWebUsers = repoAccount.GetAllActiveClientUsers(); foreach (var webUser in activWebUsers) { if (!(webUser.CRPUserName.Trim() == UserName) || !(webUser.CRPPassWord.Trim() != encPassword)) { continue; } Session["Counter"] = Convert.ToInt32(Session["Counter"]) + 1; break; } if (!(Convert.ToInt32(Session["Counter"]) >= 3)) { ViewBag.ErrorMsg = "Login Failed.Try Again!"; clsCommonMethods.UserLog(Server.MapPath("~\\ErrorLogs\\Unauthorized_UserLog"), UserName, UserPassword, "Client"); return(View()); } else { Session["Counter"] = 0; UpdateClientUserBlockStatusViewModel userBlocked = new UpdateClientUserBlockStatusViewModel(); userBlocked.UserID = UserName; userBlocked.BlockedDate = DateTime.Now; userBlocked.Status = 3; repoAccount.BlockedClientUser(userBlocked); repoAccount.SaveChanges(); ViewBag.ErrorMsg = "User has been Blocked, Please contact to Administrator!"; Session.Abandon(); return(View()); } } else { Session["UserName"] = UserName; Session["ClientUserRowID"] = loggedUser.ClientUserRowID; Session["ClientRowID"] = loggedUser.ClientRowID; Session["ClientName"] = loggedUser.ClientName + " (" + loggedUser.ClientSubGroupName + ")"; Session["ClientSubGroupName"] = loggedUser.ClientSubGroupName; Session["LocationName"] = loggedUser.LocationName; Session["HRApproval"] = loggedUser.HRApprovalRequired; Session["Abbreviation"] = loggedUser.Abbreviation; Session["CodeGeneration"] = loggedUser.CodeGeneration; Session["CSpocName"] = loggedUser.CSpocName; Session["CSpocEmailID"] = loggedUser.CSpocEmailID; Session["CreatedBy"] = loggedUser.CreatedBy; Session["ClientBranch"] = loggedUser.ClientBranch; Session["ClientUType"] = "Client"; Session["Valid"] = 1; if (Convert.ToInt32(Session["Valid"]) == 1) { DateTime dateTime = DateTime.Today; TimeSpan TimeSinceCreation = new TimeSpan(); if (loggedUser.ModifiedTime != null) { TimeSinceCreation = dateTime.Subtract(loggedUser.ModifiedTime.Value); } else { TimeSinceCreation = dateTime.Subtract(loggedUser.CreatedTime.Value); } if (TimeSinceCreation.Days > 179) { ViewBag.ErrorMsg = "Your password has expired. Please contact your Administrator!"; Session.Abandon(); return(View()); } else if (TimeSinceCreation.Days < 0) { clsCommonMethods.UserLog(Server.MapPath("~\\ErrorLogs\\Unauthorized_UserLog"), UserName, UserPassword, "Client"); ViewBag.ErrorMsg = "Invalid login. Please Try again!"; Session.Abandon(); return(View()); } } AddUserLoggedInDetailViewModel loggedInDetails = new AddUserLoggedInDetailViewModel(); loggedInDetails.LoginName = loggedUser.ClientName + "(" + loggedUser.ClientSubGroupName + ")"; loggedInDetails.LoginType = loggedUser.LocationName; loggedInDetails.LoginId = UserName; loggedInDetails.LoginBy = "Client"; loggedInDetails.IPDetails = Request.UserHostAddress; loggedInDetails.LoginDate = DateTime.Now; loggedInDetails.LoginStatus = 1; Session["LoginDetailRowID"] = repoAccount.AddUserLoggedInDetails(loggedInDetails); } FormsAuthentication.SetAuthCookie(UserName, false); return(RedirectToAction("DashboardClient", "Home", new { area = "ClientArea" })); } } } else { ModelState.AddModelError("", "Enter Password"); } } else { var query = from state in ModelState.Values from error in state.Errors select error.ErrorMessage; var errorList = query.ToList(); string strError = string.Empty; foreach (string str in errorList) { strError += str + "\n"; } ModelState.AddModelError("", strError); } } catch (Exception Ex) { ViewBag.ErrorMsg = Ex.Message; clsCommonMethods.ErrorLog(Server.MapPath("~\\ErrorLogs\\Logfiles"), Ex.Message, Ex.StackTrace); } return(View()); }