Beispiel #1
0
        public static void SendSlackSpamReport(string postBody, int topicId, string commentType, int memberId)
        {
            var ts = new TopicService(ApplicationContext.Current.DatabaseContext);

            using (var client = new WebClient())
            {
                var topic = ts.GetById(topicId);
                var post  = string.Format("Topic title: *{0}*\n\n Link to topic: http://our.umbraco.org{1}\n\n", topic.Title, topic.GetUrl());
                post = post + string.Format("{0} text: {1}\n\n", commentType, postBody);
                post = post + string.Format("Go to member http://our.umbraco.org/member/{0}\n\n", memberId);

                var body = string.Format("The following forum post was marked as spam by the spam system, if this is incorrect make sure to mark it as ham.\n\n{0}", post);
                body = body.Replace("&", "&amp;").Replace("<", "&lt;").Replace(">", "&gt;");

                var values = new NameValueCollection
                {
                    { "channel", ConfigurationManager.AppSettings["SlackChannel"] },
                    { "token", ConfigurationManager.AppSettings["SlackToken"] },
                    { "username", ConfigurationManager.AppSettings["SlackUsername"] },
                    { "icon_url", ConfigurationManager.AppSettings["SlackIconUrl"] },
                    { "text", body }
                };

                try
                {
                    var data     = client.UploadValues("https://slack.com/api/chat.postMessage", "POST", values);
                    var response = client.Encoding.GetString(data);
                }
                catch (Exception ex)
                {
                    Log.Add(LogTypes.Error, new User(0), -1, string.Format("Posting update to Slack failed {0} {1}", ex.Message, ex.StackTrace));
                }
            }
        }
Beispiel #2
0
        public void Flag(Flag flag)
        {
            var post   = string.Format("A {0} has been flagged as spam for a moderator to check\n", flag.TypeOfPost);
            var member = Members.GetById(flag.MemberId);

            post = post + string.Format("Flagged by member {0} https://our.umbraco.com/member/{1}\n", member.Name, member.Id);

            var topicId  = flag.Id;
            var posterId = 0;
            var ts       = new TopicService(ApplicationContext.Current.DatabaseContext);

            if (flag.TypeOfPost == "comment")
            {
                var cs      = new CommentService(ApplicationContext.Current.DatabaseContext, ts);
                var comment = cs.GetById(flag.Id);
                topicId  = comment.TopicId;
                posterId = comment.MemberId;
            }

            var topic = ts.GetById(topicId);

            if (flag.TypeOfPost == "thread")
            {
                posterId = topic.MemberId;
            }

            post = post + string.Format("Topic title: *{0}*\nLink to author: https://our.umbraco.com/member/{1}\n Link to {2}: https://our.umbraco.com{3}{4}\n\n", topic.Title, posterId, flag.TypeOfPost, topic.GetUrl(), flag.TypeOfPost == "comment" ? "#comment-" + flag.Id : string.Empty);

            SendSlackNotification(post);
        }
        public ExpandoObject Topic(int id, TopicSaveModel model)
        {
            dynamic o = new ExpandoObject();

            var t = TopicService.GetById(id);

            if (t == null)
            {
                throw new Exception("Topic not found");
            }

            if (t.MemberId != Members.GetCurrentMemberId() && Members.IsAdmin() == false)
            {
                throw new Exception("You cannot edit this topic");
            }

            t.Updated  = DateTime.Now;
            t.Body     = model.Body;
            t.Version  = model.Version;
            t.ParentId = model.Forum;
            t.Title    = model.Title;

            // If the chosen version is Umbraco Heartcore, overrule other categories
            if (model.Version == Constants.Forum.HeartcoreVersionNumber)
            {
                var heartCodeForumId = GetHeartCoreForumId();
                t.ParentId = heartCodeForumId;
            }

            TopicService.Save(t);

            o.url = string.Format("{0}/{1}-{2}", library.NiceUrl(t.ParentId), t.Id, t.UrlName);

            return(o);
        }
