Exemple #1
0
        public virtual async Task <ActionResult> CreatePost(CreateAjaxPostViewModel post)
        {
            var topic             = _topicService.Get(post.Topic);
            var loggedOnUser      = User.GetMembershipUser(MembershipService, false);
            var loggedOnUsersRole = loggedOnUser.GetRole(RoleService);
            var permissions       = RoleService.GetPermissions(topic.Category, loggedOnUsersRole);

            var postPipelineResult = await _postService.Create(post.PostContent, topic, loggedOnUser, null, false, post.InReplyTo);

            if (!postPipelineResult.Successful)
            {
                // TODO - This is shit. We need to return an object to process
                throw new Exception(postPipelineResult.ProcessLog.FirstOrDefault());
            }

            //Check for moderation
            if (postPipelineResult.EntityToProcess.Pending == true)
            {
                return(PartialView("_PostModeration"));
            }

            // Create the view model
            var viewModel = ViewModelMapping.CreatePostViewModel(postPipelineResult.EntityToProcess, new List <Vote>(), permissions, topic,
                                                                 loggedOnUser, SettingsService.GetSettings(), new List <Favourite>());

            // Return view
            return(PartialView("_Post", viewModel));
        }
Exemple #2
0
        public virtual async Task <ActionResult> CreatePost(CreateAjaxPostViewModel post)
        {
            // See if the user has actually added some content to the topic
            if (!ModelState.IsValid)
            {
                ModelState.AddModelError("PostContent",
                                         LocalizationService.GetResourceString("Post.Errors.NoInputPostContent"));
                return(View());
            }

            var topic             = _topicService.Get(post.Topic);
            var loggedOnUser      = User.GetMembershipUser(MembershipService, false);
            var loggedOnUsersRole = loggedOnUser.GetRole(RoleService);
            var permissions       = RoleService.GetPermissions(topic.Category, loggedOnUsersRole);

            var postPipelineResult = await _postService.Create(post.PostContent, topic, loggedOnUser, null, false, post.InReplyTo);

            if (!postPipelineResult.Successful)
            {
                // TODO - This is shit. We need to return an object to process
                throw new Exception(postPipelineResult.ProcessLog.FirstOrDefault());
            }

            // Count up total posts User
            var user = _membershipService.UpdateTotalPosts(postPipelineResult.EntityToProcess.User.Id, true);

            Context.SaveChanges();

            //Check for moderation
            if (postPipelineResult.EntityToProcess.Pending == true)
            {
                return(PartialView("_PostModeration"));
            }

            // Create the view model
            var viewModel = ViewModelMapping.CreatePostViewModel(postPipelineResult.EntityToProcess, new List <Vote>(), permissions, topic,
                                                                 loggedOnUser, SettingsService.GetSettings(), new List <Favourite>());

            // Return view
            return(PartialView("_Post", viewModel));
        }
Exemple #3
0
        public ActionResult CreatePost(CreateAjaxPostViewModel post)
        {
            PermissionSet permissions;
            Post          newPost;
            Topic         topic;

            using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork())
            {
                var loggedOnUser = MembershipService.GetUser(LoggedOnReadOnlyUser.Id);

                // Check stop words
                var stopWords = _bannedWordService.GetAll(true);
                foreach (var stopWord in stopWords)
                {
                    if (post.PostContent.IndexOf(stopWord.Word, StringComparison.CurrentCultureIgnoreCase) >= 0)
                    {
                        throw new Exception(LocalizationService.GetResourceString("StopWord.Error"));
                    }
                }

                // Quick check to see if user is locked out, when logged in
                if (loggedOnUser.IsLockedOut || !loggedOnUser.IsApproved)
                {
                    FormsAuthentication.SignOut();
                    throw new Exception(LocalizationService.GetResourceString("Errors.NoAccess"));
                }

                topic = _topicService.Get(post.Topic);

                var postContent = _bannedWordService.SanitiseBannedWords(post.PostContent);

                var akismetHelper = new AkismetHelper(SettingsService);

                newPost = _postService.AddNewPost(postContent, topic, loggedOnUser, out permissions);

                if (akismetHelper.IsSpam(newPost))
                {
                    newPost.Pending = true;
                }

                try
                {
                    unitOfWork.Commit();
                }
                catch (Exception ex)
                {
                    unitOfWork.Rollback();
                    LoggingService.Error(ex);
                    throw new Exception(LocalizationService.GetResourceString("Errors.GenericMessage"));
                }
            }

            //Check for moderation
            if (newPost.Pending == true)
            {
                return(PartialView("_PostModeration"));
            }

            // All good send the notifications and send the post back

            using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork())
            {
                // Create the view model
                var viewModel = ViewModelMapping.CreatePostViewModel(newPost, new List <Vote>(), permissions, topic, LoggedOnReadOnlyUser, SettingsService.GetSettings(), new List <Favourite>());

                // Success send any notifications
                NotifyNewTopics(topic, unitOfWork);

                // Return view
                return(PartialView("_Post", viewModel));
            }
        }
