Ejemplo n.º 1
0
        private void CreateUser(string windowsLiveId)
        {
            SiteUser newUser = new SiteUser(siteSettings);

            newUser.WindowsLiveId = windowsLiveId;
            newUser.Name          = txtUserName.Text;
            newUser.LoginName     = txtUserName.Text;
            newUser.Email         = txtEmail.Text;
            CMembershipProvider CMembership = (CMembershipProvider)Membership.Provider;

            newUser.Password = CMembership.EncodePassword(SiteUser.CreateRandomPassword(7), siteSettings);
            //newUser.Password = SiteUser.CreateRandomPassword(7);
            newUser.PasswordQuestion = Resource.ManageUsersDefaultSecurityQuestion;
            newUser.PasswordAnswer   = Resource.ManageUsersDefaultSecurityAnswer;
            newUser.Save();
            if (siteSettings.UseSecureRegistration)
            {
                newUser.SetRegistrationConfirmationGuid(Guid.NewGuid());
            }

            CProfileConfiguration profileConfig
                = CProfileConfiguration.GetConfig();

            // set default values first
            foreach (CProfilePropertyDefinition propertyDefinition in profileConfig.PropertyDefinitions)
            {
                CProfilePropertyDefinition.SavePropertyDefault(
                    newUser, propertyDefinition);
            }

            foreach (CProfilePropertyDefinition propertyDefinition in profileConfig.PropertyDefinitions)
            {
                if (propertyDefinition.RequiredForRegistration)
                {
                    CProfilePropertyDefinition.SaveProperty(
                        newUser,
                        pnlRequiredProfileProperties,
                        propertyDefinition,
                        timeOffset);
                }
            }

            // track user ip address
            UserLocation userLocation = new UserLocation(newUser.UserGuid, SiteUtils.GetIP4Address());

            userLocation.SiteGuid = siteSettings.SiteGuid;
            userLocation.Hostname = Page.Request.UserHostName;
            userLocation.Save();

            UserRegisteredEventArgs u = new UserRegisteredEventArgs(newUser);

            OnUserRegistered(u);

            CacheHelper.TouchMembershipStatisticsCacheDependencyFile();

            NewsletterHelper.ClaimExistingSubscriptions(newUser);

            DoUserLogin(newUser);
        }