Beispiel #4
0
        void CommentService_Created(object sender, CommentEventArgs e)
        {
            var ts = new TopicService(ApplicationContext.Current.DatabaseContext);

            //Subscribe to topic
            var ns = new NotificationService(ApplicationContext.Current.DatabaseContext);

            ns.SubscribeToForumTopic(e.Comment.TopicId, e.Comment.MemberId);

            //data for notification:
            var membershipHelper = new MembershipHelper(Umbraco.Web.UmbracoContext.Current);
            var member           = membershipHelper.GetById(e.Comment.MemberId);
            var memberName       = string.Empty;

            if (member != null)
            {
                memberName = member.Name;
            }
            var topic = ts.GetById(e.Comment.TopicId);

            //send notifications
            InstantNotification not = new InstantNotification();

            not.Invoke(Config.ConfigurationFile, Config.AssemblyDir, "NewComment", e.Comment, topic, topic.GetUrl(), memberName);
        }
        public ExpandoObject Topic(int id, TopicSaveModel model)
        {
            dynamic o = new ExpandoObject();

            var t = TopicService.GetById(id);

            if (t == null)
            {
                throw new Exception("Topic not found");
            }

            if (t.MemberId != Members.GetCurrentMemberId() && Members.IsAdmin() == false)
            {
                throw new Exception("You cannot edit this topic");
            }

            t.Updated  = DateTime.Now;
            t.Body     = model.Body;
            t.Version  = model.Version;
            t.ParentId = model.Forum;
            t.Title    = model.Title;
            TopicService.Save(t);

            o.url = string.Format("{0}/{1}-{2}", library.NiceUrl(t.ParentId), t.Id, t.UrlName);

            return(o);
        }
Beispiel #6
0
        void TopicSolved(object sender, ActionEventArgs e)
        {
            var ts = new TopicService(ApplicationContext.Current.DatabaseContext);
            var cs = new CommentService(ApplicationContext.Current.DatabaseContext, ts);

            Action a = (Action)sender;

            if (a.Alias == "TopicSolved")
            {
                var c = cs.GetById(e.ItemId);
                if (c != null)
                {
                    var t = ts.GetById(c.TopicId);

                    //if performer and author of the topic is the same... go ahead..
                    if ((e.PerformerId == t.MemberId || ModeratorRoles.Split(',').Any(x => Roles.IsUserInRole(x))) && t.Answer == 0)
                    {
                        //receiver of points is the comment author.
                        e.ReceiverId = c.MemberId;

                        //remove any previous votes by the author on this comment to ensure the solution is saved instead of just the vote
                        a.ClearVotes(e.PerformerId, e.ItemId);

                        //this uses a non-standard coloumn in the forum schema, so this is added manually..
                        t.Answer = c.Id;
                        ts.Save(t);
                    }
                }
            }
        }
