protected override void loadData()
        {
            var pb  = PostBack.CreateFull(actionGetter: () => new PostBackAction(new ExternalResourceInfo(es.info.ReturnAndDestinationUrl)));
            var fib = FormItemBlock.CreateFormItemTable();

            newPassword = new DataValue <string>();
            fib.AddFormItems(
                FormItem.Create(
                    "New password",
                    new EwfTextBox("", masksCharacters: true),
                    validationGetter: control => new Validation((pbv, v) => newPassword.Value = control.GetPostBackValue(pbv), pb)));
            var newPasswordConfirm = new DataValue <string>();

            fib.AddFormItems(
                FormItem.Create(
                    "Re-type new password",
                    new EwfTextBox("", masksCharacters: true),
                    validationGetter: control => new Validation((pbv, v) => newPasswordConfirm.Value = control.GetPostBackValue(pbv), pb)));
            pb.AddTopValidationMethod((pbv, validator) => FormsAuthStatics.ValidatePassword(validator, newPassword, newPasswordConfirm));

            ph.AddControlsReturnThis(fib);
            EwfUiStatics.SetContentFootActions(new ActionButtonSetup("Change Password", new PostBackButton(pb)));

            pb.AddModificationMethod(modifyData);
        }
 /// <summary>
 /// Call this during ModifyData.
 /// </summary>
 // NOTE SJR: This needs to change: You can't see this comment unless you're scrolling through all of the methods. It's easy to not call this
 // even though the radio button for generating a new password and emailing it to the user is always there.
 public void SendEmailIfNecessary()
 {
     if (passwordToEmail == null)
     {
         return;
     }
     FormsAuthStatics.SendPassword(Email, passwordToEmail);
     EwfPage.AddStatusMessage(StatusMessageType.Info, "Password reset email sent.");
 }
Exemple #3
0
        protected override PageContent getContent()
        {
            var mod      = getMod();
            var password = new DataValue <string> {
                Value = ""
            };
            Tuple <IReadOnlyCollection <EtherealComponent>, Action <int> > logInHiddenFieldsAndMethod = null;

            return(FormState.ExecuteWithDataModificationsAndDefaultAction(
                       PostBack.CreateFull(
                           modificationMethod: () => {
                if (AppTools.User == null)
                {
                    mod.UserId = MainSequence.GetNextValue();
                }
                if (password.Value.Any())
                {
                    var passwordSalter = new Password(password.Value);
                    mod.Salt = passwordSalter.Salt;
                    mod.SaltedPassword = passwordSalter.ComputeSaltedHash();
                }
                mod.Execute();

                logInHiddenFieldsAndMethod?.Item2(mod.UserId);
            },
                           actionGetter: () => new PostBackAction(logInHiddenFieldsAndMethod != null ? (PageBase)Home.GetInfo() : Profile.GetInfo(AppTools.User.UserId)))
                       .ToCollection(),
                       () => {
                var content = new UiPageContent(contentFootActions: new ButtonSetup(AppTools.User != null ? "Update Settings" : "Sign up").ToCollection());

                if (AppTools.User == null)
                {
                    content.Add(
                        new EwfHyperlink(
                            EnterpriseWebLibrary.EnterpriseWebFramework.UserManagement.Pages.LogIn.GetInfo(Home.GetInfo().GetUrl()),
                            new StandardHyperlinkStyle("Have an account?")));
                }

                content.Add(getFormItemStack(mod, password));

                if (AppTools.User == null)
                {
                    logInHiddenFieldsAndMethod = FormsAuthStatics.GetLogInHiddenFieldsAndSpecifiedUserLogInMethod();
                    content.Add(logInHiddenFieldsAndMethod.Item1);
                }

                return content;
            }));
        }