Ejemplo n.º 2
0
        private void CreateUser(
            string openId,
            string email,
            string loginName,
            string name)
        {
            SiteUser newUser = new SiteUser(siteSettings);

            newUser.Email = email;

            if (loginName.Length > 50)
            {
                loginName = loginName.Substring(0, 50);
            }

            int i = 1;

            while (SiteUser.LoginExistsInDB(
                       siteSettings.SiteId, loginName))
            {
                loginName += i.ToString();
                if (loginName.Length > 50)
                {
                    loginName = loginName.Remove(40, 1);
                }
                i++;
            }
            if ((name == null) || (name.Length == 0))
            {
                name = loginName;
            }
            newUser.LoginName = loginName;
            newUser.Name      = name;
            //newUser.Password = SiteUser.CreateRandomPassword(7);
            mojoMembershipProvider mojoMembership = (mojoMembershipProvider)Membership.Provider;

            newUser.Password         = mojoMembership.EncodePassword(siteSettings, newUser, SiteUser.CreateRandomPassword(7, WebConfigSettings.PasswordGeneratorChars));
            newUser.PasswordQuestion = Resource.ManageUsersDefaultSecurityQuestion;
            newUser.PasswordAnswer   = Resource.ManageUsersDefaultSecurityAnswer;
            newUser.OpenIdUri        = openId;
            newUser.Save();
            if (siteSettings.UseSecureRegistration)
            {
                newUser.SetRegistrationConfirmationGuid(Guid.NewGuid());
            }

            mojoProfileConfiguration profileConfig
                = mojoProfileConfiguration.GetConfig();

            // set default values first
            foreach (mojoProfilePropertyDefinition propertyDefinition in profileConfig.PropertyDefinitions)
            {
                mojoProfilePropertyDefinition.SavePropertyDefault(
                    newUser, propertyDefinition);
            }

            foreach (mojoProfilePropertyDefinition propertyDefinition in profileConfig.PropertyDefinitions)
            {
                if ((propertyDefinition.RequiredForRegistration) || (propertyDefinition.ShowOnRegistration))
                {
                    mojoProfilePropertyDefinition.SaveProperty(
                        newUser,
                        pnlRequiredProfileProperties,
                        propertyDefinition,
                        timeOffset,
                        timeZone);
                }
            }

            // track user ip address
            UserLocation userLocation = new UserLocation(newUser.UserGuid, SiteUtils.GetIP4Address());

            userLocation.SiteGuid = siteSettings.SiteGuid;
            userLocation.Hostname = Page.Request.UserHostName;
            userLocation.Save();

            UserRegisteredEventArgs u = new UserRegisteredEventArgs(newUser);

            OnUserRegistered(u);

            CacheHelper.ClearMembershipStatisticsCache();

            NewsletterHelper.ClaimExistingSubscriptions(newUser);

            DoUserLogin(newUser);
        }
        void application_AuthenticateRequest(object sender, EventArgs e)
        {
            //if (debugLog) log.Debug("AuthHandlerHttpModule Application_AuthenticateRequest");

            if (sender == null)
            {
                return;
            }

            HttpApplication app = (HttpApplication)sender;

            if (app.Request == null)
            {
                return;
            }
            if (!app.Request.IsAuthenticated)
            {
                return;
            }

            if (WebUtils.IsRequestForStaticFile(app.Request.Path))
            {
                return;
            }
            if (app.Request.Path.ContainsCaseInsensitive(".ashx"))
            {
                return;
            }
            if (app.Request.Path.ContainsCaseInsensitive(".axd"))
            {
                return;
            }
            if (app.Request.Path.ContainsCaseInsensitive("setup/default.aspx"))
            {
                return;
            }


            //if (debugLog) log.Debug("IsAuthenticated == true");
            SiteSettings siteSettings;

            try
            {
                siteSettings = CacheHelper.GetCurrentSiteSettings();
            }
            catch (System.Data.Common.DbException ex)
            {
                // can happen during upgrades
                log.Error(ex);
                return;
            }
            catch (InvalidOperationException ex)
            {
                log.Error(ex);
                return;
            }
            catch (Exception ex)
            {
                // hate to trap System.Exception but SqlCeException doe snot inherit from DbException as it should
                if (DatabaseHelper.DBPlatform() != "SqlCe")
                {
                    throw;
                }
                log.Error(ex);
                return;
            }
            bool useFolderForSiteDetection = WebConfigSettings.UseFoldersInsteadOfHostnamesForMultipleSites;

            // Added by Haluk Eryuksel - 2006-01-23
            // support for Windows authentication
            if (
                (app.User.Identity.AuthenticationType == "NTLM") ||
                (app.User.Identity.AuthenticationType == "Negotiate")
                // || ( Context.User.Identity.AuthenticationType == "Windows" )
                )
            {
                //Added by Benedict Chan - 2008-08-05
                //Added Cookie here so that we don't have to check the users in every page, also to authenticate under NTLM with "useFolderForSiteDetection == true"
                string cookieName = "siteguid" + siteSettings.SiteGuid;
                if (!CookieHelper.CookieExists(cookieName))
                {
                    bool existsInDB;
                    existsInDB = SiteUser.LoginExistsInDB(siteSettings.SiteId, app.Context.User.Identity.Name);

                    if (!existsInDB)
                    {
                        SiteUser u = new SiteUser(siteSettings);
                        u.Name      = app.Context.User.Identity.Name;
                        u.LoginName = app.Context.User.Identity.Name;
                        u.Email     = GuessEmailAddress(u.Name);
                        u.Password  = SiteUser.CreateRandomPassword(7, WebConfigSettings.PasswordGeneratorChars);

                        mojoMembershipProvider m = Membership.Provider as mojoMembershipProvider;
                        if (m != null)
                        {
                            u.Password = m.EncodePassword(siteSettings, u, u.Password);
                        }

                        u.Save();
                        NewsletterHelper.ClaimExistingSubscriptions(u);

                        UserRegisteredEventArgs args = new UserRegisteredEventArgs(u);
                        OnUserRegistered(args);
                    }

                    SiteUser siteUser = new SiteUser(siteSettings, app.Context.User.Identity.Name);
                    CookieHelper.SetCookie(cookieName, siteUser.UserGuid.ToString(), true);

                    //Copied logic from SiteLogin.cs  Since we will skip them if we use NTLM
                    if (siteUser.UserId > -1 && siteSettings.AllowUserSkins && siteUser.Skin.Length > 0)
                    {
                        SiteUtils.SetSkinCookie(siteUser);
                    }

                    // track user ip address
                    try
                    {
                        UserLocation userLocation = new UserLocation(siteUser.UserGuid, SiteUtils.GetIP4Address());
                        userLocation.SiteGuid = siteSettings.SiteGuid;
                        userLocation.Hostname = app.Request.UserHostName;
                        userLocation.Save();
                        log.Info("Set UserLocation : " + app.Request.UserHostName + ":" + SiteUtils.GetIP4Address());
                    }
                    catch (Exception ex)
                    {
                        log.Error(SiteUtils.GetIP4Address(), ex);
                    }
                }

                //End-Added by Benedict Chan
            }
            // End-Added by Haluk Eryuksel


            if ((useFolderForSiteDetection) && (!WebConfigSettings.UseRelatedSiteMode))
            {
                // replace GenericPrincipal with custom one
                //string roles = string.Empty;
                if (!(app.Context.User is mojoIdentity))
                {
                    app.Context.User = new mojoPrincipal(app.Context.User);
                }
            }
        }
