コード例 #1
0
ファイル: PostService.cs プロジェクト: keepbreath/CoreForum
        /// <inheritdoc />
        public async Task <IPipelineProcess <Post> > Edit(Post post, HttpPostedFileBase[] files, bool isTopicStarter, string postedTopicName, string postedContent)
        {
            // Get the pipelines
            var postCreatePipes = ForumConfiguration.Instance.PipelinesPostUpdate;

            // Set the post to topic starter
            post.IsTopicStarter = isTopicStarter;

            // The model to process
            var piplineModel = new PipelineProcess <Post>(post);

            // Add the files for the post
            piplineModel.ExtendedData.Add(Constants.ExtendedDataKeys.PostedFiles, files);
            piplineModel.ExtendedData.Add(Constants.ExtendedDataKeys.Name, postedTopicName);
            piplineModel.ExtendedData.Add(Constants.ExtendedDataKeys.Content, postedContent);
            piplineModel.ExtendedData.Add(Constants.ExtendedDataKeys.Username, HttpContext.Current.User.Identity.Name);

            // Get instance of the pipeline to use
            var pipeline = new Pipeline <IPipelineProcess <Post>, Post>(_context);

            // Register the pipes
            var allPostPipes = ImplementationManager.GetInstances <IPipe <IPipelineProcess <Post> > >();

            // Loop through the pipes and add the ones we want
            foreach (var pipe in postCreatePipes)
            {
                if (allPostPipes.ContainsKey(pipe))
                {
                    pipeline.Register(allPostPipes[pipe]);
                }
            }

            // Process the pipeline
            return(await pipeline.Process(piplineModel));
        }
コード例 #2
0
        /// <summary>
        ///     Scrubs a user, removes everything from points to posts and topics.
        /// </summary>
        /// <param name="user"></param>
        public async Task <IPipelineProcess <MembershipUser> > ScrubUsers(MembershipUser user)
        {
            // Get the pipelines
            var pipes = ForumConfiguration.Instance.PipelinesUserScrub;

            // The model to process
            var piplineModel = new PipelineProcess <MembershipUser>(user);

            // Get instance of the pipeline to use
            var pipeline = new Pipeline <IPipelineProcess <MembershipUser>, MembershipUser>(_context);

            // Register the pipes
            var allMembershipUserPipes = ImplementationManager.GetInstances <IPipe <IPipelineProcess <MembershipUser> > >();

            // Loop through the pipes and add the ones we want
            foreach (var pipe in pipes)
            {
                if (allMembershipUserPipes.ContainsKey(pipe))
                {
                    pipeline.Register(allMembershipUserPipes[pipe]);
                }
            }

            // Process the pipeline
            return(await pipeline.Process(piplineModel));
        }
コード例 #3
0
ファイル: PostService.cs プロジェクト: keepbreath/CoreForum
        /// <summary>
        /// Delete a post
        /// </summary>
        /// <param name="post"></param>
        /// <param name="ignoreLastPost"></param>
        /// <returns>Returns true if can delete</returns>
        public async Task <IPipelineProcess <Post> > Delete(Post post, bool ignoreLastPost)
        {
            // Get the pipelines
            var postPipes = ForumConfiguration.Instance.PipelinesPostDelete;

            // The model to process
            var piplineModel = new PipelineProcess <Post>(post);

            // Add extended data
            piplineModel.ExtendedData.Add(Constants.ExtendedDataKeys.IgnoreLastPost, ignoreLastPost);
            piplineModel.ExtendedData.Add(Constants.ExtendedDataKeys.Username, HttpContext.Current.User.Identity.Name);

            // Get instance of the pipeline to use
            var pipeline = new Pipeline <IPipelineProcess <Post>, Post>(_context);

            // Register the pipes
            var allPostPipes = ImplementationManager.GetInstances <IPipe <IPipelineProcess <Post> > >();

            // Loop through the pipes and add the ones we want
            foreach (var pipe in postPipes)
            {
                if (allPostPipes.ContainsKey(pipe))
                {
                    pipeline.Register(allPostPipes[pipe]);
                }
            }

            return(await pipeline.Process(piplineModel));
        }
