/// <summary> /// User checking /// </summary> /// <returns>Redirect to page</returns> public ActionResult SignIn(bool notAdmin = false) { // Save Url for return if (!_userService.IsAutoSignIn()) { if (Request.UrlReferrer != null) { if (Request.UrlReferrer.ToString().IndexOf("SignIn") <= 0) { _userService.SetUrlForBack(Request.UrlReferrer != null ? Request.UrlReferrer.ToString() : "/"); } } else { _userService.SetUrlForBack("/"); } } else { _userService.SetUrlForBack(Request.UrlReferrer != null ? Request.UrlReferrer.ToString() : "/"); } var model = new User_DetailsModel { UserId = String.Empty }; // if admin error if (notAdmin) { ViewBag.userNotAdminMsg = "You must be administrator."; } return(View("SignIn", model)); }
public ActionResult CheckDetails() { User_DetailsModel userInfo = null; if (HttpContext.Session["signInUserInfo"] == null) { return(RedirectToAction("SignIn")); } else { userInfo = (User_DetailsModel)HttpContext.Session["signInUserInfo"]; } if (string.IsNullOrEmpty(userInfo.ReminderQuestion) || string.IsNullOrEmpty(userInfo.ReminderAnswer) || !userInfo.DateOfBirth.HasValue) { return(View("MissingDetails", new User_AccountInfoModel() { ReminderQuestion = userInfo.ReminderQuestion, ReminderAnswer = userInfo.ReminderAnswer, Day = userInfo.DateOfBirth.HasValue ? userInfo.DateOfBirth.Value.Day : 0, Month = userInfo.DateOfBirth.HasValue ? userInfo.DateOfBirth.Value.Month : 0, Year = userInfo.DateOfBirth.HasValue ? userInfo.DateOfBirth.Value.Year : 0 })); } else { SetAuthInfo(userInfo); return(Redirect(Url.ProcessNextStep())); } }
/// <summary> /// Set auth info /// </summary> /// <param name="model"></param> public void SetAuthInfo(User_DetailsModel model) { var _storeService = new StoreService(_dataContext); // This is made for clean back url from session and flag var urlForback = GetUrlForBack() ?? "/"; bool AutoSignIn = this.IsAutoSignIn(); // Clear from Session SetUrlForBack(null); IsAutoSignIn(false); SetUserId(model.UserId); SetUserName(model.UserName); SetGroup(model.GroupID); // If no store indfo then set store in cookies if (model.UserStoreID.HasValue && (!_storeService.IsStoreInfoExist())) { _storeService.SetStoreInfo(model.UserStoreID.Value, model.UserStoreName); IsCallCenter(model.ClientPriorityBooking); } if (model.UserStoreID.HasValue && (_storeService.IsStoreInfoExist())) { IsOffshoreCallCenter(model.GroupID); } FormsAuthentication.SetAuthCookie(model.UserId, createPersistentCookie: false); // Add log record to database var log = new Log(_dataContext); var browser = HttpContext.Current.Request.Browser; log.Database.SignIn.Add(String.Format("{0} v{1}", browser.Browser, browser["version"])); }
public ActionResult MissingDetails(User_AccountInfoModel model) { if (ModelState.IsValid) { bool? errorVariableIsYear; string errorMessage = CAST.Validation.DateOfBirthValidation.Check(model.Year, model.Month, model.Day, out errorVariableIsYear); if (!string.IsNullOrEmpty(errorMessage)) { if (errorVariableIsYear.Value) { ModelState.AddModelError("Year", errorMessage); } else { ModelState.AddModelError("Day", errorMessage); } return(View(model)); } model.UserId = _userService.GetFirstTimeUserId(); model.DateOfBirth = new DateTime(model.Year, model.Month, model.Day); _userService.SaveUserDetails(model); User_DetailsModel userInfo = (User_DetailsModel)HttpContext.Session["signInUserInfo"]; SetAuthInfo(userInfo); return(Redirect(Url.ProcessNextStep())); } return(View(model)); }
private void SetAuthInfo(User_DetailsModel userInfo) { _userService.SetAuthInfo(userInfo); if (HttpContext.Session["signInUserInfo"] != null) { HttpContext.Session.Remove("signInUserInfo"); } }
/// <summary> /// - First step - password is expired /// _userState.FirstTimeUserId - user ID </summary> /// <returns></returns> public ActionResult ExpiredPassword() { User_DetailsModel userInfo = (User_DetailsModel)HttpContext.Session["signInUserInfo"]; if (userInfo.PasswordExpired) { ViewBag.header = "Period of validity of the password expired. "; return(View("NewPassword")); } else { return(Redirect(Url.ProcessNextStep())); } }
private void SetAuthInfo(User_DetailsModel userInfo) { _userService.SetAuthInfo(userInfo); string[] v = new string[] { "signInUserInfo", "signInDateTime", "errorMessage" }; foreach (string key in v) { if (HttpContext.Session[key] != null) { HttpContext.Session.Remove(key); } } }
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)); }