Ejemplo n.º 4
0
        private SiteUser CreateUser(
            string openId,
            string email,
            string loginName,
            string name,
            bool emailIsVerified)
        {
            SiteUser newUser = new SiteUser(siteSettings);

            newUser.Email = email;

            if (loginName.Length > 50)
            {
                loginName = loginName.Substring(0, 50);
            }

            int i = 1;

            while (SiteUser.LoginExistsInDB(
                       siteSettings.SiteId, loginName))
            {
                loginName += i.ToString();
                if (loginName.Length > 50)
                {
                    loginName = loginName.Remove(40, 1);
                }
                i++;
            }
            if ((name == null) || (name.Length == 0))
            {
                name = loginName;
            }
            newUser.LoginName = loginName;
            newUser.Name      = name;
            //newUser.Password = SiteUser.CreateRandomPassword(7);
            mojoMembershipProvider mojoMembership = (mojoMembershipProvider)Membership.Provider;

            newUser.Password         = mojoMembership.EncodePassword(siteSettings, newUser, SiteUser.CreateRandomPassword(7, WebConfigSettings.PasswordGeneratorChars));
            newUser.PasswordQuestion = Resource.ManageUsersDefaultSecurityQuestion;
            newUser.PasswordAnswer   = Resource.ManageUsersDefaultSecurityAnswer;
            newUser.OpenIdUri        = openId;
            newUser.Save();

            //test
            //emailIsVerified = false;

            if (siteSettings.UseSecureRegistration)
            {
                if (!emailIsVerified)
                {
                    newUser.SetRegistrationConfirmationGuid(Guid.NewGuid());
                }
            }



            mojoProfileConfiguration profileConfig
                = mojoProfileConfiguration.GetConfig();

            // set default values first
            foreach (mojoProfilePropertyDefinition propertyDefinition in profileConfig.PropertyDefinitions)
            {
                // we are using the new TimeZoneInfo list but it doesn't work under Mono
                // this makes us skip the TimeOffsetHours setting from mojoProfile.config which is not used under windows
                if (propertyDefinition.Name == mojoProfilePropertyDefinition.TimeOffsetHoursKey)
                {
                    continue;
                }
                mojoProfilePropertyDefinition.SavePropertyDefault(
                    newUser, propertyDefinition);
            }

            foreach (mojoProfilePropertyDefinition propertyDefinition in profileConfig.PropertyDefinitions)
            {
                // we are using the new TimeZoneInfo list but it doesn't work under Mono
                // this makes us skip the TimeOffsetHours setting from mojoProfile.config which is not used under windows
                if (propertyDefinition.Name == mojoProfilePropertyDefinition.TimeOffsetHoursKey)
                {
                    continue;
                }
                if ((propertyDefinition.RequiredForRegistration) || (propertyDefinition.ShowOnRegistration))
                {
                    mojoProfilePropertyDefinition.SaveProperty(
                        newUser,
                        pnlRequiredProfileProperties,
                        propertyDefinition,
                        timeOffset,
                        timeZone);
                }
            }

            // track user ip address
            UserLocation userLocation = new UserLocation(newUser.UserGuid, SiteUtils.GetIP4Address());

            userLocation.SiteGuid = siteSettings.SiteGuid;
            userLocation.Hostname = Page.Request.UserHostName;
            userLocation.Save();

            UserRegisteredEventArgs u = new UserRegisteredEventArgs(newUser);

            OnUserRegistered(u);

            CacheHelper.ClearMembershipStatisticsCache();

            // we'll map them next time they login
            //OpenIdRpxHelper rpxHelper = new OpenIdRpxHelper(rpxApiKey, rpxBaseUrl);
            //rpxHelper.Map(openId, newUser.UserGuid.ToString());

            DoSubscribe(newUser);

            NewsletterHelper.ClaimExistingSubscriptions(newUser);

            return(newUser);
        }