Exemple #4
0
        public ActionResult CreatePost(CreateAjaxPostViewModel post)
        {
            PermissionSet permissions;
            Post newPost;
            Topic topic;

            using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork())
            {
                var loggedOnUser = MembershipService.GetUser(LoggedOnReadOnlyUser.Id);

                // Flood control
                if (!_postService.PassedPostFloodTest(LoggedOnReadOnlyUser))
                {
                    throw new Exception(LocalizationService.GetResourceString("Errors.GenericMessage"));
                }

                // Check stop words
                var stopWords = _bannedWordService.GetAll(true);
                foreach (var stopWord in stopWords)
                {
                    if (post.PostContent.IndexOf(stopWord.Word, StringComparison.CurrentCultureIgnoreCase) >= 0)
                    {
                        throw new Exception(LocalizationService.GetResourceString("StopWord.Error"));
                    }
                }

                // Quick check to see if user is locked out, when logged in
                if (loggedOnUser.IsLockedOut || !loggedOnUser.IsApproved)
                {
                    FormsAuthentication.SignOut();
                    throw new Exception(LocalizationService.GetResourceString("Errors.NoAccess"));
                }

                topic = _topicService.Get(post.Topic);

                var postContent = _bannedWordService.SanitiseBannedWords(post.PostContent);

                var akismetHelper = new AkismetHelper(SettingsService);

                newPost = _postService.AddNewPost(postContent, topic, loggedOnUser, out permissions);

                // Set the reply to
                newPost.InReplyTo = post.InReplyTo;

                if (akismetHelper.IsSpam(newPost))
                {
                    newPost.Pending = true;
                }

                try
                {
                    unitOfWork.Commit();
                }
                catch (Exception ex)
                {
                    unitOfWork.Rollback();
                    LoggingService.Error(ex);
                    throw new Exception(LocalizationService.GetResourceString("Errors.GenericMessage"));
                }
            }

            //Check for moderation
            if (newPost.Pending == true)
            {
                return PartialView("_PostModeration");
            }

            // All good send the notifications and send the post back

            using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork())
            {
                // Create the view model
                var viewModel = ViewModelMapping.CreatePostViewModel(newPost, new List<Vote>(), permissions, topic, LoggedOnReadOnlyUser, SettingsService.GetSettings(), new List<Favourite>());

                // Success send any notifications
                NotifyNewTopics(topic, unitOfWork);

                // Return view
                return PartialView("_Post", viewModel);
            }
        }