Exemple #4
0
        protected override void loadData()
        {
            ph.AddControlsReturnThis(
                new Paragraph(
                    StringTools.ConcatenateWithDelimiter(
                        " ",
                        "Click \"Reset Password\" to email yourself a new password.",
                        "Upon receiving your new password, you may immediately use it to log in.",
                        "You will then be prompted to change your password to something you will remember, which you may use to log in from that point forward.")));

            EwfUiStatics.SetContentFootActions(
                new ActionButtonSetup(
                    "Reset Password",
                    new PostBackButton(
                        PostBack.CreateFull(
                            firstModificationMethod: () => {
                FormsAuthStatics.ResetAndSendPassword(info.User.UserId);
                AddStatusMessage(StatusMessageType.Info, "Your new password has been sent to your email address.");
            },
                            actionGetter: () => new PostBackAction(new ExternalResourceInfo(info.ReturnUrl))))));
        }
        /// <summary>
        /// Call this during LoadData.
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="vl"></param>
        /// <param name="availableRoles">Pass a restricted list of <see cref="Role"/>s the user may select. Otherwise, Roles available
        /// in the System Provider are used.</param>
        /// <param name="validationPredicate">If the function returns true, validation continues.</param>
        public void LoadData(int?userId, ValidationList vl, List <Role> availableRoles = null, Func <bool> validationPredicate = null)
        {
            availableRoles = (availableRoles != null ? availableRoles.OrderBy(r => r.Name) : UserManagementStatics.SystemProvider.GetRoles()).ToList();

            user = userId.HasValue ? UserManagementStatics.GetUser(userId.Value, true) : null;
            if (includePasswordControls() && user != null)
            {
                facUser = FormsAuthStatics.GetUser(user.UserId, true);
            }

            Func <bool> validationShouldRun = () => validationPredicate == null || validationPredicate();

            var b = FormItemBlock.CreateFormItemTable(heading: "Security Information");

            b.AddFormItems(
                FormItem.Create(
                    "Email address",
                    new EwfTextBox(user != null ? user.Email : ""),
                    validationGetter: control => new Validation(
                        (pbv, validator) => {
                if (validationShouldRun())
                {
                    Email = validator.GetEmailAddress(new ValidationErrorHandler("email address"), control.GetPostBackValue(pbv), false);
                }
            },
                        vl)));

            if (includePasswordControls())
            {
                var group = new RadioButtonGroup(false);

                var keepPassword = FormItem.Create(
                    "",
                    group.CreateInlineRadioButton(true, label: userId.HasValue ? "Keep the current password" : "Do not create a password"),
                    validationGetter: control => new Validation(
                        (pbv, validator) => {
                    if (!validationShouldRun() || !control.IsCheckedInPostBack(pbv))
                    {
                        return;
                    }
                    if (user != null)
                    {
                        Salt               = facUser.Salt;
                        SaltedPassword     = facUser.SaltedPassword;
                        MustChangePassword = facUser.MustChangePassword;
                    }
                    else
                    {
                        genPassword(false);
                    }
                },
                        vl));

                var generatePassword = FormItem.Create(
                    "",
                    group.CreateInlineRadioButton(false, label: "Generate a " + (userId.HasValue ? "new, " : "") + "random password and email it to the user"),
                    validationGetter: control => new Validation(
                        (pbv, validator) => {
                    if (validationShouldRun() && control.IsCheckedInPostBack(pbv))
                    {
                        genPassword(true);
                    }
                },
                        vl));

                var newPassword      = new DataValue <string>();
                var confirmPassword  = new DataValue <string>();
                var newPasswordTable = EwfTable.Create(style: EwfTableStyle.StandardExceptLayout);
                newPasswordTable.AddItem(
                    new EwfTableItem(
                        "Password",
                        FormItem.Create(
                            "",
                            new EwfTextBox("", masksCharacters: true, disableBrowserAutoComplete: true)
                {
                    Width = Unit.Pixel(200)
                },
                            validationGetter: control => new Validation((pbv, v) => newPassword.Value = control.GetPostBackValue(pbv), vl)).ToControl()));
                newPasswordTable.AddItem(
                    new EwfTableItem(
                        "Password again",
                        FormItem.Create(
                            "",
                            new EwfTextBox("", masksCharacters: true, disableBrowserAutoComplete: true)
                {
                    Width = Unit.Pixel(200)
                },
                            validationGetter: control => new Validation((pbv, v) => confirmPassword.Value = control.GetPostBackValue(pbv), vl)).ToControl()));

                var providePasswordRadio = group.CreateBlockRadioButton(false, label: "Provide a " + (userId.HasValue ? "new " : "") + "password");
                providePasswordRadio.NestedControls.Add(newPasswordTable);
                var providePassword = FormItem.Create(
                    "",
                    providePasswordRadio,
                    validationGetter: control => new Validation(
                        (pbv, validator) => {
                    if (!validationShouldRun() || !control.IsCheckedInPostBack(pbv))
                    {
                        return;
                    }
                    FormsAuthStatics.ValidatePassword(validator, newPassword, confirmPassword);
                    var p              = new Password(newPassword.Value);
                    Salt               = p.Salt;
                    SaltedPassword     = p.ComputeSaltedHash();
                    MustChangePassword = false;
                },
                        vl));

                b.AddFormItems(
                    FormItem.Create("Password", ControlStack.CreateWithControls(true, keepPassword.ToControl(), generatePassword.ToControl(), providePassword.ToControl())));
            }

            b.AddFormItems(
                FormItem.Create(
                    "Role",
                    SelectList.CreateDropDown(
                        from i in availableRoles select SelectListItem.Create(i.RoleId as int?, i.Name),
                        user != null ? user.Role.RoleId as int? : null),
                    validationGetter: control => new Validation(
                        (pbv, validator) => {
                if (validationShouldRun())
                {
                    RoleId = control.ValidateAndGetSelectedItemIdInPostBack(pbv, validator) ?? default(int);
                }
            },
                        vl)));

            Controls.Add(b);
        }
        protected override void loadData()
        {
            var logInPb =
                PostBack.CreateFull(
                    actionGetter:
                    () =>
                    new PostBackAction(user.MustChangePassword ? ChangePassword.Page.GetInfo(info.ReturnUrl) as ResourceInfo : new ExternalResourceInfo(info.ReturnUrl)));
            var newPasswordPb = PostBack.CreateFull(id: "newPw", actionGetter: getSendNewPasswordAction);

            var registeredTable = EwfTable.Create(caption: "Registered users");

            registeredTable.AddItem(
                new EwfTableItem(
                    ("You may log in to this system if you have registered your email address with " + FormsAuthStatics.SystemProvider.AdministratingCompanyName).ToCell(
                        new TableCellSetup(fieldSpan: 2))));

            emailAddress = new DataValue <string>();
            var emailVl = new BasicValidationList();

            registeredTable.AddItem(
                new EwfTableItem("Email address", emailAddress.GetEmailAddressFormItem("", "Please enter a valid email address.", emailVl).ToControl()));
            logInPb.AddValidations(emailVl);
            newPasswordPb.AddValidations(emailVl);

            var password = new DataValue <string>();

            registeredTable.AddItem(
                new EwfTableItem(
                    "Password",
                    FormItem.Create(
                        "",
                        new EwfTextBox("", masksCharacters: true),
                        validationGetter: control => new EwfValidation((pbv, v) => password.Value = control.GetPostBackValue(pbv), logInPb)).ToControl()));

            if (FormsAuthStatics.PasswordResetEnabled)
            {
                registeredTable.AddItem(
                    new EwfTableItem(
                        new PlaceHolder().AddControlsReturnThis(
                            "If you are a first-time user and do not know your password, or if you have forgotten your password, ".GetLiteralControl(),
                            new PostBackButton(newPasswordPb, new TextActionControlStyle("click here to immediately send yourself a new password."), usesSubmitBehavior: false))
                        .ToCell(new TableCellSetup(fieldSpan: 2))));
            }

            ph.AddControlsReturnThis(registeredTable);

            var specialInstructions = EwfUiStatics.AppProvider.GetSpecialInstructionsForLogInPage();

            if (specialInstructions != null)
            {
                ph.AddControlsReturnThis(specialInstructions);
            }
            else
            {
                var unregisteredTable = EwfTable.Create(caption: "Unregistered users");
                unregisteredTable.AddItem(new EwfTableItem("If you have difficulty logging in, please " + FormsAuthStatics.SystemProvider.LogInHelpInstructions));
                ph.AddControlsReturnThis(unregisteredTable);
            }

            EwfUiStatics.SetContentFootActions(new ActionButtonSetup("Log In", new PostBackButton(logInPb)));

            var logInMethod = FormsAuthStatics.GetLogInMethod(
                this,
                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.",
                logInPb);

            logInPb.AddModificationMethod(() => user = logInMethod());
        }
        /// <summary>
        /// Call this during LoadData.
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="availableRoles">Pass a restricted list of <see cref="Role"/>s the user may select. Otherwise, Roles available
        /// in the System Provider are used.</param>
        public void LoadData(int?userId, List <Role> availableRoles = null)
        {
            availableRoles = (availableRoles?.OrderBy(r => r.Name) ?? UserManagementStatics.SystemProvider.GetRoles()).ToList();

            var user    = userId.HasValue ? UserManagementStatics.GetUser(userId.Value, true) : null;
            var facUser = includePasswordControls() && user != null?FormsAuthStatics.GetUser(user.UserId, true) : null;

            var b = FormItemList.CreateStack();

            b.AddFormItems(Email.ToEmailAddressControl(false, value: user != null ? user.Email : "").ToFormItem(label: "Email address".ToComponents()));

            if (includePasswordControls())
            {
                var group = new RadioButtonGroup(false);

                var keepPassword = group.CreateRadioButton(
                    true,
                    label: userId.HasValue ? "Keep the current password".ToComponents() : "Do not create a password".ToComponents(),
                    validationMethod: (postBackValue, validator) => {
                    if (!postBackValue.Value)
                    {
                        return;
                    }
                    if (user != null)
                    {
                        Salt.Value               = facUser.Salt;
                        SaltedPassword.Value     = facUser.SaltedPassword;
                        MustChangePassword.Value = facUser.MustChangePassword;
                    }
                    else
                    {
                        genPassword(false);
                    }
                })
                                   .ToFormItem();

                var generatePassword = group.CreateRadioButton(
                    false,
                    label: "Generate a {0} password and email it to the user".FormatWith(userId.HasValue ? "new, random" : "random").ToComponents(),
                    validationMethod: (postBackValue, validator) => {
                    if (postBackValue.Value)
                    {
                        genPassword(true);
                    }
                })
                                       .ToFormItem();

                var providePasswordSelected = new DataValue <bool>();
                var providePassword         = group.CreateFlowRadioButton(
                    false,
                    label: "Provide a {0}".FormatWith(userId.HasValue ? "new password" : "password").ToComponents(),
                    setup: FlowRadioButtonSetup.Create(
                        nestedContentGetter: () => {
                    return(FormState.ExecuteWithValidationPredicate(
                               () => providePasswordSelected.Value,
                               () => {
                        var password = new DataValue <string>();
                        var list = FormItemList.CreateStack(
                            generalSetup: new FormItemListSetup(classes: new ElementClass("newPassword")),
                            items: password.GetPasswordModificationFormItems());

                        new EwfValidation(
                            validator => {
                            var p = new Password(password.Value);
                            Salt.Value = p.Salt;
                            SaltedPassword.Value = p.ComputeSaltedHash();
                            MustChangePassword.Value = false;
                        });

                        return list.ToCollection();
                    }));
                }),
                    validationMethod: (postBackValue, validator) => providePasswordSelected.Value = postBackValue.Value)
                                              .ToFormItem();

                b.AddFormItems(
                    new StackList(keepPassword.ToListItem().ToCollection().Append(generatePassword.ToListItem()).Append(providePassword.ToListItem())).ToFormItem(
                        label: "Password".ToComponents()));
            }

            b.AddFormItems(
                RoleId.ToDropDown(
                    DropDownSetup.Create(from i in availableRoles select SelectListItem.Create(i.RoleId as int?, i.Name)),
                    value: new SpecifiedValue <int?>(user?.Role.RoleId))
                .ToFormItem(label: "Role".ToComponents()));

            this.AddControlsReturnThis(new Section("Security Information", b.ToCollection()).ToCollection().GetControls());
        }