Ejemplo n.º 5
0
        void application_AuthenticateRequest(object sender, EventArgs e)
        {
            if (log.IsDebugEnabled)
            {
                log.Debug("AuthHandlerHttpModule Application_AuthenticateRequest");
            }

            if (sender == null)
            {
                return;
            }

            HttpApplication app = (HttpApplication)sender;

            if (
                (app.Request.Path.EndsWith(".gif", StringComparison.InvariantCultureIgnoreCase)) ||
                (app.Request.Path.EndsWith(".js", StringComparison.InvariantCultureIgnoreCase)) ||
                (app.Request.Path.EndsWith(".png", StringComparison.InvariantCultureIgnoreCase)) ||
                (app.Request.Path.EndsWith(".jpg", StringComparison.InvariantCultureIgnoreCase)) ||
                (app.Request.Path.EndsWith(".css", StringComparison.InvariantCultureIgnoreCase)) ||
                (app.Request.Path.EndsWith(".axd", StringComparison.InvariantCultureIgnoreCase)) ||
                (app.Request.Path.EndsWith("thumbnailservice.ashx", StringComparison.InvariantCultureIgnoreCase)) ||
                (app.Request.Path.Contains("csshandler.ashx")) ||
                (app.Request.Path.EndsWith("/Data/", StringComparison.InvariantCultureIgnoreCase)) ||
                (app.Request.Path.StartsWith("/Data/", StringComparison.InvariantCultureIgnoreCase)) ||
                (app.Request.Path.Contains("GCheckoutNotificationHandler.ashx"))
                )
            {
                return;
            }



            if (app.Request.IsAuthenticated)
            {
                if (log.IsDebugEnabled)
                {
                    log.Debug("IsAuthenticated == true");
                }

                SiteSettings siteSettings = CacheHelper.GetCurrentSiteSettings();
                bool         useFolderForSiteDetection = WebConfigSettings.UseFoldersInsteadOfHostnamesForMultipleSites;

                // Added by Haluk Eryuksel - 2006-01-23
                // support for Windows authentication
                if (
                    (app.User.Identity.AuthenticationType == "NTLM") ||
                    (app.User.Identity.AuthenticationType == "Negotiate")
                    // || ( Context.User.Identity.AuthenticationType == "Windows" )
                    )
                {
                    //Added by Benedict Chan - 2008-08-05
                    //Added Cookie here so that we don't have to check the users in every page, also to authenticate under NTLM with "useFolderForSiteDetection == true"
                    string cookieName = "siteguid" + siteSettings.SiteGuid;
                    if (!CookieHelper.CookieExists(cookieName))
                    {
                        bool existsInDB;
                        existsInDB = SiteUser.LoginExistsInDB(siteSettings.SiteId, app.Context.User.Identity.Name);

                        if (!existsInDB)
                        {
                            SiteUser u = new SiteUser(siteSettings);
                            u.Name      = app.Context.User.Identity.Name;
                            u.LoginName = app.Context.User.Identity.Name;
                            u.Email     = "";
                            u.Password  = SiteUser.CreateRandomPassword(7);
                            u.Save();
                            NewsletterHelper.ClaimExistingSubscriptions(u);

                            UserRegisteredEventArgs args = new UserRegisteredEventArgs(u);
                            OnUserRegistered(args);
                        }

                        SiteUser siteUser = new SiteUser(siteSettings, app.Context.User.Identity.Name);
                        CookieHelper.SetCookie(cookieName, siteUser.UserGuid.ToString(), true);

                        //Copied logic from SiteLogin.cs  Since we will skip them if we use NTLM
                        if (siteUser.UserId > -1 && siteSettings.AllowUserSkins && siteUser.Skin.Length > 0)
                        {
                            SiteUtils.SetSkinCookie(siteUser);
                        }

                        // track user ip address
                        try
                        {
                            UserLocation userLocation = new UserLocation(siteUser.UserGuid, SiteUtils.GetIP4Address());
                            userLocation.SiteGuid = siteSettings.SiteGuid;
                            userLocation.Hostname = app.Request.UserHostName;
                            userLocation.Save();
                            log.Info("Set UserLocation : " + app.Request.UserHostName + ":" + SiteUtils.GetIP4Address());
                        }
                        catch (Exception ex)
                        {
                            log.Error(SiteUtils.GetIP4Address(), ex);
                        }
                    }

                    //End-Added by Benedict Chan
                }
                // End-Added by Haluk Eryuksel


                if ((useFolderForSiteDetection) && (!WebConfigSettings.UseRelatedSiteMode))
                {
                    // replace GenericPrincipal with custom one
                    //string roles = string.Empty;
                    if (!(app.Context.User is CIdentity))
                    {
                        app.Context.User = new CPrincipal(app.Context.User);
                    }
                }
            }
        }
