Exemplo n.º 1
0
 public ForumTopicMessage Clone()
 {
     ForumTopicMessage copy = new ForumTopicMessage();
     copy.forumTopicMessageID = forumTopicMessageID;
     copy.forumTopicID = forumTopicID;
     copy.authorUserID = authorUserID;
     copy.authorName = authorName;
     copy.dateCreated = dateCreated;
     copy.bodySource = bodySource;
     copy.bodyOutput = bodyOutput;
     copy.moderationState = moderationState;
     copy.markupType = markupType;
     return copy;
 }
		private void PostTopic()
		{
			string forumStr = Request.Form["forum"];
			string path = Request.Form["path"];

			string notLoggedInURL = Request.Form["notLoggedInURL"];

			Forum forum = DataLayer.SelectForumByURLToken(forumStr);
			if (forum == null)
				forum = DataLayer.SelectForumByCode(forumStr);
			if (forum == null)
			{
				WriteErrorMessage("Bad forum code");
				return;
			}

			#region Check to see if the current user is allowed to post a new topic
			switch (forum.PostNewTopics)
			{
				case Forum.AccessType.AllowAnonymous:
					throw new NotImplementedException("need to put in anonymous author name.");

				case Forum.AccessType.ActivatedMembers:
					CheckAuthentication(notLoggedInURL);
					if (!SecurityProvider.CurrentUser.Activated)
					{
						WriteErrorMessage("You're not authenticated yet.");
						return;
					}
					break;

				case Forum.AccessType.AllMembers:
					CheckAuthentication(notLoggedInURL);
					break;

				case Forum.AccessType.Administrators:
					CheckAuthentication(notLoggedInURL);
					if (!SecurityProvider.CurrentUser.HasPermission(PermissionType.AdministrativeAccess))
					{
						WriteErrorMessage("Only administrators may post new topics.");
						return;
					}
					break;

				case Forum.AccessType.RoleMembers:
					CheckAuthentication(notLoggedInURL);
					if (forum.PostWriteAccessRoleID.HasValue)
					{
						Role role = SecurityProvider.DataLayer.SelectRole(forum.PostWriteAccessRoleID.Value);
						if (role != null)
						{
							if (SecurityProvider.CurrentUser.HasRole(role.RoleCode))
								break;
						}
					}
					WriteErrorMessage("You don't have the required permissions to post new topics.");
					return;
			}
			#endregion

			ForumTopic topic = new ForumTopic();
			ForumTopicMessage msg = new ForumTopicMessage();

			if (WebAuthentication.Instance.IsLoggedIn)
			{
				topic.AuthorUserID = SecurityProvider.CurrentUser.UserID;
				msg.AuthorUserID = SecurityProvider.CurrentUser.UserID;
			}
			else
			{
				throw new NotImplementedException("need to put in anonymous author name.");
				//topic.AuthorName =
				//msg.AuthorName =
			}

			topic.DateCreated = SprocketDate.Now;
			topic.ForumID = forum.ForumID;
			topic.ForumTopicID = 0;

#warning to do: let administrators put in a "locked" checkbox to lock the topic by default when posting it
			topic.Locked = false;

#warning to do: check for spam
			if (forum.RequireModeration)
				topic.Moderation = ForumModerationState.Pending;
			else
				topic.Moderation = ForumModerationState.Approved;

#warning to do: should be able to make the topic sticky when posting it
			topic.Sticky = false;

#warning to do: validate the subject. if invalid, store values in fast-expiring cookie and redirect to standalone posting page
			topic.Subject = Request.Form["subject"];

#warning to do: administrators should be able to specify a URL Token
			//topic.URLToken

			msg.BodySource = Request.Form["body"];
			switch (forum.Markup)
			{
				case Forum.MarkupType.BBCode:
#warning to do: check for images in source
					throw new NotImplementedException("BBCode not implemented yet.");

				case Forum.MarkupType.None:
					msg.BodyOutput = HttpUtility.HtmlEncode(msg.BodySource).Replace(Environment.NewLine, "<br />");
					break;

				case Forum.MarkupType.Textile:
#warning to do: check for images in source
					msg.BodyOutput = Textile.TextileFormatter.FormatString(msg.BodySource);
					break;

				case Forum.MarkupType.LimitedHTML:
#warning to do: check for images in source
					throw new NotImplementedException("Limited HTML not implemented yet.");

				case Forum.MarkupType.ExtendedHTML:
#warning to do: check for images in source
					msg.BodyOutput = WebUtility.SafeHtmlString(msg.BodySource, true);
					break;

				default:
					throw new NotImplementedException();
			}
#warning to do: signatures need to be appended to the output

			msg.ForumTopicMessageID = 0;
			msg.DateCreated = SprocketDate.Now;

			if (forum.RequireModeration)
				msg.Moderation = ForumModerationState.Pending;
			else
			{
				if (MightBeSpam(msg.BodySource))
				{
					msg.Moderation = ForumModerationState.Pending;
					topic.Moderation = ForumModerationState.Pending;
				}
				else
				{
					msg.Moderation = ForumModerationState.Approved;
				}
			}

			try
			{
				using (TransactionScope scope = new TransactionScope())
				{
					DatabaseManager.DatabaseEngine.PersistConnection();
					DataLayer.Store(topic);
					msg.ForumTopicID = topic.ForumTopicID;
					DataLayer.Store(msg);
					scope.Complete();
				}
			}
			finally
			{
				DatabaseManager.DatabaseEngine.ReleaseConnection();
			}

#warning to do: redirect to message rather than the forum itself.
		}