Exemple #5
0
        public PartialViewResult CreatePost(CreateAjaxPostViewModel post)
        {
            PermissionSet permissions;
            Post          newPost;
            Topic         topic;
            var           postContent = string.Empty;

            using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork())
            {
                // Quick check to see if user is locked out, when logged in
                if (CurrentMember.IsLockedOut | !CurrentMember.IsApproved)
                {
                    ServiceFactory.MemberService.LogOff();
                    throw new Exception(Lang("Errors.NoAccess"));
                }

                // Check for banned links
                if (ServiceFactory.BannedLinkService.ContainsBannedLink(post.PostContent))
                {
                    throw new Exception(Lang("Errors.BannedLink"));
                }

                topic = ServiceFactory.TopicService.Get(post.Topic);

                postContent = ServiceFactory.BannedWordService.SanitiseBannedWords(post.PostContent);

                var akismetHelper = new AkismetHelper();

                newPost = ServiceFactory.PostService.AddNewPost(postContent, topic, CurrentMember, out permissions);

                if (!akismetHelper.IsSpam(newPost))
                {
                    try
                    {
                        unitOfWork.Commit();
                    }
                    catch (Exception ex)
                    {
                        unitOfWork.Rollback();
                        LogError(ex);
                        throw new Exception(Lang("Errors.GenericMessage"));
                    }
                }
                else
                {
                    unitOfWork.Rollback();
                    throw new Exception(Lang("Errors.PossibleSpam"));
                }
            }

            //Check for moderation
            if (newPost.Pending)
            {
                return(PartialView(PathHelper.GetThemePartialViewPath("PostModeration")));
            }

            // All good send the notifications and send the post back
            using (UnitOfWorkManager.NewUnitOfWork())
            {
                // Create the view model
                var viewModel = PostMapper.MapPostViewModel(permissions, newPost, CurrentMember, Settings, topic, new List <Vote>(), new List <Favourite>());

                // Success send any notifications
                NotifyNewTopics(topic, postContent);

                return(PartialView(PathHelper.GetThemePartialViewPath("Post"), viewModel));
            }
        }
        public ActionResult CreatePost(CreateAjaxPostViewModel post)
        {
            PermissionSet permissions;


            var loggedOnReadOnlyUser = User.GetMembershipUser(MembershipService);

            var loggedOnUser = MembershipService.GetUser(loggedOnReadOnlyUser.Id);

            // Flood control
            if (!_postService.PassedPostFloodTest(loggedOnReadOnlyUser))
            {
                throw new Exception(LocalizationService.GetResourceString("Errors.GenericMessage"));
            }

            // Check stop words
            var stopWords = _bannedWordService.GetAll(true);

            foreach (var stopWord in stopWords)
            {
                if (post.PostContent.IndexOf(stopWord.Word, StringComparison.CurrentCultureIgnoreCase) >= 0)
                {
                    throw new Exception(LocalizationService.GetResourceString("StopWord.Error"));
                }
            }

            // Quick check to see if user is locked out, when logged in
            if (loggedOnUser.IsLockedOut || !loggedOnUser.IsApproved)
            {
                FormsAuthentication.SignOut();
                throw new Exception(LocalizationService.GetResourceString("Errors.NoAccess"));
            }

            var topic = _topicService.Get(post.Topic);

            var postContent = _bannedWordService.SanitiseBannedWords(post.PostContent);

            var akismetHelper = new AkismetHelper(SettingsService);

            var newPost = _postService.AddNewPost(postContent, topic, loggedOnUser, out permissions);

            // Set the reply to
            newPost.InReplyTo = post.InReplyTo;


            if (akismetHelper.IsSpam(newPost))
            {
                newPost.Pending = true;
            }

            if (!newPost.Pending.HasValue || !newPost.Pending.Value)
            {
                _activityService.PostCreated(newPost);
            }

            try
            {
                Context.SaveChanges();
            }
            catch (Exception ex)
            {
                Context.RollBack();
                LoggingService.Error(ex);
                throw new Exception(LocalizationService.GetResourceString("Errors.GenericMessage"));
            }

            //Check for moderation
            if (newPost.Pending == true)
            {
                return(PartialView("_PostModeration"));
            }

            // All good send the notifications and send the post back


            // Create the view model
            var viewModel = ViewModelMapping.CreatePostViewModel(newPost, new List <Vote>(), permissions, topic,
                                                                 loggedOnReadOnlyUser, SettingsService.GetSettings(), new List <Favourite>());

            // Success send any notifications
            NotifyNewTopics(topic, loggedOnReadOnlyUser);

            // Return view
            return(PartialView("_Post", viewModel));
        }