Ejemplo n.º 6
0
        private void DoNewUserLogic(OpenIdEventArgs e)
        {
            if (e == null)
            {
                return;
            }

            ClaimsResponse claim = e.Response.GetExtension <ClaimsResponse>();

            if (claim == null)
            {
                return;
            }

            if (IsValidForUserCreation(e, claim))
            {
                if (SiteUser.EmailExistsInDB(siteSettings.SiteId, claim.Email))
                {
                    // show message that user should login and associate
                    // their open id account on their profile page.
                    lblError.Text = Resource.OpenIDRegisterUserEmailExistsMessage;
                    return;
                }
                else
                {
                    // create user automagically since we have all
                    // the needed data
                    SiteUser newUser = new SiteUser(siteSettings);
                    newUser.Email = claim.Email;
                    newUser.Name  = claim.FullName;
                    string loginName = newUser.Name.Replace(" ", ".").ToLower();
                    if (loginName.Length > 50)
                    {
                        loginName = loginName.Substring(0, 50);
                    }

                    if (SiteUser.LoginExistsInDB(
                            siteSettings.SiteId, loginName))
                    {
                        loginName = e.ClaimedIdentifier.ToString().Replace("http://", string.Empty).Replace("https://", string.Empty).Replace("/", string.Empty);
                        if (loginName.Length > 50)
                        {
                            loginName = loginName.Substring(0, 50);
                        }

                        int i = 1;
                        while (SiteUser.LoginExistsInDB(
                                   siteSettings.SiteId, loginName))
                        {
                            loginName += i.ToString();
                            if (loginName.Length > 50)
                            {
                                loginName = loginName.Remove(40, 1);
                            }
                            i++;
                        }
                    }

                    newUser.LoginName        = loginName;
                    newUser.Password         = SiteUser.CreateRandomPassword(7, WebConfigSettings.PasswordGeneratorChars);
                    newUser.PasswordQuestion = Resource.ManageUsersDefaultSecurityQuestion;
                    newUser.PasswordAnswer   = Resource.ManageUsersDefaultSecurityAnswer;
                    newUser.OpenIdUri        = e.ClaimedIdentifier.ToString();
                    newUser.Save();
                    if (siteSettings.UseSecureRegistration)
                    {
                        newUser.SetRegistrationConfirmationGuid(Guid.NewGuid());
                    }


                    // track user ip address
                    UserLocation userLocation = new UserLocation(newUser.UserGuid, SiteUtils.GetIP4Address());
                    userLocation.SiteGuid = siteSettings.SiteGuid;
                    userLocation.Hostname = Page.Request.UserHostName;
                    userLocation.Save();

                    if (
                        (siteSettings.UseSecureRegistration) &&
                        (newUser.RegisterConfirmGuid != Guid.Empty)
                        )
                    {
                        Notification.SendRegistrationConfirmationLink(
                            SiteUtils.GetSmtpSettings(),
                            ResourceHelper.GetMessageTemplate("RegisterConfirmEmailMessage.config"),
                            siteSettings.DefaultEmailFromAddress,
                            siteSettings.DefaultFromEmailAlias,
                            newUser.Email,
                            siteSettings.SiteName,
                            WebUtils.GetSiteRoot() + "/ConfirmRegistration.aspx?ticket=" +
                            newUser.RegisterConfirmGuid.ToString());

                        lblError.Text = Resource.LoginUnconfirmedEmailMessage;
                        log.Info("Automatically created User " + newUser.Name + " on login from open id. Tried to login but email address is not confirmed.");

                        return;
                    }

                    if (siteSettings.UseEmailForLogin)
                    {
                        FormsAuthentication.SetAuthCookie(
                            newUser.Email, true);
                    }
                    else
                    {
                        FormsAuthentication.SetAuthCookie(
                            newUser.LoginName, true);
                    }

                    if (WebConfigSettings.UseFoldersInsteadOfHostnamesForMultipleSites)
                    {
                        string cookieName = "siteguid" + siteSettings.SiteGuid;
                        CookieHelper.SetCookie(cookieName, newUser.UserGuid.ToString(), true);
                    }

                    newUser.UpdateLastLoginTime();

                    string redirectUrl = GetRedirectPath();
                    CookieHelper.ExpireCookie(returnUrlCookieName);
                    WebUtils.SetupRedirect(this, redirectUrl);
                    return;
                }
            }
            else
            {
                // user not found
                // required fields not available from open id
                // redirect to register page?
                // Or show message with Link to
                // register page
                string registerLinkHref = siteRoot
                                          + "/Secure/RegisterWithOpenID.aspx";

                litNotRegisteredYetMessage.Text
                    = string.Format(
                          Resource.OpenIDMustRegisterBeforeLoginMesage,
                          registerLinkHref);
            }
        }
