public ActionResult Index(string id = null, string userMsgRequestIdParam = null) { FormsAuthenticationTicket ticket = null; try { int userId = 0, latestSessionId = 0; _UserDetailsBusinessLogic = new UserDetailsBusinessLogic(); userMsgRequestId = userMsgRequestIdParam; if (id == null || id == "") { System.Web.Security.FormsAuthentication.SignOut(); Session.Abandon(); HttpCookie authCookie = Request.Cookies[FormsAuthentication.FormsCookieName]; if (authCookie.Value != "") { //Before destroying the session cookie // 1.Update the session details to UserSessionLog(Update the LoggedOffTimestamp) // 2.Update the 'IsLoggedIn' flsg of SystemUser as false ticket = FormsAuthentication.Decrypt(authCookie.Value); userId = _UserDetailsBusinessLogic.GetUserID(ticket.Name); latestSessionId = _UserDetailsBusinessLogic.GetLatestSessionIdForUser(userId); _UserDetailsBusinessLogic.UpdateUserSessionLog(latestSessionId); _UserDetailsBusinessLogic.UpdateLoggedInStatus(userId, false); authCookie.Expires = DateTime.Now.AddSeconds(-1); Response.Cookies.Add(authCookie); } } else { System.Web.HttpContext.Current.Session["LoginUserType"] = id; } return(View()); } catch (Exception ex) { currentFile = this.ControllerContext.RouteData.Values["controller"].ToString(); // System.Diagnostics.StackTrace(true).GetFrame(0).GetFileName(); StackTrace st = new StackTrace(); StackFrame sf = st.GetFrame(0); methodName = sf.GetMethod().Name; ErrorLogHelper.UpdatingErrorLog(currentFile + "-" + methodName, ticket == null ? "N/A" : ticket.Name, ex); this.HttpContext.Session["ErrorMsg"] = "PageLoadError"; return(RedirectToAction("Index", "LoginError")); } }
public ActionResult Authenticate(LoginViewModel model) { try { _UserDetailsBusinessLogic = new UserDetailsBusinessLogic(); int userId = 0; if (LoginAuth(model.Username, model.Password)) { if (_UserDetailsBusinessLogic.IsUserActive(model.Username) == true) { //Before redirecting: // 1.Add the session details to UserSessionLog // 2.Update the 'IsLoggedIn' flsg of SystemUser as true userId = _UserDetailsBusinessLogic.GetUserID(model.Username); _UserDetailsBusinessLogic.SaveSessionDetails(userId, IPAddress, countryCode, country, city, region); _UserDetailsBusinessLogic.UpdateLoggedInStatus(userId, true); if (userMsgRequestId != null) { return(RedirectToAction("Index", "UserMessage", new RouteValueDictionary(new { requestId = userMsgRequestId }))); } return(RedirectToAction("Index", "LandingPage")); } else { TempData["notice"] = "Oops..Your account has been inactivated temporarily.Please contact the System Administrator"; return(RedirectToAction("Index", "Login")); } } else { this.HttpContext.Session["ErrorMsg"] = "LoginErr"; TempData["notice"] = "Username Pasword Combination Is Incorrect"; return(RedirectToAction("Index", "Login")); } } catch (Exception ex) { currentFile = this.ControllerContext.RouteData.Values["controller"].ToString(); // System.Diagnostics.StackTrace(true).GetFrame(0).GetFileName(); StackTrace st = new StackTrace(); StackFrame sf = st.GetFrame(0); methodName = sf.GetMethod().Name; ErrorLogHelper.UpdatingErrorLog(currentFile + "-" + methodName, "N/A", ex); return(RedirectToAction("Index", "Login")); } }