コード例 #4
0
ファイル: CategoryService.cs プロジェクト: zhyqhb/mvcforum
        /// <summary>
        ///     Delete a category
        /// </summary>
        /// <param name="category"></param>
        public async Task <IPipelineProcess <Category> > Delete(Category category)
        {
            // Get the pipelines
            var categoryPipes = ForumConfiguration.Instance.PipelinesCategoryDelete;

            // The model to process
            var piplineModel = new PipelineProcess <Category>(category);

            // Get instance of the pipeline to use
            var pipeline = new Pipeline <IPipelineProcess <Category>, Category>(_context);

            // Register the pipes
            var allCategoryPipes = ImplementationManager.GetInstances <IPipe <IPipelineProcess <Category> > >();

            // Loop through the pipes and add the ones we want
            foreach (var pipe in categoryPipes)
            {
                if (allCategoryPipes.ContainsKey(pipe))
                {
                    pipeline.Register(allCategoryPipes[pipe]);
                }
            }

            return(await pipeline.Process(piplineModel));
        }
コード例 #5
0
        /// <summary>
        ///     Create new user
        /// </summary>
        /// <param name="newUser"></param>
        /// <param name="loginType"></param>
        /// <returns></returns>
        public async Task <IPipelineProcess <MembershipUser> > CreateUser(MembershipUser newUser, LoginType loginType)
        {
            // Get the site settings
            var settings = _settingsService.GetSettings(false);

            // Santise the user fields
            newUser = SanitizeUser(newUser);

            // Hash the password
            var salt = StringUtils.CreateSalt(Constants.SaltSize);
            var hash = StringUtils.GenerateSaltedHash(newUser.Password, salt);

            newUser.Password     = hash;
            newUser.PasswordSalt = salt;

            // Add the roles
            newUser.Roles = new List <MembershipRole> {
                settings.NewMemberStartingRole
            };

            // Set dates
            newUser.CreateDate      = newUser.LastPasswordChangedDate = DateTime.UtcNow;
            newUser.LastLockoutDate = (DateTime)SqlDateTime.MinValue;
            newUser.LastLoginDate   = DateTime.UtcNow;
            newUser.IsLockedOut     = false;
            newUser.Slug            = ServiceHelpers.GenerateSlug(newUser.UserName,
                                                                  GetUserBySlugLike(ServiceHelpers.CreateUrl(newUser.UserName)).Select(x => x.Slug).ToList(), null);

            // Get the pipelines
            var userCreatePipes = ForumConfiguration.Instance.PipelinesUserCreate;

            // The model to process
            var piplineModel = new PipelineProcess <MembershipUser>(newUser);

            // Add the login type to
            piplineModel.ExtendedData.Add(Constants.ExtendedDataKeys.LoginType, loginType);

            // Get instance of the pipeline to use
            var createUserPipeline = new Pipeline <IPipelineProcess <MembershipUser>, MembershipUser>(_context);

            // Register the pipes
            var allMembershipUserPipes = ImplementationManager.GetInstances <IPipe <IPipelineProcess <MembershipUser> > >();

            // Loop through the pipes and add the ones we want
            foreach (var pipe in userCreatePipes)
            {
                if (allMembershipUserPipes.ContainsKey(pipe))
                {
                    createUserPipeline.Register(allMembershipUserPipes[pipe]);
                }
            }

            // Process the pipeline
            return(await createUserPipeline.Process(piplineModel));
        }
コード例 #6
0
        /// <summary>
        /// Create a new topic and also the topic starter post
        /// </summary>
        /// <param name="topic"></param>
        /// <param name="files"></param>
        /// <param name="tags"></param>
        /// <param name="subscribe"></param>
        /// <param name="postContent"></param>
        /// <param name="post">Optional Post: Used for moving a existing post into a new topic</param>
        /// <returns></returns>
        public async Task <IPipelineProcess <Topic> > Create(Topic topic, HttpPostedFileBase[] files, string tags, bool subscribe, string postContent, Post post)
        {
            // url slug generator
            topic.Slug = ServiceHelpers.GenerateSlug(topic.Name,
                                                     GetTopicBySlugLike(ServiceHelpers.CreateUrl(topic.Name))
                                                     .Select(x => x.Slug).ToList(), null);

            // Get the pipelines
            var topicCreatePipes = ForumConfiguration.Instance.PipelinesTopicCreate;

            // The model to process
            var piplineModel = new PipelineProcess <Topic>(topic);

            // See if we have any files
            if (files != null && files.Any(x => x != null))
            {
                piplineModel.ExtendedData.Add(Constants.ExtendedDataKeys.PostedFiles, files);
            }

            // See if we have any tags
            if (!string.IsNullOrWhiteSpace(tags))
            {
                piplineModel.ExtendedData.Add(Constants.ExtendedDataKeys.Tags, tags);
            }

            // See if we have a post
            if (post != null)
            {
                piplineModel.ExtendedData.Add(Constants.ExtendedDataKeys.Post, post);
            }

            // Add the extended data we need
            piplineModel.ExtendedData.Add(Constants.ExtendedDataKeys.Subscribe, subscribe);
            piplineModel.ExtendedData.Add(Constants.ExtendedDataKeys.IsEdit, false);
            piplineModel.ExtendedData.Add(Constants.ExtendedDataKeys.Content, postContent);
            piplineModel.ExtendedData.Add(Constants.ExtendedDataKeys.Username, HttpContext.Current.User.Identity.Name);

            // Get instance of the pipeline to use
            var pipeline = new Pipeline <IPipelineProcess <Topic>, Topic>(_context);

            // Register the pipes
            var allTopicPipes = ImplementationManager.GetInstances <IPipe <IPipelineProcess <Topic> > >();

            // Loop through the pipes and add the ones we want
            foreach (var pipe in topicCreatePipes)
            {
                if (allTopicPipes.ContainsKey(pipe))
                {
                    pipeline.Register(allTopicPipes[pipe]);
                }
            }

            // Process the pipeline
            return(await pipeline.Process(piplineModel));
        }