Exemplo n.º 3
0
        private void ReplyToTopic()
        {
            string forumStr = Request.Form["forum"];
            string path = Request.Form["path"];

            string notLoggedInURL = Request.Form["notLoggedInURL"];

            ForumTopic topic = DataLayer.SelectForumTopic(long.Parse(Request.Form["topic"]));
            if (topic == null)
            {
                WriteErrorMessage("Bad topic ID");
                return;
            }
            Forum forum = DataLayer.SelectForum(topic.ForumID);

            #region Check to see if the current user is allowed to reply to the topic
            switch (forum.WriteReplies)
            {
                case Forum.AccessType.AllowAnonymous:
                    throw new NotImplementedException("need to put in anonymous author name and CAPTCHA.");

                case Forum.AccessType.ActivatedMembers:
                    CheckAuthentication(notLoggedInURL);
                    if (!SecurityProvider.CurrentUser.Activated)
                    {
                        WriteErrorMessage("You're not authenticated yet.");
                        return;
                    }
                    break;

                case Forum.AccessType.AllMembers:
                    CheckAuthentication(notLoggedInURL);
                    break;

                case Forum.AccessType.Administrators:
                    CheckAuthentication(notLoggedInURL);
                    if (!SecurityProvider.CurrentUser.HasPermission(PermissionType.AdministrativeAccess))
                    {
                        WriteErrorMessage("Only administrators may reply to this topic.");
                        return;
                    }
                    break;

                case Forum.AccessType.RoleMembers:
                    CheckAuthentication(notLoggedInURL);
                    if (forum.PostWriteAccessRoleID.HasValue)
                        if (SecurityProvider.DataLayer.IsUserInRole(SecurityProvider.CurrentUser.UserID, forum.PostWriteAccessRoleID.Value))
                            break;
                    WriteErrorMessage("You don't have the required permissions to post new topics.");
                    return;
            }
            #endregion

            ForumTopicMessage msg = new ForumTopicMessage();
            msg.ForumTopicID = topic.ForumTopicID;

            if (WebAuthentication.IsLoggedIn)
                msg.AuthorUserID = SecurityProvider.CurrentUser.UserID;
            else
                throw new NotImplementedException("need to put in anonymous author name.");

            msg.DateCreated = SprocketDate.Now;
            msg.ForumTopicMessageID = 0;

            #warning to do: administrators should be able to specify a URL Token

            msg.BodySource = Request.Form["body"];
            switch (forum.Markup)
            {
                case Forum.MarkupType.BBCode:
            #warning to do: check for images in source
                    throw new NotImplementedException("BBCode not implemented yet.");

                case Forum.MarkupType.None:
                    msg.BodyOutput = HttpUtility.HtmlEncode(msg.BodySource).Replace(Environment.NewLine, "<br />");
                    break;

                case Forum.MarkupType.Textile:
            #warning to do: check for images in source
                    msg.BodyOutput = Textile.TextileFormatter.FormatString(msg.BodySource);
                    break;

                case Forum.MarkupType.LimitedHTML:
            #warning to do: check for images in source
                    throw new NotImplementedException("Limited HTML not implemented yet.");

                case Forum.MarkupType.ExtendedHTML:
            #warning to do: check for images in source
                    msg.BodyOutput = WebUtility.SafeHtmlString(msg.BodySource, true);
                    break;

                default:
                    throw new NotImplementedException();
            }
            #warning to do: signatures need to be appended to the output

            if (forum.RequireModeration)
                msg.Moderation = ForumModerationState.Pending;
            else
            {
                if (MightBeSpam(msg.BodySource))
                    msg.Moderation = ForumModerationState.Pending;
                else
                    msg.Moderation = ForumModerationState.Approved;
            }

            DataLayer.Store(msg);

            string urltoken = forum.URLToken;
            if(urltoken == "" || urltoken == null)
                urltoken = forum.ForumID.ToString();
            WebUtility.Redirect(ContentManager.RequestedPage.Path + "/" + urltoken + "/topic/" + topic.ForumTopicID + "/#" + msg.ForumTopicMessageID);
        }