コード例 #1
0
 private void OnUserRegistered(UserRegisteredEventArgs e)
 {
     foreach (UserRegisteredHandlerProvider handler in UserRegisteredHandlerProviderManager.Providers)
     {
         handler.UserRegisteredHandler(null, e);
     }
 }
コード例 #2
0
 protected void OnUserRegistered(UserRegisteredEventArgs e)
 {
     if (UserRegistered != null)
     {
         UserRegistered(this, e);
     }
 }
コード例 #3
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);
        }
コード例 #4
0
		public User CreateNewUser(string username, string password, string email)
		{
			var author = new User {UserName = username, Password = password, Email = email};
			_userRepository.SaveUser(author);
			var userRegistered = new UserRegisteredEventArgs(this, author);
			UserRegistered.Raise(userRegistered);
			return author;
		}
コード例 #5
0
        public override void UserRegisteredHandler(object sender, UserRegisteredEventArgs e)
        {
            if (e == null)
            {
                return;
            }
            if (e.SiteUser == null)
            {
                return;
            }

            SiteSettings siteSettings = CacheHelper.GetCurrentSiteSettings();

            log.Debug("NotifyUserRegisteredHandler called for new user " + e.SiteUser.Email);

            if (HttpContext.Current == null)
            {
                return;
            }

            if (siteSettings.UseSecureRegistration)
            {
                return;
            }

            EmailTemplate template = EmailTemplate.Get(siteSettings.SiteId, "RegisterEmailNotification");

            if (template == null || template.Guid == Guid.Empty)
            {
                return;
            }
            string fromEmailAlias = (template.FromName.Length > 0 ? template.FromName : siteSettings.DefaultFromEmailAlias);

            SmtpSettings smtpSettings = SiteUtils.GetSmtpSettings();

            string toEmail = e.SiteUser.Email;

            if (template.ToAddresses.Length > 0)
            {
                toEmail += ";" + template.ToAddresses;
            }

            EmailMessageTask messageTask = new EmailMessageTask(smtpSettings);

            messageTask.SiteGuid       = siteSettings.SiteGuid;
            messageTask.EmailFrom      = siteSettings.DefaultEmailFromAddress;
            messageTask.EmailFromAlias = (template.FromName.Length > 0 ? template.FromName : siteSettings.DefaultFromEmailAlias);
            messageTask.EmailReplyTo   = template.ReplyToAddress;
            messageTask.EmailTo        = toEmail;
            messageTask.EmailCc        = template.CcAddresses;
            messageTask.EmailBcc       = template.BccAddresses;
            messageTask.UseHtml        = true;
            messageTask.Subject        = template.Subject.Replace("{Email}", e.SiteUser.Email).Replace("{FirstName}", e.SiteUser.FirstName).Replace("{LastName}", e.SiteUser.LastName);
            messageTask.HtmlBody       = template.HtmlBody.Replace("{SiteName}", siteSettings.SiteName).Replace("{Email}", e.SiteUser.Email).Replace("{FirstName}", e.SiteUser.FirstName).Replace("{LastName}", e.SiteUser.LastName).Replace("{Username}", e.SiteUser.Name).Replace("{Password}", e.SiteUser.Password);
            messageTask.QueueTask();

            WebTaskManager.StartOrResumeTasks();
        }
コード例 #6
0
        public override void UserRegisteredHandler(object sender, UserRegisteredEventArgs e)
        {
            //if (sender == null) return;
            if (e == null) return;
            if (e.SiteUser == null) return;

            // do nothing
            log.Debug("DoNothingUserRegisteredHandler called for new user " + e.SiteUser.Email);
        }
コード例 #7
0
        //private void HookupRegistrationEventHandlers()
        //{
        //    // this is a hook so that custom code can be fired when pages are created
        //    // implement a PageCreatedEventHandlerPovider and put a config file for it in
        //    // /Setup/ProviderConfig/pagecreatedeventhandlers
        //    try
        //    {
        //        foreach (UserRegisteredHandlerProvider handler in UserRegisteredHandlerProviderManager.Providers)
        //        {
        //            this.UserRegistered += handler.UserRegisteredHandler;
        //        }
        //    }
        //    catch (TypeInitializationException ex)
        //    {
        //        log.Error(ex);
        //    }

        //}

        //public event UserRegistreredEventHandler UserRegistered;

        protected void OnUserRegistered(UserRegisteredEventArgs e)
        {
            foreach (UserRegisteredHandlerProvider handler in UserRegisteredHandlerProviderManager.Providers)
            {
                handler.UserRegisteredHandler(null, e);
            }

            //if (UserRegistered != null)
            //{
            //    UserRegistered(this, e);
            //}
        }
コード例 #8
0
        public override void UserRegisteredHandler(object sender, UserRegisteredEventArgs e)
        {
            //if (sender == null) return;
            if (e == null)
            {
                return;
            }
            if (e.SiteUser == null)
            {
                return;
            }

            // do nothing
            log.Debug("DoNothingUserRegisteredHandler called for new user " + e.SiteUser.Email);
        }
