// Adding a New User

        /// <summary>
        /// Gets password and "password again" form items. The validation sets this data value to the provided password, and ensures that the two form items contain
        /// identical, valid passwords.
        /// </summary>
        public static IReadOnlyCollection <FormItem> GetPasswordModificationFormItems(
            this DataValue <string> password, IEnumerable <PhrasingComponent> firstLabel = null, IEnumerable <PhrasingComponent> secondLabel = null)
        {
            var passwordAgain         = new DataValue <string>();
            var passwordAgainFormItem = passwordAgain.ToTextControl(true, setup: TextControlSetup.CreateObscured(autoFillTokens: "new-password"), value: "")
                                        .ToFormItem(label: secondLabel?.Materialize() ?? "Password again".ToComponents());

            var passwordFormItem = password.ToTextControl(
                true,
                setup: TextControlSetup.CreateObscured(autoFillTokens: "new-password"),
                value: "",
                additionalValidationMethod: validator => {
                if (password.Value != passwordAgain.Value)
                {
                    validator.NoteErrorAndAddMessage("Passwords do not match.");
                }
                else
                {
                    if (SystemProvider is StrictFormsAuthUserManagementProvider strictProvider)
                    {
                        strictProvider.ValidatePassword(validator, password.Value);
                    }
                    else if (password.Value.Length < 7)
                    {
                        validator.NoteErrorAndAddMessage("Passwords must be at least 7 characters long.");
                    }
                }
            })
                                   .ToFormItem(label: firstLabel?.Materialize() ?? "Password".ToComponents());

            return(new[] { passwordFormItem, passwordAgainFormItem });
        }
        protected override void loadData()
        {
            if (info.Password.Any())
            {
                if (!pageViewDataModificationsExecuted)
                {
                    throw new ApplicationException("Page-view data modifications did not execute.");
                }

                ph.AddControlsReturnThis(new Paragraph("Please wait.".ToComponents()).ToCollection().GetControls());
                StandardLibrarySessionState.Instance.SetInstantClientSideNavigation(new ExternalResourceInfo(info.ReturnUrl).GetUrl());
                return;
            }

            FormState.ExecuteWithDataModificationsAndDefaultAction(
                PostBack.CreateFull(
                    firstModificationMethod: () => logIn(false),
                    actionGetter: () => new PostBackAction(new ExternalResourceInfo(info.ReturnUrl)))
                .ToCollection(),
                () => {
                ph.AddControlsReturnThis(
                    FormItemList.CreateStack(
                        items: new TextControl(
                            "",
                            true,
                            setup: TextControlSetup.CreateObscured(),
                            validationMethod: (postBackValue, validator) => {
                    // NOTE: Using a single password here is a hack. The real solution is being able to use RSIS credentials, which is a goal.
                    var passwordMatch = postBackValue == ConfigurationStatics.SystemGeneralProvider.IntermediateLogInPassword;
                    if (!passwordMatch)
                    {
                        validator.NoteErrorAndAddMessage("Incorrect password.");
                    }
                }).ToFormItem(label: "Enter your password for this non-live installation".ToComponents())
                        .ToCollection())
                    .ToCollection()
                    .GetControls());

                EwfUiStatics.SetContentFootActions(new ButtonSetup("Log In").ToCollection());
            });
        }
Exemplo n.º 3
0
        // Adding a New User

        /// <summary>
        /// Gets password and "password again" form items. The validation ensures that the two form items contain identical, valid passwords.
        /// </summary>
        /// <param name="passwordUpdater">A method that takes a user ID and updates the password data for the corresponding user. Do not pass null.</param>
        /// <param name="firstLabel"></param>
        /// <param name="secondLabel"></param>
        public static IReadOnlyCollection <FormItem> GetPasswordModificationFormItems(
            out Action <int> passwordUpdater, IEnumerable <PhrasingComponent> firstLabel = null, IEnumerable <PhrasingComponent> secondLabel = null)
        {
            var password = new DataValue <string>();
            var passwordAgainFormItem = password.ToTextControl(true, setup: TextControlSetup.CreateObscured(autoFillTokens: "new-password"), value: "")
                                        .ToFormItem(label: secondLabel?.Materialize() ?? "Password again".ToComponents());

            var passwordFormItem = new TextControl(
                "",
                true,
                setup: TextControlSetup.CreateObscured(autoFillTokens: "new-password"),
                validationMethod: (postBackValue, validator) => {
                if (postBackValue != password.Value)
                {
                    validator.NoteErrorAndAddMessage("Passwords do not match.");
                }
                else
                {
                    if (UserManagementStatics.LocalIdentityProvider.PasswordValidationMethod != null)
                    {
                        UserManagementStatics.LocalIdentityProvider.PasswordValidationMethod(validator, password.Value);
                    }
                    else if (password.Value.Length < 7)
                    {
                        validator.NoteErrorAndAddMessage("Passwords must be at least 7 characters long.");
                    }
                }
            }).ToFormItem(label: firstLabel?.Materialize() ?? "Password".ToComponents());

            passwordUpdater = userId => {
                if (!password.Changed)
                {
                    return;
                }
                var p = new LocalIdentityProvider.Password(password.Value);
                UserManagementStatics.LocalIdentityProvider.PasswordUpdater(userId, p.Salt, p.ComputeSaltedHash());
            };

            return(new[] { passwordFormItem, passwordAgainFormItem });
        }
