Esempio n. 1
0
        private void PopulateLabels()
        {
            this.RegisterUser.ContinueButtonStyle.Font.Bold = true;
            this.RegisterUser.CreateUserButtonStyle.Font.Bold = true;

            Title = SiteUtils.FormatPageTitle(siteSettings, Resource.RegisterLink);

            litAlreadyAuthenticated.Text = Resource.AlreadyRegisteredMessage;

            MetaDescription = string.Format(CultureInfo.InvariantCulture,
                Resource.MetaDescriptionRegistrationPageFormat, siteSettings.SiteName);

            mojoRegisterButton StartNextButton = (mojoRegisterButton)CreateUserWizardStep1.ContentTemplateContainer.FindControl("StartNextButton");
            StartNextButton.Text = Resource.RegisterButton;

            RequiredFieldValidator userNameRequired
                = (RequiredFieldValidator)CreateUserWizardStep1.ContentTemplateContainer.FindControl("UserNameRequired");

            userNameRequired.ErrorMessage = Resource.RegisterLoginNameRequiredMessage;

            if (WebConfigSettings.UserNameValidationExpression.Length > 0)
            {
                RegularExpressionValidator regexUserName
                    = (RegularExpressionValidator)CreateUserWizardStep1.ContentTemplateContainer.FindControl("regexUserName");

                if (regexUserName != null)
                {
                    regexUserName.ValidationExpression = WebConfigSettings.UserNameValidationExpression;
                    regexUserName.ErrorMessage = WebConfigSettings.UserNameValidationWarning;
                    regexUserName.Enabled = true;

                }

            }

            CustomValidator failSafeUserNameValidator
                = (CustomValidator)CreateUserWizardStep1.ContentTemplateContainer.FindControl("FailSafeUserNameValidator");

            failSafeUserNameValidator.ErrorMessage = Resource.UserNameHasInvalidCharsWarning;
            failSafeUserNameValidator.ServerValidate += new ServerValidateEventHandler(failSafeUserNameValidator_ServerValidate);

            RequiredFieldValidator emailRequired
                = (RequiredFieldValidator)CreateUserWizardStep1.ContentTemplateContainer.FindControl("EmailRequired");

            emailRequired.ErrorMessage = Resource.RegisterEmailRequiredMessage;

            RegularExpressionValidator emailRegex
                = (RegularExpressionValidator)CreateUserWizardStep1.ContentTemplateContainer.FindControl("EmailRegex");

            emailRegex.ErrorMessage = Resource.RegisterEmailRegexMessage;

            if (WebConfigSettings.CustomEmailRegexWarning.Length > 0)
            {
                emailRegex.ErrorMessage = WebConfigSettings.CustomEmailRegexWarning;
            }

            CustomValidator passwordRulesValidator
                = (CustomValidator)CreateUserWizardStep1.ContentTemplateContainer.FindControl("PasswordRulesValidator");

            // hookup event to handle validation
            passwordRulesValidator.ServerValidate += new ServerValidateEventHandler(PasswordRulesValidator_ServerValidate);

            RequiredFieldValidator passwordRequired
                = (RequiredFieldValidator)CreateUserWizardStep1.ContentTemplateContainer.FindControl("PasswordRequired");

            passwordRequired.ErrorMessage = Resource.RegisterPasswordRequiredMessage;

            RegularExpressionValidator passwordRegex
                = (RegularExpressionValidator)CreateUserWizardStep1.ContentTemplateContainer.FindControl("PasswordRegex");

            passwordRegex.ErrorMessage = Resource.RegisterPasswordRegexWarning;

            RequiredFieldValidator confirmPasswordRequired
                = (RequiredFieldValidator)CreateUserWizardStep1.ContentTemplateContainer.FindControl("ConfirmPasswordRequired");

            confirmPasswordRequired.ErrorMessage = Resource.RegisterConfirmPasswordRequiredMessage;

            CompareValidator passwordCompare
                = (CompareValidator)CreateUserWizardStep1.ContentTemplateContainer.FindControl("PasswordCompare");

            passwordCompare.ErrorMessage = Resource.RegisterComparePasswordWarning;

            RequiredFieldValidator questionRequired
                = (RequiredFieldValidator)CreateUserWizardStep1.ContentTemplateContainer.FindControl("QuestionRequired");

            questionRequired.ErrorMessage = Resource.RegisterSecurityQuestionRequiredMessage;

            RequiredFieldValidator answerRequired
                = (RequiredFieldValidator)CreateUserWizardStep1.ContentTemplateContainer.FindControl("AnswerRequired");

            answerRequired.ErrorMessage = Resource.RegisterSecurityAnswerRequiredMessage;

            this.RegisterUser.RequireEmail = true;

            this.RegisterUser.CreateUserButtonText = Resource.RegisterButton;
            RegisterUser.CreateUserButtonStyle.CssClass += " createuserbutton";

            this.RegisterUser.CancelButtonText = Resource.RegisterCancelButton;

            if (WebConfigSettings.UseShortcutKeys)
            {
                this.RegisterUser.AccessKey = AccessKeys.RegisterAccessKey;
                this.RegisterUser.CreateUserButtonText +=
                    SiteUtils.GetButtonAccessKeyPostfix(this.RegisterUser.AccessKey);
                this.RegisterUser.ContinueButtonText +=
                    SiteUtils.GetButtonAccessKeyPostfix(this.RegisterUser.AccessKey);
            }

            this.RegisterUser.InvalidQuestionErrorMessage = Resource.RegisterInvalidQuestionErrorMessage;
            this.RegisterUser.InvalidAnswerErrorMessage = Resource.RegisterInvalidAnswerErrorMessage;
            this.RegisterUser.InvalidEmailErrorMessage = Resource.RegisterEmailRegexMessage;

            this.RegisterUser.StartNextButtonText = Resource.RegisterButton;

            this.RegisterUser.DuplicateEmailErrorMessage
                = Resource.RegisterDuplicateEmailMessage;

            this.RegisterUser.DuplicateUserNameErrorMessage
                = Resource.RegisterDuplicateUserNameMessage;

            if (Membership.Provider.PasswordStrengthRegularExpression.Length == 0)
            {
                passwordRegex.Visible = false;
            }

            if (!Membership.Provider.RequiresQuestionAndAnswer)
            {

                HtmlContainerControl divQuestion
                = (HtmlContainerControl)CreateUserWizardStep1.ContentTemplateContainer.FindControl("divQuestion");

                divQuestion.Visible = false;
                questionRequired.Visible = false;

                HtmlContainerControl divAnswer
                = (HtmlContainerControl)CreateUserWizardStep1.ContentTemplateContainer.FindControl("divAnswer");

                divAnswer.Visible = false;
                answerRequired.Visible = false;

            }

            litOr.Text = Resource.LiteralOr;

            Button continueButton =
                (Button)CompleteWizardStep1.ContentTemplateContainer.FindControl("ContinueButton");

            continueButton.Text  = Resource.RegisterContinueButton;

            Literal completeMessage =
                (Literal)CompleteWizardStep1.ContentTemplateContainer.FindControl("CompleteMessage");

            completeMessage.Text = "";
            if (siteSettings.UseSecureRegistration)
            {
                this.RegisterUser.LoginCreatedUser = false;
                completeMessage.Text = Resource.RegistrationRequiresEmailConfirmationMessage;
            }
            else if (siteSettings.RequireApprovalBeforeLogin)
            {
                this.RegisterUser.LoginCreatedUser = false;
                completeMessage.Text = Resource.RegistrationRequiresApprovalMessage;
            }
            else
            {
                this.RegisterUser.LoginCreatedUser = true;
                completeMessage.Text = Resource.RegisterCompleteMessage;

            }

            HtmlContainerControl divAgreement
                = (HtmlContainerControl)CreateUserWizardStep1.ContentTemplateContainer.FindControl("divAgreement");

            HtmlContainerControl divPreamble
                = (HtmlContainerControl)CreateUserWizardStep1.ContentTemplateContainer.FindControl("divPreamble");

            CustomValidator MustAgree
                = (CustomValidator)CreateUserWizardStep1.ContentTemplateContainer.FindControl("MustAgree");

            if (divPreamble != null)
            {
                string preamble = siteSettings.RegistrationPreamble;
                if (preamble.Length == 0)
                {
                    preamble = ResourceHelper.GetMessageTemplate("RegisterPreamble.config");
                }
                if (preamble.Length > 0)
                {
                    Literal pre = new Literal();
                    pre.Text = preamble;
                    divPreamble.Controls.Add(pre);
                }
            }

            string termsOfUse = siteSettings.RegistrationAgreement;
            if (termsOfUse.Length == 0)
            {
                termsOfUse = ResourceHelper.GetMessageTemplate("RegisterLicense.config");
            }
            if (termsOfUse.Length > 0)
            {
                if (MustAgree != null)
                {
                    MustAgree.ServerValidate += new ServerValidateEventHandler(MustAgree_ServerValidate);
                    MustAgree.ClientValidationFunction = "CheckBoxRequired_ClientValidate";
                    MustAgree.ErrorMessage = Resource.TermsOfUseWarning;
                    MustAgree.Enabled = true;
                }

                if (chkAgree != null)
                {
                    chkAgree.Text = Resource.TermsOfUseAgree;
                    includeAgreeValidator = true;
                }

                Literal agreement = new Literal();
                agreement.Text = termsOfUse;
                divAgreement.Controls.Add(agreement);
            }
            else
            {
                if (MustAgree != null) { MustAgree.Enabled = false; }
                if (chkAgree != null) { chkAgree.Visible = false; }

            }

            lnkOpenIDRegistration.Text = Resource.OpenIDRegistrationLink;
            lnkOpenIDRegistration.ToolTip = Resource.OpenIDRegistrationLink;

            lnkWindowsLiveID.Text = Resource.WindowsLiveIDRegistrationLink;
            lnkWindowsLiveID.ToolTip = Resource.WindowsLiveIDRegistrationLink;

            litThirdPartyAuthHeading.Text = Resource.ThirdPartyRegistrationHeading;

            if ((siteSettings.UseEmailForLogin) && (WebConfigSettings.AutoGenerateAndHideUserNamesWhenUsingEmailForLogin))
            {
                Panel userNamePanel
                = (Panel)CreateUserWizardStep1.ContentTemplateContainer.FindControl("pnlUserName");

                TextBox txtUserName = (TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("UserName");

                if (userNamePanel != null) { userNamePanel.Attributes.Add("style", "display:none;"); }
                userNameRequired.Enabled = false;
                userNameRequired.Visible = false;
                if (txtUserName != null) { txtUserName.Text = "nothing"; }
            }

            if (
                (WebConfigSettings.EnableAjaxControlPasswordStrength) // false as of 2014-12-15 because enabling it causes viewstate mac error
                && (siteSettings.ShowPasswordStrengthOnRegistration))
            {
                PasswordStrength passwordStrengthChecker = (PasswordStrength)CreateUserWizardStep1.ContentTemplateContainer.FindControl("passwordStrengthChecker");
                if (passwordStrengthChecker != null)
                {
                    passwordStrengthChecker.Enabled = true;
                    passwordStrengthChecker.RequiresUpperAndLowerCaseCharacters = true;
                    passwordStrengthChecker.MinimumLowerCaseCharacters = WebConfigSettings.PasswordStrengthMinimumLowerCaseCharacters;
                    passwordStrengthChecker.MinimumUpperCaseCharacters = WebConfigSettings.PasswordStrengthMinimumUpperCaseCharacters;
                    passwordStrengthChecker.MinimumSymbolCharacters = siteSettings.MinRequiredNonAlphanumericCharacters;
                    passwordStrengthChecker.PreferredPasswordLength = siteSettings.MinRequiredPasswordLength;

                    passwordStrengthChecker.PrefixText = Resource.PasswordStrengthPrefix;
                    passwordStrengthChecker.TextStrengthDescriptions = Resource.PasswordStrengthDescriptions;
                    passwordStrengthChecker.CalculationWeightings = WebConfigSettings.PasswordStrengthCalculationWeightings;

                    try
                    {
                        passwordStrengthChecker.StrengthIndicatorType = (StrengthIndicatorTypes)Enum.Parse(typeof(StrengthIndicatorTypes), WebConfigSettings.PasswordStrengthIndicatorType, true);
                    }
                    catch (ArgumentException)
                    {
                        passwordStrengthChecker.StrengthIndicatorType = StrengthIndicatorTypes.Text;
                    }
                    catch (OverflowException)
                    {
                        passwordStrengthChecker.StrengthIndicatorType = StrengthIndicatorTypes.Text;
                    }

                    try
                    {
                        passwordStrengthChecker.DisplayPosition = (DisplayPosition)Enum.Parse(typeof(DisplayPosition), WebConfigSettings.PasswordStrengthDisplayPosition, true);
                    }
                    catch (ArgumentException)
                    {
                        passwordStrengthChecker.DisplayPosition = DisplayPosition.RightSide;
                    }
                    catch (OverflowException)
                    {
                        passwordStrengthChecker.DisplayPosition = DisplayPosition.RightSide;
                    }
                }

            }

            if (siteSettings.RequireEnterEmailTwiceOnRegistration)
            {
                Panel divConfirmEmail = (Panel)CreateUserWizardStep1.ContentTemplateContainer.FindControl("divConfirmEmail");
                CompareValidator EmailCompare = (CompareValidator)CreateUserWizardStep1.ContentTemplateContainer.FindControl("EmailCompare");
                RequiredFieldValidator ConfirmEmailRequired = (RequiredFieldValidator)CreateUserWizardStep1.ContentTemplateContainer.FindControl("ConfirmEmailRequired");

                //ConfirmEmailRequired
                if ((divConfirmEmail != null) && (EmailCompare != null))
                {
                    divConfirmEmail.Visible = true;
                    EmailCompare.ErrorMessage = Resource.RegisterCompareEmailWarning;
                    EmailCompare.Enabled = true;
                    EmailCompare.EnableClientScript = true;

                    ConfirmEmailRequired.ErrorMessage = Resource.RegisterCompareEmailRequired;
                    ConfirmEmailRequired.Enabled = true;

                }

            }

            Panel divCaptcha = (Panel)CreateUserWizardStep1.ContentTemplateContainer.FindControl("divCaptcha");
            captcha = (CaptchaControl)CreateUserWizardStep1.ContentTemplateContainer.FindControl("captcha");

            if ((divCaptcha != null) && (captcha != null))
            {
                if (!siteSettings.RequireCaptchaOnRegistration)
                {
                    captcha.Enabled = false;
                    captcha.Visible = false;
                    divCaptcha.Visible = false;
                }
                else
                {
                    captcha.ProviderName = siteSettings.CaptchaProvider;
                    captcha.RecaptchaPrivateKey = siteSettings.RecaptchaPrivateKey;
                    captcha.RecaptchaPublicKey = siteSettings.RecaptchaPublicKey;

                }
            }
        }
Esempio n. 2
0
        private void PopulateControls()
        {
            if (siteSettings == null) { return; }
            if (siteSettings.DisableDbAuth) { this.Visible = false; return; }

            LoginCtrl.SetRedirectUrl = setRedirectUrl;

            lblUserID = (SiteLabel)this.LoginCtrl.FindControl("lblUserID");
            lblEmail = (SiteLabel)this.LoginCtrl.FindControl("lblEmail");
            txtUserName = (TextBox)this.LoginCtrl.FindControl("UserName");
            txtPassword = (TextBox)this.LoginCtrl.FindControl("Password");
            chkRememberMe = (CheckBox)this.LoginCtrl.FindControl("RememberMe");
            btnLogin = (mojoButton)this.LoginCtrl.FindControl("Login");
            lnkRecovery = (HyperLink)this.LoginCtrl.FindControl("lnkPasswordRecovery");
            lnkExtraLink = (HyperLink)this.LoginCtrl.FindControl("lnkRegisterExtraLink");

            if (WebConfigSettings.DisableAutoCompleteOnLogin)
            {
                txtUserName.AutoCompleteType = AutoCompleteType.Disabled;
                txtPassword.AutoCompleteType = AutoCompleteType.Disabled;
            }

            divCaptcha = (Panel)LoginCtrl.FindControl("divCaptcha");
            captcha = (CaptchaControl)LoginCtrl.FindControl("captcha");
            if (!siteSettings.RequireCaptchaOnLogin)
            {
                if (divCaptcha != null) { divCaptcha.Visible = false; }
                if (captcha != null) { captcha.Captcha.Enabled = false; }
            }
            else
            {
                captcha.ProviderName = siteSettings.CaptchaProvider;
                captcha.RecaptchaPrivateKey = siteSettings.RecaptchaPrivateKey;
                captcha.RecaptchaPublicKey = siteSettings.RecaptchaPublicKey;

            }

            if ((siteSettings.UseEmailForLogin) && (!siteSettings.UseLdapAuth))
            {
                if (!WebConfigSettings.AllowLoginWithUsernameWhenSiteSettingIsUseEmailForLogin)
                {
                    EmailValidator regexEmail = new EmailValidator();
                    regexEmail.ControlToValidate = txtUserName.ID;
                    regexEmail.ErrorMessage = Resource.LoginFailedInvalidEmailFormatMessage;
                    this.LoginCtrl.Controls.Add(regexEmail);
                }

            }

            if (siteSettings.UseEmailForLogin && !siteSettings.UseLdapAuth)
            {
                this.lblUserID.Visible = false;
            }
            else
            {
                this.lblEmail.Visible = false;
            }

            if (setFocus) { txtUserName.Focus(); }

            lnkRecovery.Visible = ((siteSettings.AllowPasswordRetrieval ||siteSettings.AllowPasswordReset) && (!siteSettings.UseLdapAuth ||
                                                                           (siteSettings.UseLdapAuth && siteSettings.AllowDbFallbackWithLdap)));

            lnkRecovery.NavigateUrl = this.LoginCtrl.PasswordRecoveryUrl;
            lnkRecovery.Text = this.LoginCtrl.PasswordRecoveryText;

            lnkExtraLink.NavigateUrl = siteRoot + "/Secure/Register.aspx";
            lnkExtraLink.Text = Resource.RegisterLink;
            lnkExtraLink.Visible = siteSettings.AllowNewRegistration;

            string returnUrlParam = Page.Request.Params.Get("returnurl");
            if (!String.IsNullOrEmpty(returnUrlParam))
            {
                //string redirectUrl = returnUrlParam;
                lnkExtraLink.NavigateUrl += "?returnurl=" + SecurityHelper.RemoveMarkup(returnUrlParam);
            }

            chkRememberMe.Visible = siteSettings.AllowPersistentLogin;
            chkRememberMe.Text = this.LoginCtrl.RememberMeText;

            if (WebConfigSettings.ForcePersistentAuthCheckboxChecked)
            {
                chkRememberMe.Checked = true;
                chkRememberMe.Visible = false;
            }

            btnLogin.Text = this.LoginCtrl.LoginButtonText;
            //SiteUtils.SetButtonAccessKey(btnLogin, AccessKeys.LoginAccessKey);
        }