public string Logout() { string clientName = "unknown"; if (DomainManager.CurrentClient != null) { clientName = DomainManager.CurrentClient.ClientName; } TLogging.Log("Logout from session: ClientName=" + clientName, TLoggingType.ToLogfile | TLoggingType.ToConsole); if (DomainManager.CurrentClient == null) { TSession.Clear(); } else { DomainManager.CurrentClient.EndSession(); } Dictionary <string, object> result = new Dictionary <string, object>(); result.Add("resultcode", "success"); return(JsonConvert.SerializeObject(result)); }
private eLoginEnum LoginInternal(string username, string password, Version AClientVersion, out Int32 AClientID, out string AWelcomeMessage, out Boolean ASystemEnabled, out IPrincipal AUserInfo, out Boolean AMustChangePassword) { AUserInfo = null; ASystemEnabled = true; AWelcomeMessage = string.Empty; AClientID = -1; AMustChangePassword = false; if (DBAccess.GDBAccessObj == null) { TServerManager.TheCastedServerManager.EstablishDBConnection(); } try { TConnectedClient CurrentClient = TClientManager.ConnectClient( username.ToUpper(), password.Trim(), HttpContext.Current.Request.UserHostName, HttpContext.Current.Request.UserHostAddress, AClientVersion, TClientServerConnectionType.csctRemote, out AClientID, out AWelcomeMessage, out ASystemEnabled, out AUserInfo); TSession.SetVariable("LoggedIn", true); // the following values are stored in the session object DomainManager.GClientID = AClientID; DomainManager.CurrentClient = CurrentClient; UserInfo.GUserInfo = (TPetraPrincipal)AUserInfo; DBAccess.GDBAccessObj.UserID = username.ToUpper(); TServerManager.TheCastedServerManager.AddDBConnection(DBAccess.GDBAccessObj); AMustChangePassword = (((TPetraPrincipal)AUserInfo).LoginMessage == SharedConstants.LOGINMUSTCHANGEPASSWORD); return(eLoginEnum.eLoginSucceeded); } catch (Exception e) { TLogging.Log(e.Message); TLogging.Log(e.StackTrace); TSession.SetVariable("LoggedIn", false); if (DBAccess.GDBAccessObj != null) { DBAccess.GDBAccessObj.CloseDBConnection(); } TSession.Clear(); return(TClientManager.LoginErrorFromException(e)); } }
public bool Logout() { TLogging.Log("Logout from session: ClientName=" + DomainManager.CurrentClient.ClientName, TLoggingType.ToLogfile | TLoggingType.ToConsole); if (DomainManager.CurrentClient == null) { TSession.Clear(); } else { DomainManager.CurrentClient.EndSession(); } return(true); }
/// <summary> /// end the session, and release all resources /// </summary> public void EndSession() { if (FAppDomainStatus == TSessionStatus.adsStopped) { TLogging.Log("EndSession (for client '" + this.ClientName + "'): Session has been stopped already!"); return; } TLogging.Log("EndSession (for client '" + this.ClientName + "'): Session is about to getting stopped!"); // TODORemoting // release all UIConnector objects ClientStillAliveCheck.TClientStillAliveCheck.StopClientStillAliveCheckThread(); TLogging.Log("EndSession (for client '" + this.ClientName + "'): Checking whether there is a DB connection"); // close db connection if (DBAccess.GDBAccessObj != null) { TLogging.Log("EndSession (for client '" + this.ClientName + "'): Closing DB connection"); DBAccess.GDBAccessObj.CloseDBConnection(true); } TLogging.Log("EndSession (for client '" + this.ClientName + "'): Checking whether there is a HttpSession.Current object"); // clear the session object if (HttpContext.Current != null) { TLogging.Log("EndSession (for client '" + this.ClientName + "'): Clearing Session"); TSession.Clear(); } FClientDisconnectionFinishedTime = DateTime.Now; FAppDomainStatus = TSessionStatus.adsStopped; TLogging.LogAtLevel(1, "Session for client " + this.ClientName + " has been destroyed successfully!"); }
/// <summary> /// initialise the server once for everyone /// </summary> public static bool Init() { if (ConfigFileName == string.Empty) { // make sure the correct config file is used if (Environment.CommandLine.Contains("/appconfigfile=")) { // this happens when we use fastcgi-mono-server4 ConfigFileName = Environment.CommandLine.Substring( Environment.CommandLine.IndexOf("/appconfigfile=") + "/appconfigfile=".Length); if (ConfigFileName.IndexOf(" ") != -1) { ConfigFileName = ConfigFileName.Substring(0, ConfigFileName.IndexOf(" ")); } } else { // this is the normal behaviour when running with local http server ConfigFileName = AppDomain.CurrentDomain.BaseDirectory + Path.DirectorySeparatorChar + "web.config"; } } new TAppSettingsManager(ConfigFileName); new TSrvSetting(); new TLogging(TSrvSetting.ServerLogFile); TLogging.DebugLevel = TAppSettingsManager.GetInt16("Server.DebugLevel", 0); if (HttpContext.Current != null) { HttpContext.Current.Server.ScriptTimeout = Convert.ToInt32( TimeSpan.FromMinutes(TAppSettingsManager.GetInt32("WebRequestTimeOutInMinutes", 15)). TotalSeconds); } // if the Login Method is called: reset cookie, ignore any old session if ((HttpContext.Current != null) && (HttpContext.Current.Request.PathInfo == "/Login")) { TSession.Clear(); } if (TServerManager.TheServerManager == null) { Catalog.Init(); TServerManager.TheServerManager = new TServerManager(); try { TServerManager.TheCastedServerManager.EstablishDBConnection(); TSystemDefaultsCache.GSystemDefaultsCache = new TSystemDefaultsCache(); DomainManager.GetSiteKeyFromSystemDefaultsCacheDelegate = @TSystemDefaultsCache.GSystemDefaultsCache.GetSiteKeyDefault; TLanguageCulture.Init(); // initialise the cached tables TSetupDelegates.Init(); TUserDefaults.InitializeUnit(); } catch (Exception e) { TLogging.Log(e.Message); TLogging.Log(e.StackTrace); throw; } TLogging.Log("Server has been initialised"); return(true); } if (DomainManager.CurrentClient != null) { if (DomainManager.CurrentClient.FAppDomainStatus == TSessionStatus.adsStopped) { TLogging.Log("There is an attempt to reconnect to stopped session: " + DomainManager.CurrentClient.ClientName); HttpContext.Current.Response.Status = "404 " + THTTPUtils.SESSION_ALREADY_CLOSED; HttpContext.Current.Response.End(); } // TLogging.Log("Init(): WebService Method name that got called: " + HttpContext.Current.Request.PathInfo); if (HttpContext.Current.Request.PathInfo != "/PollClientTasks") { DomainManager.CurrentClient.UpdateLastAccessTime(); } } return(false); }