Ejemplo n.º 7
0
        private SiteUser CreateUser(FaceBookUser oUser)
        {
            if (string.IsNullOrEmpty(oUser.Email) || !Email.IsValidEmailAddressSyntax(oUser.Email))
            {
                oUser.Email = oUser.Id + "@facebook.com";
            }

            if (SiteUser.EmailExistsInDB(siteSettings.SiteId, oUser.Email))
            {
                var user = new SiteUser(siteSettings, oUser.Email);
                if (user != null && user.UserId > 0)
                {
                    if (string.IsNullOrEmpty(user.OpenIdUri))
                    {
                        user.OpenIdUri = oUser.Id;
                        //if (oUser.Email != user.Email)
                        //    user.ApprovedForLogin = true;
                        user.Save();
                    }

                    return(user);
                }
            }

            SiteUser newUser = new SiteUser(siteSettings);

            newUser.Email     = oUser.Email;
            newUser.LoginName = SiteUtils.SuggestLoginNameFromEmail(siteSettings.SiteId, newUser.Email);
            newUser.Name      = newUser.LoginName;
            gbMembershipProvider gbMembership = (gbMembershipProvider)Membership.Provider;

            newUser.Password = gbMembership.EncodePassword(siteSettings, newUser, SiteUser.CreateRandomPassword(7, WebConfigSettings.PasswordGeneratorChars));

            newUser.ApprovedForLogin = false;
            newUser.OpenIdUri        = oUser.Id; //"http://www.facebook.com/profile.php?id=" + oUser.Id;
            if (!string.IsNullOrEmpty(oUser.First_Name))
            {
                newUser.FirstName = oUser.First_Name;
            }
            if (!string.IsNullOrEmpty(oUser.Last_Name))
            {
                newUser.FirstName = (oUser.Last_Name + " " + newUser.FirstName).Trim();
                //newUser.LastName = oUser.Last_Name;
            }

            if (string.IsNullOrEmpty(newUser.FirstName) && !string.IsNullOrEmpty(oUser.Name))
            {
                newUser.FirstName = oUser.Name;
            }

            //if (!string.IsNullOrEmpty(oUser.Bio))
            //    newUser.AuthorBio = oUser.Bio;
            if (!string.IsNullOrEmpty(oUser.Gender))
            {
                switch (oUser.Gender.ToLower())
                {
                case "male":
                case "nam":
                    newUser.Gender = "M";
                    break;

                case "female":
                case "nữ":
                    newUser.Gender = "F";
                    break;
                }

                //newUser.Gender = oUser.Gender.ToUpper();
            }
            //if (!string.IsNullOrEmpty(oUser.Link))
            //    newUser.WebSiteUrl = oUser.Link;
            //newUser.AvatarUrl = string.Format("https://graph.facebook.com/{0}/picture?width=160&height=160", oUser.Id);

            newUser.Save();

            //// track clientNo ip address
            //UserLocation userLocation = new UserLocation(newUser.UserGuid, SiteUtils.GetIP4Address());
            //userLocation.SiteGuid = siteSettings.SiteGuid;
            //userLocation.Hostname = Page.Request.UserHostName;
            //userLocation.Save();

            UserRegisteredEventArgs u = new UserRegisteredEventArgs(newUser);

            OnUserRegistered(u);

            CacheHelper.ClearMembershipStatisticsCache();

            return(newUser);
        }
        private void CreateUser(string windowsLiveId)
        {
            SiteUser newUser = new SiteUser(siteSettings);

            newUser.WindowsLiveId = windowsLiveId;
            newUser.Name          = SecurityHelper.RemoveMarkup(txtUserName.Text);
            newUser.LoginName     = newUser.Name;
            newUser.Email         = txtEmail.Text;
            mojoMembershipProvider mojoMembership = (mojoMembershipProvider)Membership.Provider;

            newUser.Password = mojoMembership.EncodePassword(siteSettings, newUser, SiteUser.CreateRandomPassword(7, WebConfigSettings.PasswordGeneratorChars));
            //newUser.Password = SiteUser.CreateRandomPassword(7);
            newUser.PasswordQuestion = Resource.ManageUsersDefaultSecurityQuestion;
            newUser.PasswordAnswer   = Resource.ManageUsersDefaultSecurityAnswer;
            newUser.Save();
            if (siteSettings.UseSecureRegistration)
            {
                newUser.SetRegistrationConfirmationGuid(Guid.NewGuid());
            }

            mojoProfileConfiguration profileConfig
                = mojoProfileConfiguration.GetConfig();

            // set default values first
            foreach (mojoProfilePropertyDefinition propertyDefinition in profileConfig.PropertyDefinitions)
            {
#if !MONO
                // we are using the new TimeZoneInfo list but it doesn't work under Mono
                // this makes us skip the TimeOffsetHours setting from mojoProfile.config which is not used under windows
                if (propertyDefinition.Name == mojoProfilePropertyDefinition.TimeOffsetHoursKey)
                {
                    continue;
                }
#endif
                mojoProfilePropertyDefinition.SavePropertyDefault(
                    newUser, propertyDefinition);
            }

            foreach (mojoProfilePropertyDefinition propertyDefinition in profileConfig.PropertyDefinitions)
            {
#if !MONO
                // we are using the new TimeZoneInfo list but it doesn't work under Mono
                // this makes us skip the TimeOffsetHours setting from mojoProfile.config which is not used under windows
                if (propertyDefinition.Name == mojoProfilePropertyDefinition.TimeOffsetHoursKey)
                {
                    continue;
                }
#endif
                if ((propertyDefinition.RequiredForRegistration) || (propertyDefinition.ShowOnRegistration))
                {
                    mojoProfilePropertyDefinition.SaveProperty(
                        newUser,
                        pnlRequiredProfileProperties,
                        propertyDefinition,
                        timeOffset,
                        timeZone);
                }
            }

            // track user ip address
            UserLocation userLocation = new UserLocation(newUser.UserGuid, SiteUtils.GetIP4Address());
            userLocation.SiteGuid = siteSettings.SiteGuid;
            userLocation.Hostname = Page.Request.UserHostName;
            userLocation.Save();

            UserRegisteredEventArgs u = new UserRegisteredEventArgs(newUser);
            OnUserRegistered(u);

            CacheHelper.ClearMembershipStatisticsCache();

            NewsletterHelper.ClaimExistingSubscriptions(newUser);

            DoUserLogin(newUser);
        }
