public ActionResult SignIn(User_DetailsModel model) { // get user info var userInfo = _userService.GetUserInfo(model.UserId, model.UserPassword); userInfo.UserComputerName = model.UserComputerName; userInfo.UserMemoryAvailable = model.UserMemoryAvailable; userInfo.UserPassword = model.UserPassword; // If user id exist in DB if (!string.IsNullOrEmpty(userInfo.UserId)) { // If user disabled if (!Convert.ToBoolean(userInfo.Enabled)) { int days = 30; if (userInfo.DisabledDate.HasValue) { days = (DateTime.Today - userInfo.DisabledDate.Value).Days; } string errorMessage = string.Format("Account inactive for more than 90 days, please request re-activation by your manager. If no further login in next {0} days you will be deleted from the system.", days); ModelState.AddModelError("UserId", errorMessage); return(View(userInfo)); } //if auto diagnose if (Convert.ToBoolean(userInfo.RunAutoDiagnostic)) { return(View(userInfo)); } // if password in DB is empty if (Convert.ToBoolean(userInfo.IsPasswordEmpty)) { _userService.SetFirstTimeUserId(userInfo.UserId); return(Redirect(Url.Process(PredefinedProcess.FirstTimeNewUser))); } // This is made for clean back url from session and flag string urlForback = _userService.GetUrlForBack() ?? "/"; bool IsAutoSignIn = _userService.IsAutoSignIn(); _userService.SetAuthInfo(userInfo); // Check if paswword is expired if (userInfo.PasswordExpired && !userInfo.ClientPriorityBooking) { return(Redirect(Url.Process(PredefinedProcess.ExpiredPassword))); } // Redirect back if (IsAutoSignIn && !urlForback.Contains("/")) { return(Redirect(Url.Process(Convert.ToInt32(urlForback)))); } // If auto sign in false, then clear self process var process = new ProcessController(); process.RemoveCurrentProcess(); return(Redirect(urlForback)); } userInfo.RunAutoDiagnostic = 0; userInfo.UserId = model.UserId; if (!userInfo.ClientPriorityBooking) { ModelState.AddModelError("UserId", "User not found! Check login and password."); } else { ModelState.AddModelError("UserId", "Employee Number not found. Check login and your store number. "); } return(View(userInfo)); }
public ActionResult SignIn(User_DetailsModel model) { if (string.IsNullOrEmpty(model.UserId)) { ModelState.AddModelError("UserId", "Please enter employee number"); return(View(model)); } // get user info var userInfo = _userService.SignIn(model.UserId, model.UserPassword); userInfo.UserComputerName = model.UserComputerName; userInfo.UserMemoryAvailable = model.UserMemoryAvailable; userInfo.UserPassword = model.UserPassword; // If user id exist in DB if (!string.IsNullOrEmpty(userInfo.UserId)) { string errorMessage; if (userInfo.NumberOfLogInFailures.HasValue) { if (userInfo.NumberOfLogInFailures.Value <= 2) { string s = userInfo.NumberOfLogInFailures.Value == 1 ? "s" : ""; userInfo.RunAutoDiagnostic = 0; errorMessage = string.Format("The given password was incorrect. {0} attempt{1} remain before the account is deactivated.", 3 - userInfo.NumberOfLogInFailures.Value, s); } else { errorMessage = "It was 3rd time you entered invalid password and the account was deactivated. Please request re-activation by your manager."; } userInfo.UserPassword = string.Empty; ModelState.AddModelError("UserId", errorMessage); return(View(userInfo)); } // If user disabled if (!userInfo.Enabled) { if (userInfo.Lastacdt.HasValue && ((DateTime.Today - userInfo.Lastacdt.Value).Days) > 90) { errorMessage = string.Format("Account inactive for more than 90 days, please request re-activation by your manager. If no further login in next {0} days you will be deleted from the system.", 120 - (DateTime.Today - userInfo.Lastacdt.Value).Days); } else { errorMessage = "Account inactive, please request re-activation by your manager."; } ModelState.AddModelError("UserId", errorMessage); return(View(userInfo)); } //if auto diagnose if (Convert.ToBoolean(userInfo.RunAutoDiagnostic)) { return(View(userInfo)); } // if password in DB is empty if (Convert.ToBoolean(userInfo.IsPasswordEmpty)) { _userService.SetFirstTimeUserId(userInfo.UserId); return(Redirect(Url.Process(PredefinedProcess.FirstTimeNewUser))); } // This is made for clean back url from session and flag string urlForback = _userService.GetUrlForBack() ?? "/"; bool IsAutoSignIn = _userService.IsAutoSignIn(); // Check if paswword is expired, or if ReminderQuestion, ReminderAnswer and/or DateOfBirth need to be set if (userInfo.PasswordExpired || string.IsNullOrEmpty(userInfo.ReminderQuestion) || string.IsNullOrEmpty(userInfo.ReminderAnswer) || !userInfo.DateOfBirth.HasValue) { _userService.SetFirstTimeUserId(userInfo.UserId); HttpContext.Session["signInUserInfo"] = userInfo; return(Redirect(Url.Process(PredefinedProcess.ExpiredPassword))); } SetAuthInfo(userInfo); // Redirect back if (IsAutoSignIn && !urlForback.Contains("/")) { return(Redirect(Url.Process(Convert.ToInt32(urlForback)))); } // If auto sign in false, then clear self process var process = new ProcessController(); process.RemoveCurrentProcess(); return(Redirect(urlForback)); } userInfo.RunAutoDiagnostic = 0; userInfo.UserId = model.UserId; ModelState.AddModelError("UserId", "User not found! Check login and password."); return(View(userInfo)); }