Exemple #8
0
        /// <summary>
        /// Call this during LoadData.
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="availableRoles">Pass a restricted list of <see cref="Role"/>s the user may select. Otherwise, Roles available
        /// in the System Provider are used.</param>
        /// <param name="validationPredicate">If the function returns true, validation continues.</param>
        public void LoadData(int?userId, List <Role> availableRoles = null, Func <bool> validationPredicate = null)
        {
            availableRoles = (availableRoles != null ? availableRoles.OrderBy(r => r.Name) : UserManagementStatics.SystemProvider.GetRoles()).ToList();

            user = userId.HasValue ? UserManagementStatics.GetUser(userId.Value, true) : null;
            if (includePasswordControls() && user != null)
            {
                facUser = FormsAuthStatics.GetUser(user.UserId, true);
            }

            Func <bool> validationShouldRun = () => validationPredicate == null || validationPredicate();

            var b = FormItemBlock.CreateFormItemTable(heading: "Security Information");

            b.AddFormItems(
                FormItem.Create(
                    "Email address",
                    new EwfTextBox(user != null ? user.Email : ""),
                    validationGetter: control => new EwfValidation(
                        (pbv, validator) => {
                if (validationShouldRun())
                {
                    Email = validator.GetEmailAddress(new ValidationErrorHandler("email address"), control.GetPostBackValue(pbv), false);
                }
            })));

            if (includePasswordControls())
            {
                var group = new RadioButtonGroup(false);

                var keepPassword = FormItem.Create(
                    "",
                    group.CreateInlineRadioButton(true, label: userId.HasValue ? "Keep the current password" : "Do not create a password"),
                    validationGetter: control => new EwfValidation(
                        (pbv, validator) => {
                    if (!validationShouldRun() || !control.IsCheckedInPostBack(pbv))
                    {
                        return;
                    }
                    if (user != null)
                    {
                        Salt               = facUser.Salt;
                        SaltedPassword     = facUser.SaltedPassword;
                        MustChangePassword = facUser.MustChangePassword;
                    }
                    else
                    {
                        genPassword(false);
                    }
                }));

                var generatePassword = FormItem.Create(
                    "",
                    group.CreateInlineRadioButton(false, label: "Generate a " + (userId.HasValue ? "new, " : "") + "random password and email it to the user"),
                    validationGetter: control => new EwfValidation(
                        (pbv, validator) => {
                    if (validationShouldRun() && control.IsCheckedInPostBack(pbv))
                    {
                        genPassword(true);
                    }
                }));

                var providePassword = FormState.ExecuteWithValidationPredicate(
                    validationShouldRun,
                    () => {
                    var providePasswordSelected = new DataValue <bool>();
                    return(FormItem.Create(
                               "",
                               group.CreateBlockRadioButton(
                                   false,
                                   (postBackValue, validator) => providePasswordSelected.Value = postBackValue.Value,
                                   label: "Provide a {0}".FormatWith(userId.HasValue ? "new password" : "password"),
                                   nestedControlListGetter: () => {
                        return FormState.ExecuteWithValidationPredicate(
                            () => providePasswordSelected.Value,
                            () => {
                            var password = new DataValue <string>();
                            var newPasswordTable = EwfTable.Create(style: EwfTableStyle.StandardExceptLayout);
                            foreach (var i in password.GetPasswordModificationFormItems(textBoxWidth: Unit.Pixel(200)))
                            {
                                newPasswordTable.AddItem(new EwfTableItem(i.Label, i.ToControl(omitLabel: true)));
                            }

                            new EwfValidation(
                                validator => {
                                var p = new Password(password.Value);
                                Salt = p.Salt;
                                SaltedPassword = p.ComputeSaltedHash();
                                MustChangePassword = false;
                            });

                            return newPasswordTable.ToCollection();
                        });
                    }),
                               validationGetter: control => control.Validation));
                });

                b.AddFormItems(
                    FormItem.Create("Password", ControlStack.CreateWithControls(true, keepPassword.ToControl(), generatePassword.ToControl(), providePassword.ToControl())));
            }

            b.AddFormItems(
                FormItem.Create(
                    "Role",
                    SelectList.CreateDropDown(
                        from i in availableRoles select SelectListItem.Create(i.RoleId as int?, i.Name),
                        user != null ? user.Role.RoleId as int? : null),
                    validationGetter: control => new EwfValidation(
                        (pbv, validator) => {
                if (validationShouldRun())
                {
                    RoleId = control.ValidateAndGetSelectedItemIdInPostBack(pbv, validator) ?? default(int);
                }
            })));

            Controls.Add(b);
        }
 private void modifyData()
 {
     FormsAuthStatics.ResetAndSendPassword(info.UserId);
     AddStatusMessage(StatusMessageType.Info, "Your new password has been sent to your email address.");
 }
        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());
            }
        }