Ejemplo n.º 9
0
        void Register_Click(object sender, EventArgs e)
        {
            if (!Page.IsValid)
            {
                return;
            }

            var email    = Email.Text;
            var password = Password.Text;
            var userName = SiteUtils.SuggestLoginNameFromEmail(siteSettings.SiteId, email);

            SiteUser existingUser = null;

            if (SiteUser.EmailExistsInDB(siteSettings.SiteId, email))
            {
                if (WebConfigSettings.AllowNewRegistrationToActivateDeletedAccountWithSameEmail)
                {
                    existingUser = SiteUser.GetByEmail(siteSettings, email);
                    if ((existingUser != null) && (!existingUser.IsDeleted))
                    {
                        existingUser = null;
                    }
                }

                if (existingUser == null)
                {
                    RegisterResults.Text = ResourceHelper.GetResourceString("Resource", "DuplicateEmailMessage");
                    return;
                }
            }

            if (SiteUser.LoginExistsInDB(siteSettings.SiteId, userName))
            {
                RegisterResults.Text = ResourceHelper.GetResourceString("Resource", "DuplicateUserNameMessage");
                return;
            }

            if (password.Length < siteSettings.MinRequiredPasswordLength)
            {
                RegisterResults.Text = ResourceHelper.GetResourceString("ProductResources", "CheckoutRegisterInvalidPassword");
                return;
            }

            int nonAlphaNumericCharactersUsedCount = 0;

            for (int i = 0; i < password.Length; i++)
            {
                if (!char.IsLetterOrDigit(password, i))
                {
                    nonAlphaNumericCharactersUsedCount++;
                }
            }

            if (nonAlphaNumericCharactersUsedCount < siteSettings.MinRequiredNonAlphanumericCharacters)
            {
                RegisterResults.Text = ResourceHelper.GetResourceString("ProductResources", "CheckoutRegisterInvalidPassword");
                return;
            }

            if (siteSettings.PasswordStrengthRegularExpression.Length > 0)
            {
                if (!Regex.IsMatch(password, siteSettings.PasswordStrengthRegularExpression))
                {
                    RegisterResults.Text = ResourceHelper.GetResourceString("ProductResources", "CheckoutRegisterInvalidPassword");
                    return;
                }
            }

            SiteUser siteUser;

            if (existingUser != null)
            {
                siteUser = existingUser;
            }
            else
            {
                siteUser = new SiteUser(siteSettings);
            }

            siteUser.Name      = userName;
            siteUser.LoginName = userName;
            siteUser.Email     = email;
            siteUser.FirstName = FullName.Text.Trim();

            var PasswordFormat = (MembershipPasswordFormat)siteSettings.PasswordFormat;

            if (PasswordFormat != MembershipPasswordFormat.Clear)
            {
                siteUser.PasswordSalt = SiteUser.CreateRandomPassword(128, WebConfigSettings.PasswordGeneratorChars);
                password = (new gbMembershipProvider()).EncodePassword(siteUser.PasswordSalt + password, PasswordFormat);
            }

            siteUser.Password         = password;
            siteUser.ApprovedForLogin = !siteSettings.RequireApprovalBeforeLogin;
            bool created = siteUser.Save();

            if (existingUser != null)
            {
                SiteUser.FlagAsNotDeleted(siteUser.UserId);
            }

            if (created)
            {
                if (siteSettings.UseEmailForLogin)
                {
                    FormsAuthentication.SetAuthCookie(siteUser.Email, false);
                }
                SiteUtils.CreateAndStoreSessionToken(siteUser);
                siteUser.UpdateLastLoginTime();
            }

            if (config.CheckoutNextZoneId > 0)
            {
                WebUtils.SetupRedirect(this, CartHelper.GetZoneUrl(config.CheckoutNextZoneId));
            }
        }
        private SiteUser CreateUser(
            string openId,
            string email,
            string loginName,
            string name,
            bool emailIsVerified)
        {
            SiteUser newUser = new SiteUser(siteSettings);

            newUser.Email = email;

            if (loginName.Length > 50)
            {
                loginName = loginName.Substring(0, 50);
            }

            int i = 1;

            while (SiteUser.LoginExistsInDB(
                       siteSettings.SiteId, loginName))
            {
                loginName += i.ToString();
                if (loginName.Length > 50)
                {
                    loginName = loginName.Remove(40, 1);
                }
                i++;
            }
            if ((name == null) || (name.Length == 0))
            {
                name = loginName;
            }
            newUser.LoginName = loginName;
            newUser.Name      = name;
            //newUser.Password = SiteUser.CreateRandomPassword(7);
            CMembershipProvider CMembership = (CMembershipProvider)Membership.Provider;

            newUser.Password         = CMembership.EncodePassword(SiteUser.CreateRandomPassword(7), siteSettings);
            newUser.PasswordQuestion = Resource.ManageUsersDefaultSecurityQuestion;
            newUser.PasswordAnswer   = Resource.ManageUsersDefaultSecurityAnswer;
            newUser.OpenIdUri        = openId;
            newUser.Save();
            if (siteSettings.UseSecureRegistration)
            {
                if (!emailIsVerified)
                {
                    newUser.SetRegistrationConfirmationGuid(Guid.NewGuid());
                }
            }

            CProfileConfiguration profileConfig
                = CProfileConfiguration.GetConfig();

            // set default values first
            foreach (CProfilePropertyDefinition propertyDefinition in profileConfig.PropertyDefinitions)
            {
                CProfilePropertyDefinition.SavePropertyDefault(
                    newUser, propertyDefinition);
            }

            foreach (CProfilePropertyDefinition propertyDefinition in profileConfig.PropertyDefinitions)
            {
                if (propertyDefinition.RequiredForRegistration)
                {
                    CProfilePropertyDefinition.SaveProperty(
                        newUser,
                        pnlRequiredProfileProperties,
                        propertyDefinition,
                        timeOffset);
                }
            }

            // track user ip address
            UserLocation userLocation = new UserLocation(newUser.UserGuid, SiteUtils.GetIP4Address());

            userLocation.SiteGuid = siteSettings.SiteGuid;
            userLocation.Hostname = Page.Request.UserHostName;
            userLocation.Save();

            UserRegisteredEventArgs u = new UserRegisteredEventArgs(newUser);

            OnUserRegistered(u);

            CacheHelper.TouchMembershipStatisticsCacheDependencyFile();

            // we'll map them next time they login
            //OpenIdRpxHelper rpxHelper = new OpenIdRpxHelper(rpxApiKey, rpxBaseUrl);
            //rpxHelper.Map(openId, newUser.UserGuid.ToString());

            NewsletterHelper.ClaimExistingSubscriptions(newUser);

            return(newUser);
        }