private IReadOnlyCollection <Func <string, FormItem> > getIndependentControls() => new Func <string, FormItem>[] { id => { var pb = PostBack.CreateFull(id: id); return(FormState.ExecuteWithDataModificationsAndDefaultAction(pb.ToCollection(), () => get("Standard", null)(id))); }, id => { var pb = PostBack.CreateFull(id: id); return(FormState.ExecuteWithDataModificationsAndDefaultAction( pb.ToCollection(), () => get( "Auto-complete, triggers action when item selected", TextControlSetup.CreateAutoComplete(TestService.GetInfo(), triggersActionWhenItemSelected: true))(id))); }, id => { var pb = PostBack.CreateFull(id: id); return(FormState.ExecuteWithDataModificationsAndDefaultAction( pb.ToCollection(), () => get( "Auto-complete, triggers action when item selected or value changed", TextControlSetup.CreateAutoComplete( TestService.GetInfo(), triggersActionWhenItemSelected: true, valueChangedAction: new PostBackFormAction(pb)))(id))); } };
protected override void loadData() { var staticFil = FormItemList.CreateStack(generalSetup: new FormItemListSetup(buttonSetup: new ButtonSetup("Submit"))); staticFil.AddFormItems( new TextControl("Values here will be retained across post-backs", true).ToFormItem(label: "Static Field".ToComponents()), new TextControl("", true).ToFormItem(label: "Static Field".ToComponents()), new TextControl( "Edit this one to get a validation error", true, setup: TextControlSetup.Create(validationPredicate: valueChangedOnPostBack => valueChangedOnPostBack), validationMethod: (postBackValue, validator) => validator.NoteErrorAndAddMessage("You can't change the value in this box!")).ToFormItem( label: "Static Field".ToComponents())); ph.AddControlsReturnThis(staticFil.ToCollection().GetControls()); ph.AddControlsReturnThis(getBasicRegionComponents().GetControls()); var listTable = EwfTable.Create( style: EwfTableStyle.StandardLayoutOnly, fields: new[] { 10, 1, 10 }.Select(i => new EwfTableField(size: i.ToPercentage())).Materialize()); listTable.AddItem( EwfTableItem.Create( EwfTableItemSetup.Create(verticalAlignment: TableCellVerticalAlignment.Top), getNonIdListRegionComponents().ToCell(), "".ToCell(), getIdListRegionComponents().ToCell())); ph.AddControlsReturnThis(listTable.ToCollection().GetControls()); }
// 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 }); }
private IReadOnlyCollection <FlowComponent> getNewCommentComponents(UpdateRegionSet createUpdateRegions) { if (AppTools.User == null) { return(new Paragraph( new EwfHyperlink( EnterpriseWebLibrary.EnterpriseWebFramework.UserManagement.Pages.LogIn.GetInfo(Home.GetInfo().GetUrl()), new StandardHyperlinkStyle("Sign in")).Concat(" or ".ToComponents()) .Append(new EwfHyperlink(User.GetInfo(), new StandardHyperlinkStyle("sign up"))) .Concat(" to add comments on this article.".ToComponents()) .Materialize()).ToCollection()); } commentMod = getCommentMod(); return(FormState.ExecuteWithDataModificationsAndDefaultAction( PostBack.CreateIntermediate( createUpdateRegions.ToCollection(), id: "comment", modificationMethod: () => { commentMod.CommentId = MainSequence.GetNextValue(); commentMod.Execute(); }) .ToCollection(), () => new FlowIdContainer( commentMod.GetBodyTextTextControlFormItem( false, label: Enumerable.Empty <PhrasingComponent>().Materialize(), controlSetup: TextControlSetup.Create(numberOfRows: 3, placeholder: "Write a comment..."), value: "") .ToComponentCollection() .Append(new EwfButton(new StandardButtonStyle("Post Comment"))), updateRegionSets: createUpdateRegions.ToCollection()).ToCollection())); }
protected override void loadData() { ph.AddControlsReturnThis(new LegacyParagraph("You may report any problems, make suggestions, or ask for help here.")); FormState.ExecuteWithDataModificationsAndDefaultAction( PostBack.CreateFull(firstModificationMethod: modifyData, actionGetter: () => new PostBackAction(new ExternalResourceInfo(info.ReturnUrl))) .ToCollection(), () => { var list = FormItemList.CreateStack(); list.AddFormItems( new EmailAddress(AppTools.User.Email, AppTools.User.FriendlyName).ToMailAddress() .ToString() .ToComponents() .ToFormItem(label: "From".ToComponents()), "{0} ({1} for this system)".FormatWith( StringTools.GetEnglishListPhrase(EmailStatics.GetAdministratorEmailAddresses().Select(i => i.DisplayName), true), "support contacts".ToQuantity(EmailStatics.GetAdministratorEmailAddresses().Count(), showQuantityAs: ShowQuantityAs.None)) .ToComponents() .ToFormItem(label: "To".ToComponents()), body.ToTextControl(false, setup: TextControlSetup.Create(numberOfRows: 10), value: "").ToFormItem(label: "Message".ToComponents())); ph.AddControlsReturnThis(list.ToCollection().GetControls()); EwfUiStatics.SetContentFootActions(new ButtonSetup("Send Message").ToCollection()); }); }
private Func <string, FormItem> get(string label, TextControlSetup setup, int?maxLength = null) => id => new TextControl( "", true, setup: setup, maxLength: maxLength, validationMethod: (postBackValue, validator) => AddStatusMessage(StatusMessageType.Info, "{0}: {1}".FormatWith(id, postBackValue))).ToFormItem( label: "{0}. {1}".FormatWith(id, label).ToComponents());
protected override PageContent getContent() { var mod = getMod(); var tagIds = ComponentStateItem.Create( "tags", ArticleId.HasValue ? ArticleTagsTableRetrieval.GetRowsLinkedToArticle(ArticleId.Value).Select(i => i.TagId).Materialize() : Enumerable.Empty <int>().Materialize(), v => v.All(id => TagsTableRetrieval.GetRowMatchingId(id, returnNullIfNoMatch: true) != null), true); return(FormState.ExecuteWithDataModificationsAndDefaultAction( PostBack.CreateFull( modificationMethod: () => { if (!ArticleId.HasValue) { mod.ArticleId = MainSequence.GetNextValue(); mod.Slug = getSuffixedSlug(mod.Title.ToUrlSlug()); mod.CreationDateAndTime = DateTime.UtcNow; } mod.Execute(); if (ArticleId.HasValue) { ArticleTagsModification.DeleteRows(new ArticleTagsTableEqualityConditions.ArticleId(ArticleId.Value)); } foreach (var i in tagIds.Value.Value) { ArticleTagsModification.InsertRow(mod.ArticleId, i); } }, actionGetter: () => new PostBackAction(Article.GetInfo(mod.ArticleId))) .ToCollection(), () => { var stack = FormItemList.CreateStack(generalSetup: new FormItemListSetup(etherealContent: tagIds.ToCollection())); stack.AddItems( mod.GetTitleTextControlFormItem(false, label: "Article title".ToComponents(), value: ArticleId.HasValue ? null : "") .Append( mod.GetDescriptionTextControlFormItem(false, label: "What's this article about?".ToComponents(), value: ArticleId.HasValue ? null : "")) .Append( mod.GetBodyMarkdownTextControlFormItem( false, label: "Write your article (in markdown)".ToComponents(), controlSetup: TextControlSetup.Create(numberOfRows: 8), value: ArticleId.HasValue ? null : "")) .Append(getTagFormItem(tagIds.Value)) .Materialize()); return new UiPageContent(contentFootActions: new ButtonSetup("Publish Article").ToCollection()).Add(stack); })); }
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()); }); }
// 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 }); }
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))); } };
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)); }
private FlowComponent getFormItemStack(UsersModification mod, DataValue <string> password) { var stack = FormItemList.CreateStack(); if (AppTools.User != null) { stack.AddItem(mod.GetProfilePictureUrlUrlControlFormItem(true, label: "URL of profile picture".ToComponents())); } stack.AddItem(mod.GetUsernameTextControlFormItem(false, label: "Username".ToComponents(), value: AppTools.User == null ? "" : null)); if (AppTools.User != null) { stack.AddItem( mod.GetShortBioTextControlFormItem(true, label: "Short bio about you".ToComponents(), controlSetup: TextControlSetup.Create(numberOfRows: 8))); } stack.AddItem(mod.GetEmailAddressEmailAddressControlFormItem(false, label: "Email".ToComponents(), value: AppTools.User == null ? "" : null)); if (AppTools.User == null) { stack.AddItems(password.GetPasswordModificationFormItems()); } else { var changePasswordChecked = new DataValue <bool>(); stack.AddItem( changePasswordChecked.ToFlowCheckbox( "Change password".ToComponents(), setup: FlowCheckboxSetup.Create( nestedContentGetter: () => FormState.ExecuteWithValidationPredicate( () => changePasswordChecked.Value, () => FormItemList.CreateGrid(1, items: password.GetPasswordModificationFormItems()).ToCollection())), value: false) .ToFormItem()); } return(stack); }
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()); } }