/// <summary> /// Single point logoff /// </summary> public static void SignOut(string urlToRedirect, bool removeLogin) { // Log User Off from Cookie Authentication System FormsAuthentication.SignOut(); // Invalidate roles token HttpCookie hck = HttpContext.Current.Response.Cookies["portalroles"]; hck.Value = null; hck.Expires = new DateTime(1999, 10, 12); hck.Path = "/"; if (removeLogin) { // Obtain PortalSettings from Current Context PortalSettings portalSettings = (PortalSettings)HttpContext.Current.Items[strPortalSettings]; // Invalidate Portal Alias Cookie security HttpCookie xhck = HttpContext.Current.Response.Cookies["Rainbow_" + portalSettings.PortalAlias.ToLower()]; xhck.Value = null; xhck.Expires = new DateTime(1999, 10, 12); xhck.Path = "/"; } // [START] [email protected] remove user window information // User Information // valid user if (HttpContext.Current.User != null) { // Obtain PortalSettings from Current Context //Ender 4 July 2003: Added to support the Monitoring module by Paul Yarrow PortalSettings portalSettings = (PortalSettings)HttpContext.Current.Items[strPortalSettings]; // User Information UsersDB users = new UsersDB(); MembershipUser user = users.GetSingleUser(HttpContext.Current.User.Identity.Name); // get user id // by ghalib ghniem Guid uid = (Guid)user.ProviderUserKey; //ghalib ghniem [email protected] 22 February 2010 //cause already in context there is the old user name, and there is no //data retrived when we ask for that old one that we changed it, it ( Guid userId = (Guid)user.ProviderUserKey;) will make an exception //so we have to check before we say Guid userId = (Guid)user.ProviderUserKey; Guid uid = Guid.Empty; if (user != null) { uid = (Guid)user.ProviderUserKey; } //end of ghalib changes if (!uid.Equals(Guid.Empty)) { try { if (Config.EnableMonitoring) { Monitoring.LogEntry(uid, portalSettings.PortalID, -1, "Logoff", string.Empty); } } catch {} } } // [END ] [email protected] remove user window information //Redirect user back to the Portal Home Page if (urlToRedirect.Length > 0) { HttpContext.Current.Response.Redirect(urlToRedirect); } }
public static string SignOn(string user, string password, bool persistent, string redirectPage) { // Obtain PortalSettings from Current Context PortalSettings portalSettings = (PortalSettings)HttpContext.Current.Items[strPortalSettings]; MembershipUser usr; UsersDB accountSystem = new UsersDB(); // Attempt to Validate User Credentials using UsersDB usr = accountSystem.Login(user, password); // Thierry (tiptopweb), 12 Apr 2003: Save old ShoppingCartID // ShoppingCartDB shoppingCart = new ShoppingCartDB(); // string tempCartID = ShoppingCartDB.GetCurrentShoppingCartID(); if (usr != null) { // Ender, 31 July 2003: Support for the monitoring module by Paul Yarrow if (Config.EnableMonitoring) { try { Monitoring.LogEntry((Guid)usr.ProviderUserKey, portalSettings.PortalID, -1, "Logon", string.Empty); } catch { ErrorHandler.Publish(LogLevel.Info, "Cannot monitoring login user " + usr.UserName); } } // Use security system to set the UserID within a client-side Cookie FormsAuthentication.SetAuthCookie(usr.ToString(), persistent); // Rainbow Security cookie Required if we are sharing a single domain // with portal Alias in the URL // Set a cookie to persist authentication for each portal // so user can be reauthenticated // automatically if they chose to Remember Login HttpCookie hck = HttpContext.Current.Response.Cookies["Rainbow_" + portalSettings.PortalAlias.ToLower()]; hck.Value = usr.ToString(); //Fill all data: name + email + id hck.Path = "/"; if (persistent) // Keep the cookie? { hck.Expires = DateTime.Now.AddYears(50); } else { //jminond - option to kill cookie after certain time always // jes1111 // if(ConfigurationSettings.AppSettings["CookieExpire"] != null) // { // int minuteAdd = int.Parse(ConfigurationSettings.AppSettings["CookieExpire"]); int minuteAdd = Config.CookieExpire; DateTime time = DateTime.Now; TimeSpan span = new TimeSpan(0, 0, minuteAdd, 0, 0); hck.Expires = time.Add(span); // } } if (redirectPage == null || redirectPage.Length == 0) { // Redirect browser back to originating page if (HttpContext.Current.Request.UrlReferrer != null) { HttpContext.Current.Response.Redirect(HttpContext.Current.Request.UrlReferrer.ToString()); } else { HttpContext.Current.Response.Redirect(Path.ApplicationRoot); } return(usr.Email); } else { HttpContext.Current.Response.Redirect(redirectPage); } } return(null); }