コード例 #9
0
        private void CreateUser()
        {
            if (SiteUser.EmailExistsInDB(siteSettings.SiteId, txtEmail.Text))
            {
                lblErrorMessage.Text = Resource.DuplicateEmailMessage;
                return;
            }

            if (SiteUser.LoginExistsInDB(siteSettings.SiteId, txtLoginName.Text))
            {
                lblErrorMessage.Text = Resource.DuplicateUserNameMessage;
                return;
            }

            SiteUser user = new SiteUser(siteSettings);

            user.Name      = txtName.Text;
            user.LoginName = txtLoginName.Text;
            user.Email     = txtEmail.Text;

            CMembershipProvider CMembership = (CMembershipProvider)Membership.Provider;

            user.Password = CMembership.EncodePassword(txtPassword.Text, siteSettings);

            if (user.Save())
            {
                user.PasswordQuestion = this.txtPasswordQuestion.Text;
                user.PasswordAnswer   = this.txtPasswordAnswer.Text;
                user.Save();

                CProfileConfiguration profileConfig = CProfileConfiguration.GetConfig();
                // set default values
                foreach (CProfilePropertyDefinition propertyDefinition in profileConfig.PropertyDefinitions)
                {
                    CProfilePropertyDefinition.SavePropertyDefault(user, propertyDefinition);
                }

                CacheHelper.TouchMembershipStatisticsCacheDependencyFile();

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

                WebUtils.SetupRedirect(this, SiteRoot
                                       + "/Admin/ManageUsers.aspx?userId=" + user.UserId.ToString()
                                       + "&username="******"&pageid=" + pageID);
                return;
            }
        }
コード例 #10
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);
        }
コード例 #11
0
        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);
                }
            }
        }
コード例 #12
0
 private void OnUserRegistered(UserRegisteredEventArgs e)
 {
     foreach (UserRegisteredHandlerProvider handler in UserRegisteredHandlerProviderManager.Providers)
     {
         handler.UserRegisteredHandler(null, e);
     }
 }
コード例 #13
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);
        }
コード例 #14
0
        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);
        }
コード例 #15
0
        public override void UserRegisteredHandler(object sender, UserRegisteredEventArgs e)
        {
            //if (sender == null) return;
            if (e == null)
            {
                return;
            }
            if (e.SiteUser == null)
            {
                return;
            }

            if (!WebConfigSettings.NotifyAdminsOnNewUserRegistration)
            {
                return;
            }

            log.Debug("NotifyAdminUserRegisteredHandler called for new user " + e.SiteUser.Email);

            if (HttpContext.Current == null)
            {
                return;
            }

            //lookup admin users and send notification email with link to manage user

            SiteSettings siteSettings   = CacheHelper.GetCurrentSiteSettings();
            CultureInfo  defaultCulture = ResourceHelper.GetDefaultCulture();

            //Role adminRole = Role.GetRoleByName(siteSettings.SiteId, "Admins");

            //if (adminRole == null)
            //{
            //    // TODO: log it?
            //    return;
            //}

            //DataTable admins = SiteUser.GetRoleMembers(adminRole.RoleId);

            string subjectTemplate
                = ResourceHelper.GetMessageTemplate(defaultCulture,
                                                    "NotifyAdminofNewUserRegistationSubject.config");

            string textBodyTemplate = ResourceHelper.GetMessageTemplate(defaultCulture,
                                                                        "NotifyAdminofNewUserRegistationMessage.config");

            string       siteRoot     = SiteUtils.GetNavigationSiteRoot();
            SmtpSettings smtpSettings = SiteUtils.GetSmtpSettings();

            List <string> adminEmails = SiteUser.GetEmailAddresses(siteSettings.SiteId, "Admins;");

            //foreach (DataRow row in admins.Rows)
            foreach (string email in adminEmails)
            {
                if (WebConfigSettings.EmailAddressesToExcludeFromAdminNotifications.IndexOf(email, StringComparison.InvariantCultureIgnoreCase) > -1)
                {
                    continue;
                }

                EmailMessageTask messageTask = new EmailMessageTask(smtpSettings);

                messageTask.EmailFrom = siteSettings.DefaultEmailFromAddress;
                //messageTask.EmailTo = row["Email"].ToString();
                messageTask.EmailTo = email;

                messageTask.Subject = string.Format(
                    defaultCulture,
                    subjectTemplate,
                    e.SiteUser.Email,
                    siteRoot
                    );


                string manageUserLink = siteRoot + "/Admin/ManageUsers.aspx?userid="
                                        + e.SiteUser.UserId.ToString(CultureInfo.InvariantCulture);

                messageTask.TextBody = string.Format(
                    defaultCulture,
                    textBodyTemplate,
                    siteSettings.SiteName,
                    siteRoot,
                    manageUserLink
                    );

                messageTask.SiteGuid = siteSettings.SiteGuid;
                messageTask.QueueTask();
            }

            WebTaskManager.StartOrResumeTasks();
        }
コード例 #16
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);
            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);
        }