コード例 #7
0
ファイル: CategoryService.cs プロジェクト: zhyqhb/mvcforum
        /// <inheritdoc />
        public async Task <IPipelineProcess <Category> > Edit(Category category, HttpPostedFileBase[] postedFiles, Guid?parentCategory, Guid?section)
        {
            // Get the pipelines
            var categoryPipes = ForumConfiguration.Instance.PipelinesCategoryUpdate;

            // The model to process
            var piplineModel = new PipelineProcess <Category>(category);

            // Add parent category
            if (parentCategory != null)
            {
                piplineModel.ExtendedData.Add(Constants.ExtendedDataKeys.ParentCategory, parentCategory);
            }

            // Add section
            if (section != null)
            {
                piplineModel.ExtendedData.Add(Constants.ExtendedDataKeys.Section, section);
            }

            // Add posted files
            if (postedFiles != null && postedFiles.Any(x => x != null))
            {
                piplineModel.ExtendedData.Add(Constants.ExtendedDataKeys.PostedFiles, postedFiles);
            }

            piplineModel.ExtendedData.Add(Constants.ExtendedDataKeys.Username, HttpContext.Current.User.Identity.Name);
            piplineModel.ExtendedData.Add(Constants.ExtendedDataKeys.IsEdit, true);

            // Get instance of the pipeline to use
            var pipeline = new Pipeline <IPipelineProcess <Category>, Category>(_context);

            // Register the pipes
            var allCategoryPipes = ImplementationManager.GetInstances <IPipe <IPipelineProcess <Category> > >();

            // Loop through the pipes and add the ones we want
            foreach (var pipe in categoryPipes)
            {
                if (allCategoryPipes.ContainsKey(pipe))
                {
                    pipeline.Register(allCategoryPipes[pipe]);
                }
            }

            return(await pipeline.Process(piplineModel));
        }
コード例 #8
0
ファイル: PostService.cs プロジェクト: nhsengland/futurenhs
        /// <summary>
        /// Create a new post
        /// </summary>
        /// <param name="post"></param>
        /// <param name="files"></param>
        /// <param name="isTopicStarter"></param>
        /// <param name="replyTo"></param>
        /// <returns></returns>
        public async Task <IPipelineProcess <Post> > Create(Post post, HttpPostedFileBase[] files, bool isTopicStarter,
                                                            Guid?replyTo)
        {
            // Get the pipelines
            var postCreatePipes = ForumConfiguration.Instance.PipelinesPostCreate;

            // Set the post to topic starter
            post.IsTopicStarter = isTopicStarter;

            // If this is a reply to someone
            if (replyTo != null)
            {
                var replyingTo = Get((Guid)replyTo);
                post.InReplyTo = replyTo;
                post.ThreadId  = replyingTo.ThreadId != null ? replyingTo.ThreadId : post.InReplyTo;
            }

            // The model to process
            var piplineModel = new PipelineProcess <Post>(post);

            // Add the files for the post
            if (files != null)
            {
                piplineModel.ExtendedData.Add(Constants.ExtendedDataKeys.PostedFiles, files);
            }

            piplineModel.ExtendedData.Add(Constants.ExtendedDataKeys.Username, HttpContext.Current.User.Identity.Name);

            // Get instance of the pipeline to use
            var pipeline = new Pipeline <IPipelineProcess <Post>, Post>(_context);

            // Register the pipes
            var allPostPipes = ImplementationManager.GetInstances <IPipe <IPipelineProcess <Post> > >();

            // Loop through the pipes and add the ones we want
            foreach (var pipe in postCreatePipes)
            {
                if (allPostPipes.ContainsKey(pipe))
                {
                    pipeline.Register(allPostPipes[pipe]);
                }
            }

            // Process the pipeline
            return(await pipeline.Process(piplineModel));
        }
