コード例 #1
0
        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, portalSettings.PortalAlias);

            // 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);

                // Appleseed 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["Appleseed_" + 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;
        }