protected override PageContent getContent()
        {
            if (Password.Any())
            {
                return(new UiPageContent(
                           pageLoadPostBack: PostBack.CreateFull(
                               modificationMethod: () => logIn(HideWarnings),
                               actionGetter: () => new PostBackAction(new ExternalResource(ReturnUrl)))).Add(new Paragraph("Please wait.".ToComponents())));
            }

            return(FormState.ExecuteWithDataModificationsAndDefaultAction(
                       PostBack.CreateFull(modificationMethod: () => logIn(false), actionGetter: () => new PostBackAction(new ExternalResource(ReturnUrl)))
                       .ToCollection(),
                       () => new UiPageContent(contentFootActions: new ButtonSetup("Log In").ToCollection()).Add(
                           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 System Manager 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()))));
        }
Пример #2
0
        private static IReadOnlyCollection <FlowComponent> getRow(MergeRow row, MergeFieldNameTree fieldNameTree, bool useSubtractiveMode)
        {
            var valueFormItems = (useSubtractiveMode
                                                       ? row.Values.Where(mergeValue => fieldNameTree?.FieldNames.All(i => i != mergeValue.Name) ?? false)
                                                       : fieldNameTree?.FieldNames.Select(fieldName => row.Values.Single(i => i.Name == fieldName)) ?? row.Values).Select(
                mergeValue => {
                IReadOnlyCollection <PhrasingComponent> value = null;
                if (mergeValue is MergeValue <string> stringValue)
                {
                    value = stringValue.Evaluate(false).ToComponents();
                }

                // Use ApplicationException instead of MailMergingException because the field names can easily be validated before this method is called.
                return(value == null
                                                               ? throw new ApplicationException("Merge field {0} evaluates to an unsupported type.".FormatWith(mergeValue.Name))
                                                               : value.ToFormItem(label: mergeValue.Name.ToComponents()));
            })
                                 .Materialize();
            var valueList = valueFormItems.Any()
                                                ? FormItemList.CreateGrid(2, items: valueFormItems).ToCollection()
                                                : Enumerable.Empty <FlowComponent>().Materialize();

            var children = (useSubtractiveMode
                                                 ? row.Children.Select(
                                childRowTree => {
                MergeFieldNameTree childFieldNameTree = null;
                if (fieldNameTree != null)
                {
                    var childNameAndFieldNameTree = fieldNameTree.ChildNamesAndChildren.SingleOrDefault(i => i.Item1 == childRowTree.NodeName);
                    childFieldNameTree = childNameAndFieldNameTree != null
                                                                                                              ? childNameAndFieldNameTree.Item2
                                                                                                              : new MergeFieldNameTree(Enumerable.Empty <string>());
                }
                return(new { rowTree = childRowTree, fieldNameTree = childFieldNameTree });
            })
                            .Where(i => i.fieldNameTree != null)
                                                 : fieldNameTree?.ChildNamesAndChildren.Select(
                                childNameAndFieldNameTree => new
            {
                rowTree = row.Children.Single(i => i.NodeName == childNameAndFieldNameTree.Item1),
                fieldNameTree = childNameAndFieldNameTree.Item2
            }) ?? row.Children.Select(childRowTree => new { rowTree = childRowTree, fieldNameTree = (MergeFieldNameTree)null }))
                           .Where(child => child.rowTree.Rows.Any())
                           .Select(
                child => new Section(
                    child.rowTree.NodeName,
                    new StackList(child.rowTree.Rows.Select(i => getRow(i, child.fieldNameTree, useSubtractiveMode).ToComponentListItem())).ToCollection()))
                           .Materialize();

            return(children.Any() ? valueList.Append(new GenericFlowContainer(children, classes: rowTreeChildClass)).Materialize() : valueList);
        }
        protected override PageContent getContent()
        {
            var body = new DataValue <string>();

            return(FormState.ExecuteWithDataModificationsAndDefaultAction(
                       PostBack.CreateFull(
                           modificationMethod: () => {
                var message = new EmailMessage
                {
                    Subject = "Support request from {0} in {1}".FormatWith(
                        AppTools.User.FriendlyName.Any() ? AppTools.User.FriendlyName : AppTools.User.Email,
                        ConfigurationStatics.SystemDisplayName),
                    BodyHtml = body.Value.GetTextAsEncodedHtml()
                };
                message.ReplyToAddresses.Add(new EmailAddress(AppTools.User.Email, AppTools.User.FriendlyName));
                message.ToAddresses.AddRange(EmailStatics.GetAdministratorEmailAddresses());
                EmailStatics.SendEmailWithDefaultFromAddress(message);
                AddStatusMessage(StatusMessageType.Info, "Your message has been sent.");
            },
                           actionGetter: () => new PostBackAction(new ExternalResource(ReturnUrl)))
                       .ToCollection(),
                       () => new UiPageContent(contentFootActions: new ButtonSetup("Send Message").ToCollection())
                       .Add(new Paragraph("You may report any problems, make suggestions, or ask for help here.".ToComponents()))
                       .Add(
                           FormItemList.CreateStack(
                               items: new EmailAddress(AppTools.User.Email, AppTools.User.FriendlyName).ToMailAddress()
                               .ToString()
                               .ToComponents()
                               .ToFormItem(label: "From".ToComponents())
                               .Append(
                                   "{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()))
                               .Append(
                                   body.ToTextControl(false, setup: TextControlSetup.Create(numberOfRows: 10), value: "").ToFormItem(label: "Message".ToComponents()))
                               .Materialize()))));
        }