Move uForum base calls to apicontroller

This commit is contained in:
Sebastiaan Janssen
2014-09-13 16:06:54 +02:00
parent e375eb0bef
commit 976fa143e2
7 changed files with 208 additions and 40 deletions
+2 -2
View File
@@ -23,13 +23,13 @@ if ($('#f_search').val() != '')
var mForum = function() {
return {
NewTopic : function(s_forumId, s_title, s_body) {
$.post("/base/uForum/NewTopic/" + s_forumId + ".aspx", {title: s_title, body: s_body},
$.post("/umbraco/api/Forum/NewTopic/?forumId=" + s_forumId, {title: s_title, body: s_body},
function(data){
window.location = jQuery("value", data).text();
});
},
NewComment : function(s_topicId, i_items, s_body) {
$.post("/base/uForum/NewComment/" + s_topicId + "/" + i_items +".aspx", {body: s_body},
$.post("/umbraco/api/Forum/NewComment/?topicId=" + s_topicId + "&itemsPerPage=" + i_items, { body: s_body },
function(data){
var forceReload = false;
forceReload = (window.location.href.indexOf("#") > -1);
+5 -5
View File
@@ -18,19 +18,19 @@ var uForum = function () {
});
},
NewTopic: function (forumId, title, body,tags) {
$.post("/base/uForum/NewTopic/" + forumId + ".aspx", { title: title, body: body,tags:tags },
$.post("/umbraco/api/Forum/NewTopic/?forumId=" + forumId, { title: title, body: body,tags:tags },
function (data) {
window.location = jQuery("value", data).text();
});
},
EditTopic: function (topicId, title, body,tags) {
$.post("/base/uForum/EditTopic/" + topicId + ".aspx", { title: title, body: body,tags:tags },
$.post("/umbraco/api/Forum/EditTopic/?topicId=" + topicId, { title: title, body: body,tags:tags },
function (data) {
window.location = jQuery("value", data).text();
});
},
NewComment: function (topicId, items, body) {
$.post("/base/uForum/NewComment/" + topicId + "/" + items + ".aspx", { body: body },
$.post("/umbraco/api/Forum/NewComment/?topicId=" + topicId + "&itemsPerPage=" + items, { body: body },
function (data) {
var forceReload = (window.location.href.indexOf("#") > -1);
window.location = jQuery("value", data).text();
@@ -41,7 +41,7 @@ var uForum = function () {
});
},
EditComment: function (commentId, items, body) {
$.post("/base/uForum/EditComment/" + commentId + "/" + items + ".aspx", { body: body },
$.post("/umbraco/api/Forum/EditComment/?commentId=" + commentId + "&itemsPerPage=" + items, { body: body },
function (data) {
var forceReload = (window.location.href.indexOf("#") > -1);
window.location = jQuery("value", data).text();
@@ -74,7 +74,7 @@ var uForum = function () {
jQuery.each(jQuery("result", data), function (index, value) {
var title = jQuery(value).find("Title").text();
var topicId = jQuery(value).find("__NodeId").text();
html += "<li><a href='/base/uForum/TopicUrl/" + topicId + ".aspx' target='_blank' class='similarTopicLink'>" + title + "</a></li>";
html += "<li><a href='/umbraco/api/Forum/TopicUrl/?topicId=" + topicId + "' target='_blank' class='similarTopicLink'>" + title + "</a></li>";
found = true;
});
html += "</ul>";
+31 -31
View File
@@ -1,89 +1,89 @@
var uPowers = function () {
return {
LikeTopic: function (s_topicId) {
$.get("/base/uPowers/Action/LikeTopic/" + s_topicId + ".aspx");
$.get("/base/uPowers/Action/LikeTopic/" + s_topicId);
},
DeleteTopic: function (s_Id) {
//This is secured on the serverside, so don't even bother fuckers...
$.get("/base/uForum/DeleteTopic/" + s_Id + ".aspx");
$.get("/umbraco/api/Forum/DeleteTopic/?topicId=" + s_Id);
},
MoveTopic: function (s_Id, f_id) {
//This is secured on the serverside, so don't even bother fuckers...
$.get("/base/uForum/MoveTopic/" + s_Id + "/" + f_id + ".aspx",
$.get("/umbraco/api/Forum/MoveTopic/?topicId=" + s_Id + "&newForumId=" + f_id,
function (data) {
window.location = jQuery("value", data).text();
});
},
LikeComment: function (s_Id) {
$.get("/base/uPowers/Action/LikeComment/" + s_Id + ".aspx");
$.get("/base/uPowers/Action/LikeComment/" + s_Id);
},
DeleteComment: function (s_Id) {
//This is secured on the serverside, so don't even bother fuckers...
$.get("/base/uForum/DeleteComment/" + s_Id + ".aspx");
$.get("/umbraco/api/Forum/DeleteComment/?commentId=" + s_Id);
},
MarkCommentAsSpam: function (s_Id) {
//This is secured on the serverside, so don't even bother fuckers...
$.get("/base/uForum/MarkCommentAsSpam/" + s_Id + ".aspx");
$.get("/umbraco/api/Forum/MarkCommentAsSpam/?commentId=" + s_Id);
},
MarkCommentAsHam: function (s_Id) {
//This is secured on the serverside, so don't even bother fuckers...
$.get("/base/uForum/MarkCommentAsHam/" + s_Id + ".aspx");
$.get("/umbraco/api/Forum/MarkCommentAsHam/?commentId=" + s_Id);
},
MarkTopicAsSpam: function (s_Id) {
//This is secured on the serverside, so don't even bother fuckers...
$.get("/base/uForum/MarkTopicAsSpam/" + s_Id + ".aspx");
$.get("/umbraco/api/Forum/MarkTopicAsSpam/?topicId=" + s_Id);
},
MarkTopicAsHam: function (s_Id) {
//This is secured on the serverside, so don't even bother fuckers...
$.get("/base/uForum/MarkTopicAsHam/" + s_Id + ".aspx");
$.get("/umbraco/api/Forum/MarkTopicAsHam/?topicId=" + s_Id);
},
EventSignUp: function (s_link, s_Id) {
$.get("/base/uEvents/Toggle/" + s_Id + ".aspx",
$.get("/base/uEvents/Toggle/" + s_Id,
function (data) {
window.location = s_link + "?done=true";
});
},
WikiUp: function (s_nodeId) {
$.get("/base/uPowers/Action/WikiUp/" + s_nodeId + ".aspx");
$.get("/base/uPowers/Action/WikiUp/" + s_nodeId);
},
WikiDelete: function (s_Id) {
//This is secured on the serverside, so don't even bother fuckers...
$.get("/base/uWiki/Delete/" + s_Id + ".aspx");
$.get("/base/uWiki/Delete/" + s_Id);
},
WikiMove: function (s_Id, s_target) {
//This is secured on the serverside, so don't even bother fuckers...
$.get("/base/uWiki/Move/" + s_Id + "/" + s_target + ".aspx",
$.get("/base/uWiki/Move/" + s_Id + "/" + s_target,
function (data) {
top.location = jQuery("value", data).text();
});
},
ProjectUp: function (s_nodeId, comment) {
$.get("/base/uPowers/Action/ProjectUp/" + s_nodeId + ".aspx");
$.get("/base/uPowers/Action/ProjectUp/" + s_nodeId);
},
ProjectApproval: function (s_nodeId) {
$.post("/base/uPowers/Action/ProjectApproval/" + s_nodeId + ".aspx");
$.post("/base/uPowers/Action/ProjectApproval/" + s_nodeId);
},
SolvesProblem: function (s_nodeId) {
$.get("/base/uPowers/Action/TopicSolved/" + s_nodeId + ".aspx");
$.get("/base/uPowers/Action/TopicSolved/" + s_nodeId);
},
BlockMember: function (s_memberId) {
//This is secured on the serverside, so don't even bother fuckers...
$.get("/base/Community/BlockMember/" + s_memberId + ".aspx");
$.get("/base/Community/BlockMember/" + s_memberId);
},
UnBlockMember: function (s_memberId) {
//This is secured on the serverside, so don't even bother fuckers...
$.get("/base/Community/UnBlockMember/" + s_memberId + ".aspx");
$.get("/base/Community/UnBlockMember/" + s_memberId);
},
DeleteMember: function (s_memberId) {
//This is secured on the serverside, so don't even bother fuckers...
$.get("/base/Community/DeleteMember/" + s_memberId + ".aspx");
$.get("/base/Community/DeleteMember/" + s_memberId);
}
};
} ();
@@ -49,7 +49,7 @@
var link = $(this);
var commentId = link.attr("rel");
var commentRow = link.closest('tr');
$.get("/base/uForum/DeleteComment/" + commentId + ".aspx");
$.get("/umbraco/api/Forum/DeleteComment/?commentId=" + commentId);
commentRow.hide("slow");
}
@@ -49,7 +49,7 @@
var link = $(this);
var commentId = link.attr("rel");
var commentRow = link.closest('tr');
$.get("/base/uForum/DeleteComment/" + commentId + ".aspx");
$.get("/umbraco/api/Forum/DeleteComment/?commentId=" + commentId);
commentRow.hide("slow");
}
+167
View File
@@ -0,0 +1,167 @@
using System.Linq;
using System.Web;
using System.Web.Http;
using uForum.Library;
using umbraco.cms.businesslogic.web;
using Umbraco.Core.Models;
using umbraco.NodeFactory;
using Umbraco.Web;
using Umbraco.Web.Security;
using Umbraco.Web.WebApi;
namespace uForum.Api
{
public class ForumController : UmbracoApiController
{
private static readonly MembershipHelper MemberShipHelper = new MembershipHelper(UmbracoContext.Current);
private static readonly IPublishedContent CurrentMember = MemberShipHelper.GetCurrentMember();
private const string ModeratorRoles = "admin,HQ,Core,MVP";
[HttpGet]
public static string EditTopic(int topicId)
{
var topic = Businesslogic.Topic.GetTopic(topicId);
if (topic.Editable(CurrentMember.Id) == false)
return "0";
var title = HttpContext.Current.Request["title"];
var body = HttpContext.Current.Request["body"];
var tags = HttpContext.Current.Request["tags"];
topic.Body = body;
topic.Title = title;
//topic.Tags = tags;
topic.Save(false);
return Xslt.NiceTopicUrl(topic.Id);
}
[HttpGet]
public static string TopicUrl(int topicId)
{
HttpContext.Current.Response.Redirect(Xslt.NiceTopicUrl(topicId));
HttpContext.Current.Response.End();
return "";
}
[HttpGet]
public static string NewTopic(int forumId)
{
var node = new Node(forumId);
if (CurrentMember.Id > 0 && Access.HasAccces(node.Id, CurrentMember.Id))
{
var title = HttpContext.Current.Request["title"];
var body = HttpContext.Current.Request["body"];
var tags = HttpContext.Current.Request["tags"];
var topic = Businesslogic.Topic.Create(forumId, title, body, CurrentMember.Id);
return Xslt.NiceTopicUrl(topic.Id);
}
return "0";
}
[HttpGet]
public static string NewComment(int topicId, int itemsPerPage)
{
if (CurrentMember.Id > 0 && topicId > 0)
{
var body = HttpContext.Current.Request["body"];
var comment = Businesslogic.Comment.Create(topicId, body, CurrentMember.Id);
return Xslt.NiceCommentUrl(comment.TopicId, comment.Id, itemsPerPage);
}
return "";
}
[HttpGet]
public static string EditComment(int commentId, int itemsPerPage)
{
var comment = new Businesslogic.Comment(commentId);
if (comment.Editable(CurrentMember.Id))
{
var body = HttpContext.Current.Request["body"];
comment.Body = body;
comment.Save();
return Xslt.NiceCommentUrl(comment.TopicId, comment.Id, itemsPerPage);
}
return "";
}
[HttpGet]
[MemberAuthorize(AllowGroup = "admin")]
public static string DeleteTopic(int topicId)
{
var topic = Businesslogic.Topic.GetTopic(topicId);
topic.Delete();
return "true";
}
[HttpGet]
[MemberAuthorize(AllowGroup = ModeratorRoles)]
public static string MarkTopicAsSpam(int topicId)
{
var topic = Businesslogic.Topic.GetTopic(topicId);
topic.MarkAsSpam();
return "true";
}
[HttpGet]
[MemberAuthorize(AllowGroup = ModeratorRoles)]
public static string MarkTopicAsHam(int topicId)
{
var topic = Businesslogic.Topic.GetTopic(topicId);
topic.MarkAsHam();
return "true";
}
[HttpGet]
[MemberAuthorize(AllowGroup = "admin")]
public static string MoveTopic(int topicId, int newForumId)
{
var topic = Businesslogic.Topic.GetTopic(topicId);
topic.Move(newForumId);
return Xslt.NiceTopicUrl(topic.Id);
}
[HttpGet]
[MemberAuthorize(AllowGroup = "admin")]
public static string DeleteComment(int commentId)
{
var comment = new Businesslogic.Comment(commentId);
comment.Delete();
return "true";
}
[HttpGet]
[MemberAuthorize(AllowGroup = ModeratorRoles)]
public static string MarkCommentAsSpam(int commentId)
{
var comment = new Businesslogic.Comment(commentId);
comment.MarkAsSpam();
return "true";
}
[HttpGet]
[MemberAuthorize(AllowGroup = ModeratorRoles)]
public string MarkCommentAsHam(int commentId)
{
var comment = new Businesslogic.Comment(commentId);
comment.MarkAsHam();
return "true";
}
}
}
+1
View File
@@ -239,6 +239,7 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Api\ForumController.cs" />
<Compile Include="Businesslogic\Comment.cs" />
<Compile Include="Businesslogic\Data.cs" />
<Compile Include="Businesslogic\Events.cs" />