コード例 #9
0
        /// <inheritdoc />
        public async Task <IPipelineProcess <Topic> > Edit(Topic topic, HttpPostedFileBase[] files, string tags, bool subscribe,
                                                           string postContent, string topicName, List <PollAnswer> pollAnswers, int closePollAfterDays)
        {
            // url slug generator
            topic.Slug = ServiceHelpers.GenerateSlug(topic.Name,
                                                     GetTopicBySlugLike(ServiceHelpers.CreateUrl(topic.Name))
                                                     .Select(x => x.Slug).ToList(), null);

            // Get the pipelines
            var topicPipes = ForumConfiguration.Instance.PipelinesTopicUpdate;

            // The model to process
            var piplineModel = new PipelineProcess <Topic>(topic);

            // Add the extended data we need
            piplineModel.ExtendedData.Add(Constants.ExtendedDataKeys.Subscribe, subscribe);
            piplineModel.ExtendedData.Add(Constants.ExtendedDataKeys.PostedFiles, files);
            piplineModel.ExtendedData.Add(Constants.ExtendedDataKeys.Tags, tags);
            piplineModel.ExtendedData.Add(Constants.ExtendedDataKeys.IsEdit, true);
            piplineModel.ExtendedData.Add(Constants.ExtendedDataKeys.Content, postContent);
            piplineModel.ExtendedData.Add(Constants.ExtendedDataKeys.PollNewAnswers, pollAnswers);
            piplineModel.ExtendedData.Add(Constants.ExtendedDataKeys.PollCloseAfterDays, closePollAfterDays);
            piplineModel.ExtendedData.Add(Constants.ExtendedDataKeys.Name, topicName);
            piplineModel.ExtendedData.Add(Constants.ExtendedDataKeys.Username, HttpContext.Current.User.Identity.Name);

            // Get instance of the pipeline to use
            var pipeline = new Pipeline <IPipelineProcess <Topic>, Topic>(_context);

            // Register the pipes
            var allTopicPipes = ImplementationManager.GetInstances <IPipe <IPipelineProcess <Topic> > >();

            // Loop through the pipes and add the ones we want
            foreach (var pipe in topicPipes)
            {
                if (allTopicPipes.ContainsKey(pipe))
                {
                    pipeline.Register(allTopicPipes[pipe]);
                }
            }

            // Process the pipeline
            return(await pipeline.Process(piplineModel));
        }
コード例 #10
0
ファイル: PostService.cs プロジェクト: nhsengland/futurenhs
        /// <inheritdoc />
        public async Task <IPipelineProcess <Post> > Move(Post post, Guid?newTopicId, string newTopicTitle,
                                                          bool moveReplyToPosts)
        {
            // Get the pipelines
            var postPipes = ForumConfiguration.Instance.PipelinesPostMove;

            // The model to process
            var piplineModel = new PipelineProcess <Post>(post);

            // Add the files for the post
            if (newTopicId != null)
            {
                piplineModel.ExtendedData.Add(Constants.ExtendedDataKeys.TopicId, newTopicId);
            }

            if (!string.IsNullOrWhiteSpace(newTopicTitle))
            {
                piplineModel.ExtendedData.Add(Constants.ExtendedDataKeys.Name, newTopicTitle);
            }

            piplineModel.ExtendedData.Add(Constants.ExtendedDataKeys.MovePosts, moveReplyToPosts);
            piplineModel.ExtendedData.Add(Constants.ExtendedDataKeys.Username, HttpContext.Current.User.Identity.Name);

            // Get instance of the pipeline to use
            var pipeline = new Pipeline <IPipelineProcess <Post>, Post>(_context);

            // Register the pipes
            var allPostPipes = ImplementationManager.GetInstances <IPipe <IPipelineProcess <Post> > >();

            // Loop through the pipes and add the ones we want
            foreach (var pipe in postPipes)
            {
                if (allPostPipes.ContainsKey(pipe))
                {
                    pipeline.Register(allPostPipes[pipe]);
                }
            }

            // Process the pipeline
            return(await pipeline.Process(piplineModel));
        }
