コード例 #1
0
        protected override void InitializeControls()
        {
            base.InitializeControls();

            panel = new Panel();

            HtmlGenericControl divSettingRow = new HtmlGenericControl("div");
            divSettingRow.Attributes.Add("class", "settingrow");

            HtmlGenericControl divButtonRow = new HtmlGenericControl("div");
            divButtonRow.Attributes.Add("class", "settingrow");

            Table table = new Table();
            TableRow exampleRow, inputRow;
            TableCell cell;
            exampleRow = new TableRow();
            table.Rows.Add(exampleRow);
            table.Rows.Add(inputRow = new TableRow());

            // top row
            cell = new TableCell();
            cell.Style[HtmlTextWriterStyle.Color] = "gray";
            cell.Style[HtmlTextWriterStyle.FontSize] = "smaller";
            requiredValidator = new RequiredFieldValidator();
            requiredValidator.ErrorMessage = RequiredTextDefault + RequiredTextSuffix;
            requiredValidator.Text = RequiredTextDefault + RequiredTextSuffix;
            requiredValidator.Display = ValidatorDisplay.Dynamic;
            requiredValidator.ControlToValidate = WrappedTextBox.ID;
            requiredValidator.ValidationGroup = ValidationGroupDefault;
            cell.Controls.Add(requiredValidator);
            uriFormatValidator = new RegularExpressionValidator();
            uriFormatValidator.ErrorMessage = UriFormatTextDefault + RequiredTextSuffix;
            uriFormatValidator.Text = UriFormatTextDefault + RequiredTextSuffix;
            uriFormatValidator.ValidationExpression = UriRegex;
            uriFormatValidator.Enabled = UriValidatorEnabledDefault;
            uriFormatValidator.Display = ValidatorDisplay.Dynamic;
            uriFormatValidator.ControlToValidate = WrappedTextBox.ID;
            uriFormatValidator.ValidationGroup = ValidationGroupDefault;
            cell.Controls.Add(uriFormatValidator);
            examplePrefixLabel = new Label();
            examplePrefixLabel.Text = ExamplePrefixDefault;
            cell.Controls.Add(examplePrefixLabel);
            cell.Controls.Add(new LiteralControl(" "));
            exampleUrlLabel = new Label();
            exampleUrlLabel.Font.Bold = true;
            exampleUrlLabel.Text = ExampleUrlDefault;
            cell.Controls.Add(exampleUrlLabel);
            exampleRow.Cells.Add(cell);

            //  row2
            buttonCell = new TableCell();
            buttonCell.Controls.Add(WrappedTextBox);
            inputRow.Cells.Add(buttonCell);

            loginButton = new Button();
            loginButton.ID = "loginButton";
            loginButton.Text = ButtonTextDefault;
            loginButton.ToolTip = ButtonToolTipDefault;
            loginButton.Click += new EventHandler(loginButton_Click);
            if (ValidationGroupDefault.Length > 0)
            {
                loginButton.ValidationGroup = ValidationGroupDefault;
            }
            #if !Mono
            panel.DefaultButton = loginButton.ID;
            #endif

            SiteLabel lbl = new SiteLabel();
            lbl.ForControl = WrappedTextBox.ID;
            lbl.ConfigKey = "OpenIDLabel";
            lbl.CssClass = "settinglabel";
            divSettingRow.Controls.Add(lbl);
            divSettingRow.Controls.Add(table);

            lbl = new SiteLabel();
            lbl.ConfigKey = "spacer";
            lbl.CssClass = "settinglabel";
            divButtonRow.Controls.Add(lbl);
            divButtonRow.Controls.Add(loginButton);

            panel.Controls.Add(divSettingRow);
            panel.Controls.Add(divButtonRow);
        }