Exemplo n.º 4
0
 private IReadOnlyCollection <Func <string, FormItem> > getControls() =>
 new[]
 {
     get("Standard", null), get("Max length 25", null, maxLength: 25), get("Placeholder", TextControlSetup.Create(placeholder: "Type here")),
     get("Name auto-fill", TextControlSetup.Create(autoFillTokens: "name")),
     get("Auto-complete", TextControlSetup.CreateAutoComplete(TestService.GetInfo())),
     get("Spell-checking disabled", TextControlSetup.Create(checksSpellingAndGrammar: false)),
     get("Spell-checking enabled", TextControlSetup.Create(checksSpellingAndGrammar: true)), id => {
         var pb = PostBack.CreateIntermediate(null, id: id);
         return(FormState.ExecuteWithDataModificationsAndDefaultAction(
                    FormState.Current.DataModifications.Append(pb),
                    () => get("Separate value-changed action", TextControlSetup.Create(valueChangedAction: new PostBackFormAction(pb)))(id)));
     },
     get("Read-only", TextControlSetup.CreateReadOnly()), get("Multiline", TextControlSetup.Create(numberOfRows: 3)),
     get("Multiline, max length 25", TextControlSetup.Create(numberOfRows: 3), maxLength: 25),
     get("Multiline with placeholder", TextControlSetup.Create(numberOfRows: 3, placeholder: "Type longer text here")),
     get("Multiline auto-fill", TextControlSetup.Create(numberOfRows: 3, autoFillTokens: "street-address")),
     get("Multiline auto-complete", TextControlSetup.CreateAutoComplete(TestService.GetInfo(), numberOfRows: 3)),
     get("Multiline, spell-checking disabled", TextControlSetup.Create(numberOfRows: 3, checksSpellingAndGrammar: false)),
     get("Multiline, spell-checking enabled", TextControlSetup.Create(numberOfRows: 3, checksSpellingAndGrammar: true)), id => {
         var pb = PostBack.CreateIntermediate(null, id: id);
         return(FormState.ExecuteWithDataModificationsAndDefaultAction(
                    FormState.Current.DataModifications.Append(pb),
                    () => get(
                        "Multiline with separate value-changed action",
                        TextControlSetup.Create(numberOfRows: 3, valueChangedAction: new PostBackFormAction(pb)))(id)));
     },
     get("Multiline read-only", TextControlSetup.CreateReadOnly(numberOfRows: 3)), get("Obscured", TextControlSetup.CreateObscured()),
     get("Obscured, max length 25", TextControlSetup.CreateObscured(), maxLength: 25),
     get("Obscured with placeholder", TextControlSetup.CreateObscured(placeholder: "Type here")),
     get("Obscured auto-fill", TextControlSetup.CreateObscured(autoFillTokens: "new-password")), id => {
         var pb = PostBack.CreateIntermediate(null, id: id);
         return(FormState.ExecuteWithDataModificationsAndDefaultAction(
                    FormState.Current.DataModifications.Append(pb),
                    () => get(
                        "Obscured with separate value-changed action",
                        TextControlSetup.CreateObscured(valueChangedAction: new PostBackFormAction(pb)))(id)));
     }
 };