コード例 #17
0
        void RegisterUser_CreatedUser(object sender, EventArgs e)
        {
            TextBox txtEmail    = (TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("Email");
            TextBox txtUserName = (TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("UserName");

            if (txtEmail == null)
            {
                return;
            }
            if (txtUserName == null)
            {
                return;
            }

            SiteUser siteUser;

            if (siteSettings.UseEmailForLogin)
            {
                siteUser = new SiteUser(siteSettings, txtEmail.Text);
            }
            else
            {
                siteUser = new SiteUser(siteSettings, txtUserName.Text);
            }

            if (siteUser.UserId == -1)
            {
                return;
            }

            if (pnlProfile != null)
            {
                CProfileConfiguration profileConfig = CProfileConfiguration.GetConfig();

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

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


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

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

            CacheHelper.TouchMembershipStatisticsCacheDependencyFile();

            if (!siteSettings.UseSecureRegistration)
            {
                if (siteSettings.UseEmailForLogin)
                {
                    FormsAuthentication.SetAuthCookie(
                        siteUser.Email, false);
                }
                else
                {
                    FormsAuthentication.SetAuthCookie(
                        siteUser.LoginName, false);
                }

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

                siteUser.UpdateLastLoginTime();
            }



            UserRegisteredEventArgs u = new UserRegisteredEventArgs(siteUser);

            OnUserRegistered(u);
        }
コード例 #18
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);
                    }
                }
            }
        }
コード例 #19
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);
        }
コード例 #20
0
 public abstract void UserRegisteredHandler(
     object sender,
     UserRegisteredEventArgs e);
コード例 #21
0
        public override void UserRegisteredHandler(object sender, UserRegisteredEventArgs e)
        {
            if (e == null)
            {
                return;
            }
            if (e.SiteUser == null)
            {
                return;
            }

            SiteSettings siteSettings = CacheHelper.GetCurrentSiteSettings();

            if (
                (!siteSettings.RequireApprovalBeforeLogin) &&
                (siteSettings.EmailAdressesForUserApprovalNotification.Length == 0)
                )
            {
                return;
            }

            log.Debug("NotifyAdminUserRegisteredHandler called for new user " + e.SiteUser.Email);

            if (HttpContext.Current == null)
            {
                return;
            }

            CultureInfo defaultCulture = SiteUtils.GetDefaultUICulture();

            string subjectTemplate
                = ResourceHelper.GetMessageTemplate(defaultCulture,
                                                    "NotifyAdminofNewUserRegistationSubject.config");

            string textBodyTemplate = ResourceHelper.GetMessageTemplate(defaultCulture,
                                                                        "NotifyAdminofNewUserRegistationMessage.config");

            string       siteRoot     = SiteUtils.GetNavigationSiteRoot();
            SmtpSettings smtpSettings = SiteUtils.GetSmtpSettings();

            //lookup admin users and send notification email with link to manage user
            List <string> adminEmails;

            if (siteSettings.EmailAdressesForUserApprovalNotification.Length > 0)
            {
                adminEmails = siteSettings.EmailAdressesForUserApprovalNotification.SplitOnChar(',');
            }
            else
            {
                adminEmails = SiteUser.GetEmailAddresses(siteSettings.SiteId, "Admins;");
            }

            //foreach (DataRow row in admins.Rows)
            foreach (string email in adminEmails)
            {
                if (WebConfigSettings.EmailAddressesToExcludeFromAdminNotifications.IndexOf(email, StringComparison.InvariantCultureIgnoreCase) > -1)
                {
                    continue;
                }

                //EmailMessageTask messageTask = new EmailMessageTask(smtpSettings);
                //messageTask.EmailFrom = siteSettings.DefaultEmailFromAddress;
                //messageTask.EmailFromAlias = siteSettings.DefaultFromEmailAlias;
                //messageTask.EmailTo = email;
                //messageTask.Subject = string.Format(defaultCulture, subjectTemplate, e.SiteUser.Email, siteRoot);

                string manageUserLink = siteRoot + "/Admin/ManageUsers.aspx?userid="
                                        + e.SiteUser.UserId.ToInvariantString();

                //messageTask.TextBody = string.Format(defaultCulture, textBodyTemplate, siteSettings.SiteName, siteRoot, manageUserLink);
                //messageTask.SiteGuid = siteSettings.SiteGuid;
                //messageTask.QueueTask();

                Email.Send(
                    smtpSettings,
                    siteSettings.DefaultEmailFromAddress,
                    siteSettings.DefaultFromEmailAlias,
                    string.Empty,
                    email,
                    string.Empty,
                    string.Empty,
                    string.Format(defaultCulture, subjectTemplate, e.SiteUser.Email, siteRoot),
                    string.Format(defaultCulture, textBodyTemplate, siteSettings.SiteName, siteRoot, manageUserLink),
                    false,
                    Email.PriorityNormal);
            }

            //WebTaskManager.StartOrResumeTasks();
        }
コード例 #22
0
 public abstract void UserRegisteredHandler(
     object sender,
     UserRegisteredEventArgs e);