Beispiel #7
0
        public void SendNotification(int topicId, int memberId, NotificationMail notificationMail)
        {
            try
            {
                var topicService = new TopicService(ApplicationContext.Current.DatabaseContext);
                var topic        = topicService.GetById(topicId);

                using (ContextHelper.EnsureHttpContext())
                {
                    var memberShipHelper = new MembershipHelper(UmbracoContext.Current);
                    var member           = memberShipHelper.GetById(memberId);

                    using (var smtpClient = new SmtpClient())
                    {
                        var fromMailAddress = new MailAddress(notificationMail.FromMail, notificationMail.FromName);

                        var subject = string.Format("{0} - '{1}'", notificationMail.Subject, topic.Title);
                        var domain  = notificationMail.Domain;
                        var body    = notificationMail.Body;
                        body = string.Format(body, topic.Title, "https://" + domain + topic.GetUrl());

                        if (member.GetPropertyValue <bool>("bugMeNot") == false)
                        {
                            const string notificationTestFolder = "~/App_Data/NotificationTest";
                            if (Directory.Exists(HostingEnvironment.MapPath(notificationTestFolder)) == false)
                            {
                                Directory.CreateDirectory(HostingEnvironment.MapPath(notificationTestFolder));
                            }

                            File.AppendAllText(string.Format("{0}/{1}.txt", HostingEnvironment.MapPath(notificationTestFolder), topic.Id),
                                               string.Format("To: {0}{3}Subject: {1}{3}Body: {3}{2}", member.GetPropertyValue <string>("Email"), subject, body, Environment.NewLine));

                            using (var mailMessage = new MailMessage())
                            {
                                mailMessage.Subject = subject;
                                mailMessage.Body    = body;

                                mailMessage.To.Add(member.GetPropertyValue <string>("Email"));
                                mailMessage.From = fromMailAddress;

                                smtpClient.Send(mailMessage);
                            }
                        }
                    }
                }

                using (var db = ApplicationContext.Current.DatabaseContext.Database)
                {
                    var sql    = new Sql("UPDATE forumTopics SET markAsSolutionReminderSent = 1 WHERE id = @topicId", new { topicId = topic.Id });
                    var result = db.Execute(sql);
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error <MarkAsSolutionReminder>("Error processing notification", ex);
                throw;
            }
        }
Beispiel #8
0
        public void SendNotification(Comment comment, string memberName, string url)
        {
            var topicService = new TopicService(ApplicationContext.Current.DatabaseContext);
            var topic        = topicService.GetById(comment.TopicId);

            var db  = ApplicationContext.Current.DatabaseContext.Database;
            var sql = new Sql().Select("memberId")
                      .From("forumTopicSubscribers")
                      .Where("topicId = @topicId", new { topicId = topic.Id });

            var results = db.Query <int>(sql).ToList();

            using (ContextHelper.EnsureHttpContext())
            {
                var memberShipHelper = new MembershipHelper(UmbracoContext.Current);

                foreach (var memberId in results.Where(memberId => memberId != comment.MemberId))
                {
                    try
                    {
                        var member = memberShipHelper.GetById(memberId);
                        if (member.GetPropertyValue <bool>("bugMeNot"))
                        {
                            continue;
                        }

                        var from = new MailAddress(_details.SelectSingleNode("//from/email").InnerText,
                                                   _details.SelectSingleNode("//from/name").InnerText);

                        var subject = string.Format(_details.SelectSingleNode("//subject").InnerText, topic.Title);

                        var domain = _details.SelectSingleNode("//domain").InnerText;
                        var body   = _details.SelectSingleNode("//body").InnerText;
                        body = string.Format(body, topic.Title, "https://" + domain + url + "#comment-" + comment.Id, memberName,
                                             HttpUtility.HtmlDecode(comment.Body.StripHtml()));

                        var mailMessage = new MailMessage
                        {
                            Subject = subject,
                            Body    = body
                        };

                        mailMessage.To.Add(member.GetPropertyValue <string>("Email"));
                        mailMessage.From = @from;

                        using (var smtpClient = new SmtpClient())
                        {
                            smtpClient.Send(mailMessage);
                        }
                    }
                    catch (Exception exception)
                    {
                        LogHelper.Error <NewForumComment>(
                            string.Format("Error sending mail to member id {0}", memberId), exception);
                    }
                }
            }
        }
Beispiel #9
0
        public string TopicMarkdown(int id)
        {
            var t = TopicService.GetById(id);

            if (t == null)
            {
                throw new Exception("Topic not found");
            }

            return(t.Body.SanitizeEdit());
        }
Beispiel #10
0
        void TopicVote(object sender, ActionEventArgs e)
        {
            var ts = new TopicService(ApplicationContext.Current.DatabaseContext);

            Action a = (Action)sender;

            if (a.Alias == "LikeTopic" || a.Alias == "DisLikeTopic")
            {
                var t = ts.GetById(e.ItemId);
                e.ReceiverId = t.MemberId;
            }
        }
Beispiel #11
0
        public void GetById_ShouldReturnCorrectData()
        {
            var user  = UserCreator.Create("test");
            var topic = TopicCreator.Create(user);

            var topicRepo = DeletableEntityRepositoryMock.Get <Topic>(new List <Topic>()
            {
                topic
            });
            var service = new TopicService(topicRepo.Object);

            var result = service.GetById <TopicViewModel>(topic.Id);

            Assert.NotNull(result);
            Assert.Equal(topic.Id, result.Id);
        }
Beispiel #12
0
        //api/topic
        public void Delete(int id)
        {
            var c = TopicService.GetById(id);

            if (c == null)
            {
                throw new Exception("Topic not found");
            }

            if (!Library.Utils.IsModerator() && c.MemberId != Members.GetCurrentMemberId())
            {
                throw new Exception("You cannot delete this topic");
            }

            TopicService.Delete(c);
        }
Beispiel #13
0
        public void Put(int id, TopicSaveModel model)
        {
            var c = TopicService.GetById(id);

            if (c == null)
            {
                throw new Exception("Topic not found");
            }

            if (c.MemberId != Members.GetCurrentMemberId())
            {
                throw new Exception("You cannot edit this topic");
            }

            c.Body = model.Body;
            TopicService.Save(c);
        }
Beispiel #14
0
        public void TopicAsSpam(int id)
        {
            var t = TopicService.GetById(id);

            if (Members.IsAdmin() == false)
            {
                throw new Exception("You cannot mark this topic as spam");
            }

            if (t == null)
            {
                throw new Exception("Topic not found");
            }

            t.IsSpam = true;

            TopicService.Save(t);
        }
Beispiel #15
0
        public static void SendSlackSpamReport(string postBody, int topicId, string commentType, int memberId)
        {
            var ts = new TopicService(ApplicationContext.Current.DatabaseContext);

            var topic = ts.GetById(topicId);
            var post  = string.Format("Topic title: *{0}*\n\n Link to topic: https://our.umbraco.com{1}\n\n", topic.Title, topic.GetUrl());

            post = post + string.Format("{0} text: {1}\n\n", commentType, postBody);
            post = post + string.Format("Go to member https://our.umbraco.com/member/{0}\n\n", memberId);

            var body = string.Format("The following forum post was marked as spam by the spam system, if this is incorrect make sure to mark it as ham.\n\n{0}", post);

            body = body.Replace("&", "&amp;").Replace("<", "&lt;").Replace(">", "&gt;");

            var slack = new Slack();

            slack.PostSlackMessage(body);
        }
Beispiel #16
0
        //api/topic
        public void Delete(int id)
        {
            var c = TopicService.GetById(id);

            if (c == null)
            {
                throw new Exception("Topic not found");
            }


            var memberShipHelper = new Umbraco.Web.Security.MembershipHelper(UmbracoContext);
            var currentMemberId  = memberShipHelper.GetCurrentMemberId();

            if (Library.Utils.IsModerator() == false && c.MemberId != currentMemberId)
            {
                throw new Exception("You cannot delete this topic");
            }

            TopicService.Delete(c);
        }
Beispiel #17
0
        void CommentVote(object sender, ActionEventArgs e)
        {
            Action a = (Action)sender;

            var ts = new TopicService(ApplicationContext.Current.DatabaseContext);
            var cs = new CommentService(ApplicationContext.Current.DatabaseContext, ts);

            if (a.Alias == "LikeComment" || a.Alias == "DisLikeComment")
            {
                var c = cs.GetById(e.ItemId);
                if (c != null)
                {
                    e.ReceiverId = c.MemberId;
                }
            }
            else if (a.Alias == "TopicSolved")
            {
                var c = cs.GetById(e.ItemId);
                var t = ts.GetById(c.TopicId);
                e.Cancel = t.Answer > 0;
            }
        }
Beispiel #18
0
        public ActionResult UpdateNews(int newsid = 11)
        {
            if (Session["account"] is null)
            {
                return(RedirectToAction("Login", "Login"));
            }
            else
            {
                var account              = Session["account"] as Account;
                NewspaperService svn     = new NewspaperService();
                var            result    = svn.GetById(newsid);
                MappingService svm       = new MappingService();
                var            mapresult = svm.GetAll().Where(x => x.NewsId == result.NewsId).ToList();
                List <Topic>   lsttopic  = new List <Topic>();
                TopicService   svt       = new TopicService();
                foreach (var item in mapresult)
                {
                    lsttopic.Add(svt.GetById(item.TopicId));
                }
                string str = "";
                foreach (var item in lsttopic)
                {
                    str += item.TopicId + ",";
                }
                str = str.Substring(0, str.Length - 1);

                ViewBag.GetTopic = str;
                NewInfo newinfo = new NewInfo();
                newinfo.Title       = result.Title;
                newinfo.NewsId      = result.NewsId;
                newinfo.Image       = result.Image;
                newinfo.Journalist  = account.AccountName;
                newinfo.Description = result.Description;
                newinfo.Topic       = svt.GetAll().ToList();
                return(View(newinfo));
            }
        }
Beispiel #19
0
        public int ApproveMember(int id)
        {
            if (Members.IsAdmin() == false)
            {
                throw new Exception("You cannot approve this member");
            }

            var memberService = UmbracoContext.Application.Services.MemberService;
            var member        = memberService.GetById(id);

            if (member == null)
            {
                throw new Exception("Member not found");
            }

            var minimumKarma = 71;

            if (member.GetValue <int>("reputationCurrent") < minimumKarma)
            {
                member.SetValue("reputationCurrent", minimumKarma);
                member.SetValue("reputationTotal", minimumKarma);
                memberService.Save(member);
            }

            var rolesForUser = Roles.GetRolesForUser(member.Username);

            if (rolesForUser.Contains("potentialspam"))
            {
                memberService.DissociateRole(member.Id, "potentialspam");
            }
            if (rolesForUser.Contains("newaccount"))
            {
                memberService.DissociateRole(member.Id, "newaccount");
            }

            var topicService   = new TopicService(ApplicationContext.Current.DatabaseContext);
            var commentService = new CommentService(ApplicationContext.Current.DatabaseContext, topicService);
            var comments       = commentService.GetAllCommentsForMember(member.Id);

            foreach (var comment in comments)
            {
                if (comment.IsSpam)
                {
                    comment.IsSpam = false;
                    commentService.Save(comment);
                    var topic      = topicService.GetById(comment.TopicId);
                    var topicUrl   = topic.GetUrl();
                    var commentUrl = string.Format("{0}#comment-{1}", topicUrl, comment.Id);
                    var memberName = member.Name;
                    commentService.SendNotifications(comment, memberName, commentUrl);
                }
            }

            var topics = topicService.GetLatestTopicsForMember(member.Id, false, 100);

            foreach (var topic in topics)
            {
                if (topic.IsSpam)
                {
                    topic.IsSpam = false;
                    topicService.Save(topic);
                    topicService.SendNotifications(topic, member.Name, topic.GetUrl());
                }
            }

            var newForumTopicNotification = new NotificationsCore.Notifications.AccountApproved();

            newForumTopicNotification.SendNotification(member.Email);

            SendSlackNotification(BuildBlockedNotifactionPost(Members.GetCurrentMember().Name, member.Id, false));

            return(minimumKarma);
        }
Beispiel #20
0
        public ActionResult Index(MatBangViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var ListPicture = new List <Picture>();
                    if (model != null)
                    {
                        var result = false;
                        if (model.Id > 0)
                        {
                            var obj = _topicService.GetById(model.Id);
                            obj.ShortDescription = model.MoTa;
                            obj.ContentDetail    = model.MatBangChiTiet;
                            _topicService.Update(obj);
                        }
                        else
                        {
                            var obj = new Topic
                            {
                                ShortDescription = model.MoTa,
                                ContentDetail    = model.MatBangChiTiet,
                                key = (int)TypeTopic.MatBang
                            };
                            _topicService.Add(obj);
                        }
                        var matBangtienIch = new Picture
                        {
                            id  = model.MatBangTienIchId,
                            Url = model.UrlMatBangTienIch,
                            Key = (int)TypeTopic.MatBangTienIch
                        };
                        ListPicture.Add(matBangtienIch);
                        var matBangtongThe = new Picture
                        {
                            id  = model.MatBangTongTheId,
                            Url = model.UrlMatBangTongThe,
                            Key = (int)TypeTopic.MatBangTongThe
                        };
                        ListPicture.Add(matBangtongThe);
                        result = _pictureService.UpdateMatBang(ListPicture);

                        if (result)
                        {
                            TempData["SuccessMsg"] = "Cập nhật trang mặt bằng thành công";
                        }
                        else
                        {
                            TempData["ErrorMsg"] = "Cập nhật trang mặt bằng thất bại";
                        }
                        return(RedirectToAction("Index", "MatBang", new { Area = "Admin" }));
                    }
                    return(Json(GetBaseObjectResult(false, "Thực hiện thất bại")));
                }
                catch (Exception ex)
                {
                    return(Json(GetBaseObjectResult(false, "Xảy ra lỗi. Bạn vui lòng thử lại sau !")));
                }
            }
            return(Json(GetBaseObjectResult(false, "Dữ liệu không hợp lệ")));
        }
        public ActionResult TopicDetails(int id)
        {
            var topicDetails = _topicSevice.GetById(id);

            return(View(topicDetails));
        }
 public JsonResult GetbyID(int ID)
 {
     return(Json(topicService.GetById(ID), JsonRequestBehavior.AllowGet));
 }