Exemple #7
0
        public ActionResult CreatePost(CreateAjaxPostViewModel post)
        {
            PermissionSet permissions;
            Post          newPost;
            Topic         topic;

            using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork())
            {
                // Quick check to see if user is locked out, when logged in
                if (LoggedOnUser.IsLockedOut | !LoggedOnUser.IsApproved)
                {
                    FormsAuthentication.SignOut();
                    throw new Exception(LocalizationService.GetResourceString("Errors.NoAccess"));
                }

                topic = _topicService.Get(post.Topic);

                var postContent = _bannedWordService.SanitiseBannedWords(post.PostContent);

                var akismetHelper = new AkismetHelper(SettingsService);

                newPost = _postService.AddNewPost(postContent, topic, LoggedOnUser, out permissions);

                if (!akismetHelper.IsSpam(newPost))
                {
                    try
                    {
                        unitOfWork.Commit();

                        // Successful, add this post to the Lucene index
                        if (_luceneService.CheckIndexExists())
                        {
                            _luceneService.AddUpdate(_luceneService.MapToModel(newPost));
                        }
                    }
                    catch (Exception ex)
                    {
                        unitOfWork.Rollback();
                        LoggingService.Error(ex);
                        throw new Exception(LocalizationService.GetResourceString("Errors.GenericMessage"));
                    }
                }
                else
                {
                    unitOfWork.Rollback();
                    throw new Exception(LocalizationService.GetResourceString("Errors.PossibleSpam"));
                }
            }

            //Check for moderation
            if (newPost.Pending == true)
            {
                return(PartialView("_PostModeration"));
            }
            else
            {
                // All good send the notifications and send the post back
                using (UnitOfWorkManager.NewUnitOfWork())
                {
                    // Create the view model
                    var viewModel = new ViewPostViewModel
                    {
                        Permissions = permissions,
                        Post        = newPost,
                        User        = LoggedOnUser,
                        ParentTopic = topic
                    };

                    // Success send any notifications
                    NotifyNewTopics(topic);

                    return(PartialView("_Post", viewModel));
                }
            }
        }
        public virtual async Task <ActionResult> CreatePostAsync(CreateAjaxPostViewModel post)
        {
            var topic = _topicService.Get(post.Topic);

            // Server side validation for JS turned off.
            if (string.IsNullOrWhiteSpace(post.PostContent))
            {
                //Use TempData as ModelState doesn't persist with a redirect, we use redirect to keep thread and go to new comment box.
                TempData["NewPostError"] = "Please enter a comment";
                return(Redirect($"{topic.NiceUrl}#createpost"));
            }

            var loggedOnUser = User.GetMembershipUser(MembershipService, false);

            var postPipelineResult = await _postService.Create(post.PostContent, topic, loggedOnUser, null, false, post.InReplyTo);

            if (!postPipelineResult.Successful)
            {
                // TODO - review how this is doene
                return(ErrorToHomePage(LocalizationService.GetResourceString("Errors.GenericMessage")));
            }

            // Post id so we know where to 'jump' to when redirecting, when replying Id of replying to otherwise new post Id
            var postId = postPipelineResult.EntityToProcess.Id;

            //Check for moderation
            if (postPipelineResult.EntityToProcess.Pending == true)
            {
                return(PartialView("_PostModeration"));
            }

            // Get posts per page so we can calculate page to redirect to
            var postsPerPage = SettingsService.GetSettings().PostsPerPage;

            // Calculate the page to redirect to
            // First get all 'root' posts, i.e. no replies and not topic starter
            var rootPosts = topic.Posts.Where(x => x.InReplyTo == null).ToList().Where(x => !x.IsTopicStarter);

            // Default the post index to count of root posts
            var postIndex = rootPosts.Count();

            Guid threadId = Guid.Empty;

            // If replying get the index of post replying to
            if (post.InReplyTo != null)
            {
                // Zero based so add one to get correct value
                postIndex = rootPosts.OrderBy(x => x.DateCreated).ToList().FindIndex(x => x.Id == post.InReplyTo) + 1;
                threadId  = (Guid)post.InReplyTo;
                if (postIndex == 0)
                {
                    // would be 0 if reply to a reply etc, so go up the heirarchy until we get to root post
                    var rootInReplyTo = GetRootPostId(topic.Posts.ToList(), (Guid)post.InReplyTo);
                    threadId = rootInReplyTo;
                    // Set index of root post or default to 1 if not found
                    postIndex = rootInReplyTo != null?rootPosts.OrderBy(x => x.DateCreated).ToList().FindIndex(x => x.Id == rootInReplyTo) + 1 : 1;
                }
            }

            // Calculate the page should redirect to based on postIndex and number of posts per page
            var page = (int)Math.Ceiling((double)postIndex / postsPerPage);

            if (threadId != Guid.Empty)
            {
                return(Redirect($"{topic.NiceUrl}?p={page}&threadId={threadId}#{postId}"));
            }

            return(Redirect($"{topic.NiceUrl}?p={page}#{postId}"));
        }
        public ActionResult CreatePost(CreateAjaxPostViewModel post)
        {
            PermissionSet permissions;
            Post          newPost;
            Topic         topic;
            var           postContent = string.Empty;

            //get user post count > 5
            var currentMemberPostCount = ServiceFactory.PostService.GetByMember(CurrentMember.Id).Count();

            if (CurrentMember.Badges == null)
            {
                CurrentMember.Badges = ServiceFactory.BadgeService.GetallMembersBadges(CurrentMember.Id);
            }


            var hasBadge = CurrentMember.Badges != null && CurrentMember.Badges.Any(x => x.Name == "UserFivePost");


            using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork())
            {
                // Quick check to see if user is locked out, when logged in
                if (CurrentMember.IsLockedOut | !CurrentMember.IsApproved)
                {
                    ServiceFactory.MemberService.LogOff();
                    throw new Exception("No Access");
                }

                // Check for banned links
                if (ServiceFactory.BannedLinkService.ContainsBannedLink(post.PostContent))
                {
                    throw new Exception("Banned Link");
                }

                topic = ServiceFactory.TopicService.Get(post.Topic);

                postContent = ServiceFactory.BannedWordService.SanitiseBannedWords(post.PostContent);

                var akismetHelper = new AkismetHelper();



                newPost = ServiceFactory.PostService.AddNewPost(postContent, topic, CurrentMember, !hasBadge, out permissions);

                if (!akismetHelper.IsSpam(newPost))
                {
                    try
                    {
                        unitOfWork.Commit();
                    }
                    catch (Exception ex)
                    {
                        unitOfWork.Rollback();
                        LogError(ex);
                        //throw new Exception("Something went wrong. Please try again");
                        return(ErrorToHomePage("Something went wrong. Please try again"));
                    }
                }
                else
                {
                    unitOfWork.Rollback();
                    throw new Exception(Lang("Errors.PossibleSpam"));
                }
            }



            //Check for moderation
            if (newPost.Pending || (currentMemberPostCount < 5 && !hasBadge))
            {
                // return PartialView(PathHelper.GetThemePartialViewPath("PostModeration"));
                NotifyCategoryAdmin(topic);

                //return MessageToHomePage("Awaiting Moderation");

                ShowMessage(new GenericMessageViewModel
                {
                    Message     = Lang("Awaiting Moderation"),
                    MessageType = GenericMessages.Warning
                });

                return(Redirect(topic.Category.Url));
            }

            // All good send the notifications and send the post back
            using (UnitOfWorkManager.NewUnitOfWork())
            {
                // Create the view model
                var viewModel = PostMapper.MapPostViewModel(permissions, newPost, CurrentMember, Settings, topic, new List <Vote>(), new List <Favourite>());

                // Success send any notifications
                NotifyNewTopics(topic, postContent);


                var urlReferrer = Request.UrlReferrer;
                if (urlReferrer != null)
                {
                    return(Redirect(urlReferrer.AbsolutePath));
                }
                return(PartialView(PathHelper.GetThemePartialViewPath("Post"), viewModel));
            }
        }