コード例 #11
0
        /// <inheritdoc />
        public async Task <IPipelineProcess <MembershipUser> > EditUserAsync(MembershipUser userToEdit, IPrincipal loggedInUser,
                                                                             HttpPostedFileBase image, bool removeImage = false, CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();

            // Get the pipelines
            var pipes = ForumConfiguration.Instance.PipelinesUserUpdate;

            // The model to process
            var pipelineModel = new PipelineProcess <MembershipUser>(userToEdit);

            // Add the user object
            pipelineModel.ExtendedData.Add(Constants.ExtendedDataKeys.Username, loggedInUser.Identity.Name);

            // Add the file to the extended data
            if (image != null)
            {
                pipelineModel.ExtendedData.Add(Constants.ExtendedDataKeys.PostedFiles, image);
            }

            // Get instance of the pipeline to use
            var pipeline = new Pipeline <IPipelineProcess <MembershipUser>, MembershipUser>(_context);

            // Register the pipes
            var allMembershipUserPipes = ImplementationManager.GetInstances <IPipe <IPipelineProcess <MembershipUser> > >();

            // Loop through the pipes and add the ones we want
            foreach (var pipe in pipes)
            {
                if (allMembershipUserPipes.ContainsKey(pipe))
                {
                    pipeline.Register(allMembershipUserPipes[pipe]);
                }
            }

            // Process the pipeline
            return(await pipeline.Process(pipelineModel));
        }
コード例 #12
0
        /// <inheritdoc />
        public async Task <IPipelineProcess <MembershipUser> > EditUser(MembershipUser userToEdit, IPrincipal loggedInUser, Image image)
        {
            // Get the pipelines
            var pipes = ForumConfiguration.Instance.PipelinesUserUpdate;

            // The model to process
            var piplineModel = new PipelineProcess <MembershipUser>(userToEdit);

            // Add the user object
            piplineModel.ExtendedData.Add(Constants.ExtendedDataKeys.Username, loggedInUser.Identity.Name);

            // Add the Image as a base 64 image so we can grab it back out
            if (image != null)
            {
                piplineModel.ExtendedData.Add(Constants.ExtendedDataKeys.ImageBase64, image.ImageToBase64());
                image.Dispose();
            }

            // Get instance of the pipeline to use
            var pipeline = new Pipeline <IPipelineProcess <MembershipUser>, MembershipUser>(_context);

            // Register the pipes
            var allMembershipUserPipes = ImplementationManager.GetInstances <IPipe <IPipelineProcess <MembershipUser> > >();

            // Loop through the pipes and add the ones we want
            foreach (var pipe in pipes)
            {
                if (allMembershipUserPipes.ContainsKey(pipe))
                {
                    pipeline.Register(allMembershipUserPipes[pipe]);
                }
            }

            // Process the pipeline
            return(await pipeline.Process(piplineModel));
        }
コード例 #13
0
        public virtual async Task <ActionResult> LogOnAsync(LogOnViewModel model, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (ModelState.IsValid)
            {
                var message = new GenericMessageViewModel();
                var user    = MembershipService.CreateEmptyUser();

                // Get the pipelines
                var userLoginPipes = ForumConfiguration.Instance.PipelinesUserLogin;

                // The model to process
                var piplineModel = new PipelineProcess <MembershipUser>(user);

                // Add the username and password
                piplineModel.ExtendedData.Add(Constants.ExtendedDataKeys.Username, model.UserName);
                piplineModel.ExtendedData.Add(Constants.ExtendedDataKeys.Password, model.Password);

                // Get instance of the pipeline to use
                var loginUserPipeline = new Pipeline <IPipelineProcess <MembershipUser>, MembershipUser>(Context);

                // Register the pipes
                var allMembershipUserPipes =
                    ImplementationManager.GetInstances <IPipe <IPipelineProcess <MembershipUser> > >();

                // Loop through the pipes and add the ones we want
                foreach (var pipe in userLoginPipes)
                {
                    if (allMembershipUserPipes.ContainsKey(pipe))
                    {
                        loginUserPipeline.Register(allMembershipUserPipes[pipe]);
                    }
                }

                // Process the pipeline
                var loginResult = await loginUserPipeline.Process(piplineModel);

                // See if it was successful
                if (loginResult.Successful)
                {
                    // Save outstanding Changes
                    Context.SaveChanges();

                    // Login the user
                    FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);

                    // Set the message
                    message.Message     = LocalizationService.GetResourceString("Members.NowLoggedIn");
                    message.MessageType = GenericMessages.success;



                    // See if we have a return url
                    if (!string.IsNullOrWhiteSpace(model.ReturnUrl))
                    {
                        return(Redirect(Request["ReturnUrl"]));
                    }

                    // If not just go to home page
                    return(Redirect(_configurationProvider.ApplicationGatewayFqdn));
                }

                // Add the error if we get here
                ModelState.AddModelError(string.Empty, loginResult.ProcessLog.FirstOrDefault());
            }

            return(View(model));
        }