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 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);
            }));
        }
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;
            }));
        }
        private void addTag(DataValue <IReadOnlyCollection <int> > tagIds, DataValue <string> tagName)
        {
            var tagId = TagsTableRetrieval.GetAllRows().MatchingName(tagName.Value)?.TagId;

            if (!tagId.HasValue)
            {
                tagId = MainSequence.GetNextValue();
                TagsModification.InsertRow(tagId.Value, tagName.Value);
            }

            if (!tagIds.Value.Contains(tagId.Value))
            {
                tagIds.Value = tagIds.Value.Append(tagId.Value).Materialize();
            }
        }
Exemple #5
0
 void FormsAuthCapableUserManagementProvider.InsertOrUpdateUser(
     int?userId, string email, int roleId, Instant?lastRequestTime, int salt, byte[] saltedPassword, bool mustChangePassword)
 {
     if (userId.HasValue)
     {
         var userMod = UsersModification.CreateForUpdate(new UsersTableEqualityConditions.UserId(userId.Value));
         userMod.EmailAddress   = email;
         userMod.Salt           = salt;
         userMod.SaltedPassword = saltedPassword;
         userMod.Execute();
     }
     else
     {
         UsersModification.InsertRow(MainSequence.GetNextValue(), "", email, "", email, salt, saltedPassword);
     }
 }