Exemplo n.º 5
0
        private FormItem getPasswordFormItem(
            IEnumerable <UpdateRegionSet> updateRegionSets, AutofocusCondition autofocusCondition, DataValue <string> password,
            ButtonBehavior sendCodeButtonBehavior)
        {
            var control = password.ToTextControl(
                false,
                setup: TextControlSetup.CreateObscured(classes: passwordClass, autoFillTokens: "current-password"),
                value: "");

            return(new FlowAutofocusRegion(
                       autofocusCondition,
                       new GenericFlowContainer(
                           control.PageComponent.Append <FlowComponent>(
                               new GenericFlowContainer(
                                   new GenericPhrasingContainer("or".ToComponents()).Append <PhrasingComponent>(
                                       new EwfButton(new StandardButtonStyle("Email Login Code"), behavior: sendCodeButtonBehavior, classes: loginCodeButtonClass))
                                   .Materialize()))
                           .Materialize(),
                           classes: passwordContainerClass).ToCollection()).ToFormItem(
                       setup: new FormItemSetup(updateRegionSets: updateRegionSets),
                       label: control.Labeler.CreateLabel("Password".ToComponents()),
                       validation: control.Validation));
        }
        protected override void loadData()
        {
            EwfUiStatics.OmitContentBox();

            Tuple <IReadOnlyCollection <EtherealComponent>, Func <FormsAuthCapableUser> > logInHiddenFieldsAndMethod = null;
            var logInPb = PostBack.CreateFull(
                firstModificationMethod: () => user = logInHiddenFieldsAndMethod.Item2(),
                actionGetter: () => new PostBackAction(
                    user.MustChangePassword ? ChangePassword.Page.GetInfo(info.ReturnUrl) as ResourceInfo : new ExternalResourceInfo(info.ReturnUrl)));
            var newPasswordPb = PostBack.CreateFull(id: "newPw", actionGetter: getSendNewPasswordAction);

            FormState.ExecuteWithDataModificationsAndDefaultAction(
                logInPb.ToCollection(),
                () => {
                var registeredComponents = new List <FlowComponent>();
                registeredComponents.Add(
                    new Paragraph(
                        "You may log in to this system if you have registered your email address with {0}"
                        .FormatWith(FormsAuthStatics.SystemProvider.AdministratingCompanyName)
                        .ToComponents()));

                emailAddress = new DataValue <string>();
                var password = new DataValue <string>();
                registeredComponents.Add(
                    FormItemList.CreateStack(
                        generalSetup: new FormItemListSetup(buttonSetup: new ButtonSetup("Log In"), enableSubmitButton: true),
                        items: FormState
                        .ExecuteWithDataModificationsAndDefaultAction(
                            new[] { logInPb, newPasswordPb },
                            () => emailAddress.GetEmailAddressFormItem("Email address".ToComponents()))
                        .Append(
                            password.ToTextControl(true, setup: TextControlSetup.CreateObscured(autoFillTokens: "current-password"), value: "")
                            .ToFormItem(label: "Password".ToComponents()))
                        .Materialize()));

                if (FormsAuthStatics.PasswordResetEnabled)
                {
                    registeredComponents.Add(
                        new Paragraph(
                            new ImportantContent("Forgot password?".ToComponents()).ToCollection()
                            .Concat(" ".ToComponents())
                            .Append(
                                new EwfButton(
                                    new StandardButtonStyle("Send me a new password", buttonSize: ButtonSize.ShrinkWrap),
                                    behavior: new PostBackBehavior(postBack: newPasswordPb)))
                            .Materialize()));
                }

                ph.AddControlsReturnThis(
                    new FlowAutofocusRegion(
                        AutofocusCondition.InitialRequest(),
                        new Section("Registered users", registeredComponents, style: SectionStyle.Box).ToCollection()).ToCollection()
                    .GetControls());

                logInHiddenFieldsAndMethod = FormsAuthStatics.GetLogInHiddenFieldsAndMethod(
                    emailAddress,
                    password,
                    getUnregisteredEmailMessage(),
                    "Incorrect password. If you do not know your password, enter your email address and send yourself a new password using the link below.");
                logInHiddenFieldsAndMethod.Item1.AddEtherealControls(this);
            });

            var specialInstructions = EwfUiStatics.AppProvider.GetSpecialInstructionsForLogInPage();

            if (specialInstructions != null)
            {
                ph.AddControlsReturnThis(specialInstructions);
            }
            else
            {
                var unregisteredComponents = new List <FlowComponent>();
                unregisteredComponents.Add(
                    new Paragraph("If you have difficulty logging in, please {0}".FormatWith(FormsAuthStatics.SystemProvider.LogInHelpInstructions).ToComponents()));
                ph.AddControlsReturnThis(new Section("Unregistered users", unregisteredComponents, style: SectionStyle.Box).ToCollection().GetControls());
            }
        }