// // GET: /Account/LogOff public ActionResult LogOff() { _log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); AppLog oAppLog = new AppLog(); oAppLog.UserName = CurrentUser.UserName; oAppLog.Method = Convert.ToString(System.Reflection.MethodBase.GetCurrentMethod().Name); oAppLog.Module = Convert.ToString(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); oAppLog.LogDate = DateTime.UtcNow; try { if (_log.IsInfoEnabled) { _log.Info("Logging off..Calling Logout method of KMSecurity in AccountController."); } KMSecurity.Logout(); oAppLog.Message = "LogOff was sucessfull"; this.LogActivity(oAppLog); if (logDB.IsInfoEnabled) { logDB.Info(""); } if (_log.IsInfoEnabled) { _log.Info("Logged off."); } if (_log.IsInfoEnabled) { _log.Info("Redirection to the Home page."); } return(RedirectToAction("Index", "Home")); } catch (Exception ex) { oAppLog.Message = "LogOff was unsucessfull"; this.LogActivity(oAppLog); if (logDB.IsInfoEnabled) { logDB.Info(""); } if (_log.IsErrorEnabled) { _log.Error(ex.Message, ex); } throw ex; } }
public ActionResult LogOnWithWindowsAuthentication() { try { string username = string.Empty; string returnUrl = string.Empty; NameValueCollection n = Request.QueryString; if (n.HasKeys()) { username = n.GetKey(0); if (username.Contains("userName")) { username = n.Get(0); } if (n.Keys.Count > 1) { returnUrl = n.GetKey(1); if (returnUrl.Contains("returnUrl")) { returnUrl = n.Get(1); } } } Session["windowsUserName"] = username; _log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); if (_log.IsInfoEnabled) { _log.Info(username + " from LDAP"); } AppLog oAppLog = new AppLog(); oAppLog.UserName = username; oAppLog.Method = Convert.ToString(System.Reflection.MethodBase.GetCurrentMethod().Name); oAppLog.Module = Convert.ToString(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); oAppLog.LogDate = DateTime.UtcNow; if (_log.IsInfoEnabled) { _log.Info("Logging in..Calling KMSEcurity LoginWithWindowsAuthentication method."); } if (KMSecurity.LoginWithWindowsAuthentication(username, false)) { if (_log.IsInfoEnabled) { _log.Info(username + " has been logged in...."); } oAppLog.Message = "LogOn was sucessfull."; this.LogActivity(oAppLog); if (logDB.IsInfoEnabled) { logDB.Info(""); } } else { if (_log.IsInfoEnabled) { _log.Info(username + " has not been logged in...."); } oAppLog.Message = "LogOn was unSucessfull."; } if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\")) { return(Redirect(returnUrl)); } else { return(RedirectToAction("Index", "Home")); } } catch (Exception ex) { if (_log.IsErrorEnabled) { _log.Error(ex.Message, ex); } throw ex; } // If we got this far, something failed, redisplay form }
public ActionResult Login(LogOnModel model, string returnUrl) { try { _log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); AppLog oAppLog = new AppLog(); oAppLog.UserName = model.UserName; oAppLog.Method = Convert.ToString(System.Reflection.MethodBase.GetCurrentMethod().Name); oAppLog.Module = Convert.ToString(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); oAppLog.LogDate = DateTime.UtcNow; if (ModelState.IsValid) { if (_log.IsInfoEnabled) { _log.Info("Logging in..Calling KMSEcurity Login method."); } if (KMSecurity.Login(model.UserName, model.Password, model.RememberMe)) { if (_log.IsInfoEnabled) { _log.Info(model.UserName + " has been logged in...."); } oAppLog.Message = "LogOn was sucessfull."; this.LogActivity(oAppLog); if (logDB.IsInfoEnabled) { logDB.Info(""); } if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\")) { return(Redirect(returnUrl)); } else { return(RedirectToAction("Index", "Home")); } } else { if (_log.IsInfoEnabled) { _log.Info(model.UserName + " has not been logged in...."); } oAppLog.Message = "LogOn was unsucessfull."; this.LogActivity(oAppLog); if (logDB.IsInfoEnabled) { logDB.Info(""); } ModelState.AddModelError("", "The user name or password provided is incorrect."); } } } catch (Exception ex) { if (_log.IsErrorEnabled) { _log.Error(ex.Message, ex); } throw ex; } // If we got this far, something failed, redisplay form return(View(model)); }