コード例 #2
0
        public static void SetupReadOnlyPropertyControl(
            Panel parentControl,
            mojoProfilePropertyDefinition propertyDefinition,
            String propertyValue,
            Double legacyTimeZoneOffset,
            TimeZoneInfo timeZone)
        {
            if (propertyValue == null)
            {
                propertyValue = String.Empty;
            }

            Literal rowOpenTag = new Literal();
            rowOpenTag.Text = "<div class='settingrow " + propertyDefinition.CssClass + "'>";
            parentControl.Controls.Add(rowOpenTag);

            SiteLabel label = new SiteLabel();
            label.ResourceFile = propertyDefinition.ResourceFile;
            // if key isn't in resource file use assume the resource hasn't been
            //localized and just use the key as the resource
            label.ShowWarningOnMissingKey = false;
            label.ConfigKey = propertyDefinition.LabelResourceKey;
            label.CssClass = "settinglabel";
            label.UseLabelTag = false;
            parentControl.Controls.Add(label);

            Label propertyLabel = new Label();
            parentControl.Controls.Add(propertyLabel);

            bool didLoadControl = false;

            if (propertyDefinition.ISettingControlSrc.Length > 0)
            {
                Control c = parentControl.Page.LoadControl(propertyDefinition.ISettingControlSrc);

                if ((c != null) && (c is IReadOnlySettingControl))
                {
                    c.ID = "isc" + propertyDefinition.Name;
                    parentControl.Controls.Add(label);

                    IReadOnlySettingControl settingControl = (IReadOnlySettingControl)c;

                    settingControl.SetReadOnlyValue(propertyValue);
                    parentControl.Controls.Add(c);
                    didLoadControl = true;

                }
            }

            if (!didLoadControl)
            {
                if ((propertyDefinition.OptionList.Count > 0) && (propertyDefinition.Type != "CheckboxList"))
                {
                    DropDownList dd = new DropDownList();
                    dd.ID = "dd" + propertyDefinition.Name;

                    foreach (mojoProfilePropertyOption option in propertyDefinition.OptionList)
                    {
                        ListItem listItem = new ListItem();
                        listItem.Value = option.Value;
                        listItem.Text = option.TextResourceKey;
                        if (option.TextResourceKey.Length > 0)
                        {
                            if (HttpContext.Current != null)
                            {
                                Object obj = HttpContext.GetGlobalResourceObject(
                                    propertyDefinition.ResourceFile, option.TextResourceKey);

                                if (obj != null)
                                {
                                    listItem.Text = obj.ToString();
                                }
                            }
                        }

                        dd.Items.Add(listItem);
                    }

                    ListItem defaultItem = dd.Items.FindByValue(propertyValue);
                    if (defaultItem != null)
                    {
                        propertyLabel.Text = HttpUtility.HtmlEncode(defaultItem.Text);
                    }
                    //dd.Enabled = false;

                }
                else
                {
                    switch (propertyDefinition.Type)
                    {

                        case "System.Boolean":
                            Literal litBool = new Literal();

                            string imgVal = propertyValue.ToLower();
                            if (imgVal.Length == 0) { imgVal = propertyDefinition.DefaultValue.ToLower(); }
                            if (imgVal.Length == 0) { imgVal = "false"; }

                            litBool.Text = "<img src='/Data/SiteImages/"
                                + imgVal + ".png' alt='" + propertyDefinition.Name + "' />";

                            parentControl.Controls.Add(litBool);

                            break;

                        case "System.DateTime":
                            Literal litDateTime = new Literal();
                            DateTime dt;
                            if (DateTime.TryParse(
                                propertyValue,
                                CultureInfo.CurrentCulture,
                                DateTimeStyles.AdjustToUniversal, out dt))
                            {

                                if (propertyDefinition.IncludeTimeForDate)
                                {
                                    dt = dt.AddHours(legacyTimeZoneOffset);
                                    litDateTime.Text = dt.ToString();
                                }
                                else
                                {
                                    litDateTime.Text = dt.Date.ToShortDateString();
                                }
                            }
                            else
                            {
                                litDateTime.Text = SecurityHelper.PreventCrossSiteScripting(propertyValue);
                            }

                            parentControl.Controls.Add(litDateTime);
                            break;

                        case "System.String":
                        default:

                            if (propertyValue.Length > 0)
                            {
                                if (propertyDefinition.AllowMarkup)
                                {
                                    propertyLabel.Text = SecurityHelper.PreventCrossSiteScripting(propertyValue);
                                }
                                else
                                {
                                    if (propertyDefinition.Name.ToLower().IndexOf("url") > -1)
                                    {
                                        Literal litLink = new Literal();
                                        litLink.Text = "<a href='" + HttpUtility.HtmlEncode(propertyValue)
                                            + "'>" + HttpUtility.HtmlEncode(propertyValue)
                                            + "</a>";

                                        parentControl.Controls.Add(litLink);

                                    }
                                    else
                                    {
                                        propertyLabel.Text = HttpUtility.HtmlEncode(propertyValue);
                                    }
                                }
                            }
                            else
                            {
                                propertyLabel.Text = "&nbsp;";
                            }

                            break;

                    }

                }

            }

            if (propertyLabel.Text.Length > 0)
            {
                parentControl.Controls.Add(propertyLabel);
            }

            Literal rowCloseTag = new Literal();
            rowCloseTag.Text = "</div>";
            parentControl.Controls.Add(rowCloseTag);
        }
コード例 #3
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);
        }
コード例 #4
0
        public static void SetupPropertyControl(
            Page currentPage,
            Panel parentControl,
            mojoProfilePropertyDefinition propertyDefinition,
            String propertyValue,
            Double legacyTimeZoneOffset,
            TimeZoneInfo timeZone,
            string siteRoot)
        {
            if (propertyValue == null)
            {
                propertyValue = String.Empty;
            }

            string validatorSkinID = "Profile";

            if (currentPage is mojoPortal.Web.UI.Pages.Register)
            {
                validatorSkinID = "Registration";
            }

            Literal rowOpenTag = new Literal();
            rowOpenTag.Text = "<div class='settingrow " + propertyDefinition.CssClass + "'>";
            parentControl.Controls.Add(rowOpenTag);

            SiteLabel label = new SiteLabel();
            label.ResourceFile = propertyDefinition.ResourceFile;
            // if key isn't in resource file use assume the resource hasn't been
            //localized and just use the key as the resource
            label.ShowWarningOnMissingKey = false;
            label.ConfigKey = propertyDefinition.LabelResourceKey;
            label.CssClass = "settinglabel";

            if (propertyDefinition.ISettingControlSrc.Length > 0)
            {
                Control c = null;
                if (propertyDefinition.ISettingControlSrc.EndsWith(".ascx"))
                {
                    c = currentPage.LoadControl(propertyDefinition.ISettingControlSrc);
                }
                else
                {
                    try
                    {
                        c = Activator.CreateInstance(System.Type.GetType(propertyDefinition.ISettingControlSrc)) as Control;

                    }
                    catch (Exception ex)
                    {
                        log.Error(ex);
                    }
                }

                if ((c != null) && (c is ISettingControl))
                {
                    c.ID = "isc" + propertyDefinition.Name;
                    parentControl.Controls.Add(label);

                    ISettingControl settingControl = (ISettingControl)c;

                    settingControl.SetValue(propertyValue);
                    parentControl.Controls.Add(c);

                    if (propertyDefinition.IncludeHelpLink)
                    {
                        AddHelpLink(parentControl, propertyDefinition);
                    }
                }

            }
            else if (propertyDefinition.OptionList.Count > 0)
            {
                if (propertyDefinition.Type == "CheckboxList")
                {
                    CheckBoxList cbl = CreateCheckBoxListQuestion(propertyDefinition, propertyValue);
                    cbl.ID = "cbl" + propertyDefinition.Name;
                    cbl.EnableTheming = false;
                    cbl.CssClass = "forminput";

                    cbl.TabIndex = 10;
                    label.ForControl = cbl.ID;
                    parentControl.Controls.Add(label);

                    parentControl.Controls.Add(cbl);

                    if (propertyDefinition.IncludeHelpLink)
                    {
                        AddHelpLink(parentControl, propertyDefinition);
                    }

                    if (propertyDefinition.RequiredForRegistration)
                    {
                        CheckBoxListValidator rfv = new CheckBoxListValidator();
                        rfv.SkinID = validatorSkinID;
                        rfv.ControlToValidate = cbl.ID;

                        rfv.ErrorMessage = string.Format(CultureInfo.InvariantCulture, Resources.ProfileResource.ProfileRequiredItemFormat,
                            ResourceHelper.GetResourceString(propertyDefinition.ResourceFile, propertyDefinition.LabelResourceKey));

                        //rfv.Display = ValidatorDisplay.None;
                        rfv.ValidationGroup = "profile";
                        parentControl.Controls.Add(rfv);
                    }

                }
                else
                {
                    // add a dropdownlist with the options

                    DropDownList dd = CreateDropDownQuestion(propertyDefinition, propertyValue);
                    dd.ID = "dd" + propertyDefinition.Name;
                    dd.EnableTheming = false;
                    dd.CssClass = "forminput " + propertyDefinition.CssClass;

                    dd.TabIndex = 10;
                    label.ForControl = dd.ID;
                    parentControl.Controls.Add(label);

                    parentControl.Controls.Add(dd);

                    if (propertyDefinition.IncludeHelpLink)
                    {
                        AddHelpLink(parentControl, propertyDefinition);
                    }

                    if (propertyDefinition.RequiredForRegistration)
                    {
                        RequiredFieldValidator rfvDd = new RequiredFieldValidator();
                        rfvDd.SkinID = validatorSkinID;
                        rfvDd.ControlToValidate = dd.ID;
                        //if(dd.Items.Count > 0)
                        //{
                        //    rfvDd.InitialValue = dd.Items[0].Value;
                        //}

                        rfvDd.ErrorMessage = string.Format(CultureInfo.InvariantCulture, Resources.ProfileResource.ProfileRequiredItemFormat,
                            ResourceHelper.GetResourceString(propertyDefinition.ResourceFile, propertyDefinition.LabelResourceKey));

                        rfvDd.ValidationGroup = "profile";
                        parentControl.Controls.Add(rfvDd);

                    }

                    if (propertyDefinition.RegexValidationExpression.Length > 0)
                    {
                        RegularExpressionValidator regexValidator = new RegularExpressionValidator();
                        regexValidator.SkinID = validatorSkinID;
                        regexValidator.ControlToValidate = dd.ID;
                        regexValidator.ValidationExpression = propertyDefinition.RegexValidationExpression;
                        regexValidator.ValidationGroup = "profile";
                        if (propertyDefinition.RegexValidationErrorResourceKey.Length > 0)
                        {
                            regexValidator.ErrorMessage = ResourceHelper.GetResourceString(
                                propertyDefinition.ResourceFile,
                                propertyDefinition.RegexValidationErrorResourceKey);

                        }

                        //regexValidator.Display = ValidatorDisplay.None;
                        parentControl.Controls.Add(regexValidator);
                    }
                }

            }
            else
            {

                switch (propertyDefinition.Type)
                {
                    case "System.Boolean":
                        CheckBox checkBox = new CheckBox();
                        checkBox.TabIndex = 10;
                        checkBox.ID = "chk" + propertyDefinition.Name;
                        checkBox.CssClass = "forminput " + propertyDefinition.CssClass;
                        label.ForControl = checkBox.ID;
                        parentControl.Controls.Add(label);
                        parentControl.Controls.Add(checkBox);
                        if (propertyDefinition.IncludeHelpLink)
                        {
                            AddHelpLink(parentControl, propertyDefinition);
                        }

                        if (propertyValue.ToLower() == "true")
                        {
                            checkBox.Checked = true;
                        }
                        break;

                    case "System.DateTime":
                        // TODO: to really make this culture aware we should store the users
                        // culture as well and use the user's culture to
                        // parse the date
                        DatePickerControl datePicker = CreateDatePicker(propertyDefinition, propertyValue, legacyTimeZoneOffset, timeZone, siteRoot);

                        datePicker.TabIndex = 10;
                        datePicker.ID = "dp" + propertyDefinition.Name;
                        datePicker.CssClass = "forminput " + propertyDefinition.CssClass;
                        parentControl.Controls.Add(label);

                        parentControl.Controls.Add(datePicker);

                        if (propertyDefinition.IncludeHelpLink)
                        {
                            AddHelpLink(parentControl, propertyDefinition);
                        }

                        if (propertyDefinition.RequiredForRegistration)
                        {
                            RequiredFieldValidator rfvDate = new RequiredFieldValidator();
                            rfvDate.SkinID = validatorSkinID;
                            rfvDate.ControlToValidate = datePicker.ID;

                            rfvDate.ErrorMessage = string.Format(CultureInfo.InvariantCulture, Resources.ProfileResource.ProfileRequiredItemFormat,
                                ResourceHelper.GetResourceString(propertyDefinition.ResourceFile, propertyDefinition.LabelResourceKey));

                            //rfvDate.Display = ValidatorDisplay.None;
                            rfvDate.ValidationGroup = "profile";
                            parentControl.Controls.Add(rfvDate);
                        }

                        if (propertyDefinition.RegexValidationExpression.Length > 0)
                        {
                            RegularExpressionValidator regexValidatorDate = new RegularExpressionValidator();
                            regexValidatorDate.SkinID = validatorSkinID;
                            regexValidatorDate.ControlToValidate = datePicker.ID;
                            regexValidatorDate.ValidationExpression = propertyDefinition.RegexValidationExpression;
                            regexValidatorDate.ValidationGroup = "profile";
                            if (propertyDefinition.RegexValidationErrorResourceKey.Length > 0)
                            {
                                regexValidatorDate.ErrorMessage = ResourceHelper.GetResourceString(
                                    propertyDefinition.ResourceFile,
                                    propertyDefinition.RegexValidationErrorResourceKey);

                            }

                            //regexValidatorDate.Display = ValidatorDisplay.None;
                            parentControl.Controls.Add(regexValidatorDate);
                        }

                        break;

                    case "System.String":
                    default:

                        TextBox textBox = new TextBox();
                        textBox.TabIndex = 10;
                        textBox.ID = "txt" + propertyDefinition.Name;
                        textBox.CssClass = "forminput " + propertyDefinition.CssClass;
                        label.ForControl = textBox.ID;
                        parentControl.Controls.Add(label);

                        if (propertyDefinition.MaxLength > 0)
                        {
                            textBox.MaxLength = propertyDefinition.MaxLength;
                        }

                        if (propertyDefinition.Columns > 0)
                        {
                            textBox.Columns = propertyDefinition.Columns;
                        }

                        if (propertyDefinition.Rows > 1)
                        {
                            textBox.TextMode = TextBoxMode.MultiLine;
                            textBox.Rows = propertyDefinition.Rows;
                        }

                        parentControl.Controls.Add(textBox);
                        if (propertyDefinition.IncludeHelpLink)
                        {
                            AddHelpLink(parentControl, propertyDefinition);
                        }

                        if (propertyValue.Length > 0)
                        {
                            textBox.Text = propertyValue;
                        }
                        if (propertyDefinition.RequiredForRegistration)
                        {
                            RequiredFieldValidator rfv = new RequiredFieldValidator();
                            rfv.SkinID = validatorSkinID;
                            rfv.ControlToValidate = textBox.ID;

                            rfv.ErrorMessage = string.Format(CultureInfo.InvariantCulture, Resources.ProfileResource.ProfileRequiredItemFormat,
                                ResourceHelper.GetResourceString(propertyDefinition.ResourceFile, propertyDefinition.LabelResourceKey));

                            //rfv.Display = ValidatorDisplay.None;
                            rfv.ValidationGroup = "profile";
                            parentControl.Controls.Add(rfv);
                        }

                        if (propertyDefinition.RegexValidationExpression.Length > 0)
                        {
                            RegularExpressionValidator regexValidator = new RegularExpressionValidator();
                            regexValidator.SkinID = validatorSkinID;
                            regexValidator.ControlToValidate = textBox.ID;
                            regexValidator.ValidationExpression = propertyDefinition.RegexValidationExpression;
                            regexValidator.ValidationGroup = "profile";
                            if (propertyDefinition.RegexValidationErrorResourceKey.Length > 0)
                            {
                                regexValidator.ErrorMessage = ResourceHelper.GetResourceString(
                                    propertyDefinition.ResourceFile,
                                    propertyDefinition.RegexValidationErrorResourceKey);

                            }

                            //regexValidator.Display = ValidatorDisplay.None;
                            parentControl.Controls.Add(regexValidator);
                        }

                        break;

                }

            }

            Literal rowCloseTag = new Literal();
            rowCloseTag.Text = "</div>";
            parentControl.Controls.Add(rowCloseTag);
        }