51 changes: 29 additions & 22 deletions core/Piranha.Manager/assets/dist/js/piranha.postedit.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,7 @@ piranha.postedit = new Vue({

fetch(route, {
method: "post",
headers: {
"Content-Type": "application/json",
},
headers: piranha.utils.antiForgeryHeaders(),
body: JSON.stringify(model)
})
.then(function (response) { return response.json(); })
Expand Down Expand Up @@ -278,27 +276,32 @@ piranha.postedit = new Vue({
revert: function () {
var self = this;

fetch(piranha.baseUrl + "manager/api/post/revert/" + self.id)
.then(function (response) { return response.json(); })
.then(function (result) {
self.bind(result);
fetch(piranha.baseUrl + "manager/api/post/revert", {
method: "post",
headers: piranha.utils.antiForgeryHeaders(),
body: JSON.stringify(self.id)
})
.then(function (response) { return response.json(); })
.then(function (result) {
self.bind(result);

Vue.nextTick(function () {
$("#selectedCategory").select2({
tags: true,
selectOnClose: true,
placeholder: piranha.resources.texts.addCategory
});
$("#selectedTags").select2({
tags: true,
selectOnClose: false,
placeholder: piranha.resources.texts.addTags
});
Vue.nextTick(function () {
$("#selectedCategory").select2({
tags: true,
selectOnClose: true,
placeholder: piranha.resources.texts.addCategory
});
$("#selectedTags").select2({
tags: true,
selectOnClose: false,
placeholder: piranha.resources.texts.addTags
});
});

piranha.notifications.push(result.status);
})
.catch(function (error) { console.log("error:", error );
piranha.notifications.push(result.status);
})
.catch(function (error) {
console.log("error:", error );
});
},
remove: function () {
Expand All @@ -311,7 +314,11 @@ piranha.postedit = new Vue({
confirmIcon: "fas fa-trash",
confirmText: piranha.resources.texts.delete,
onConfirm: function () {
fetch(piranha.baseUrl + "manager/api/post/delete/" + self.id)
fetch(piranha.baseUrl + "manager/api/post/delete", {
method: "delete",
headers: piranha.utils.antiForgeryHeaders(),
body: JSON.stringify(self.id)
})
.then(function (response) { return response.json(); })
.then(function (result) {
piranha.notifications.push(result);
Expand Down

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions core/Piranha.Manager/assets/dist/js/piranha.siteedit.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ piranha.siteedit = new Vue({

fetch(piranha.baseUrl + "manager/api/site/save", {
method: "post",
headers: {
"Content-Type": "application/json",
},
headers: piranha.utils.antiForgeryHeaders(),
body: JSON.stringify(model)
})
.then(function (response) { return response.json(); })
Expand All @@ -104,9 +102,7 @@ piranha.siteedit = new Vue({

fetch(piranha.baseUrl + "manager/api/site/savecontent", {
method: "post",
headers: {
"Content-Type": "application/json",
},
headers: piranha.utils.antiForgeryHeaders(),
body: JSON.stringify(content)
})
.then(function (contentResponse) { return contentResponse.json(); })
Expand All @@ -121,7 +117,13 @@ piranha.siteedit = new Vue({
self.callback = null;
}
} else {
piranha.notifications.push(contentResult);
if (result.status !== 400) {
// Push status to notification hub
piranha.notifications.push(contentResult);
} else {
// Unauthorized request
piranha.notifications.unauthorized();
}
}
})
.catch(function (error) {
Expand Down Expand Up @@ -216,9 +218,7 @@ piranha.siteedit = new Vue({

fetch(piranha.baseUrl + "manager/api/site/delete", {
method: "delete",
headers: {
"Content-Type": "application/json"
},
headers: piranha.utils.antiForgeryHeaders(),
body: JSON.stringify(self.id)
})
.then(function (response) { return response.json(); })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,11 @@ export default {
confirmIcon: "fas fa-trash",
confirmText: piranha.resources.texts.delete,
onConfirm: function () {
fetch(piranha.baseUrl + "manager/api/post/delete/" + postId)
fetch(piranha.baseUrl + "manager/api/post/delete", {
method: "delete",
headers: piranha.utils.antiForgeryHeaders(),
body: JSON.stringify(postId)
})
.then(function (response) { return response.json(); })
.then(function (result) {
piranha.notifications.push(result);
Expand Down
79 changes: 43 additions & 36 deletions core/Piranha.Manager/assets/src/js/piranha.alias.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,43 +44,45 @@
}

fetch(piranha.baseUrl + "manager/api/alias/save", {
method: "post",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
id: piranha.alias.model.id,
siteId: piranha.alias.siteId,
aliasUrl: piranha.alias.model.aliasUrl,
redirectUrl: piranha.alias.model.redirectUrl,
isPermanent: piranha.alias.model.isPermanent != null ? piranha.alias.model.isPermanent : false
})
method: "post",
headers: piranha.utils.antiForgeryHeaders(),
body: JSON.stringify({
id: piranha.alias.model.id,
siteId: piranha.alias.siteId,
aliasUrl: piranha.alias.model.aliasUrl,
redirectUrl: piranha.alias.model.redirectUrl,
isPermanent: piranha.alias.model.isPermanent != null ? piranha.alias.model.isPermanent : false
})
.then(function (response) { return response.json(); })
.then(function (result) {
if (result.status.type === "success")
{
// Remove validation class
form.classList.remove("was-validated");
})
.then(function (response) { return response.json(); })
.then(function (result) {
if (result.status.type === "success") {
// Remove validation class
form.classList.remove("was-validated");

// Close modal
$("#aliasModal").modal("hide");
// Close modal
$("#aliasModal").modal("hide");

// Clear modal
piranha.alias.model.id = null;
piranha.alias.model.aliasUrl = null;
piranha.alias.model.redirectUrl = null;
piranha.alias.model.isPermanent = true;
// Clear modal
piranha.alias.model.id = null;
piranha.alias.model.aliasUrl = null;
piranha.alias.model.redirectUrl = null;
piranha.alias.model.isPermanent = true;

piranha.alias.items = result.items;
}
piranha.alias.items = result.items;
}

if (result.status !== 400) {
// Push status to notification hub
piranha.notifications.push(result.status);
})
.catch(function (error) {
console.log("error:", error);
});
} else {
// Unauthorized request
piranha.notifications.unauthorized();
}
})
.catch(function (error) {
console.log("error:", error);
});
},
remove: function (id) {
var self = this;
Expand All @@ -94,17 +96,22 @@
onConfirm: function () {
fetch(piranha.baseUrl + "manager/api/alias/delete", {
method: "delete",
headers: {
"Content-Type": "application/json"
},
headers: piranha.utils.antiForgeryHeaders(),
body: JSON.stringify(id)
})
.then(function (response) { return response.json(); })
.then(function (result) {
self.items = result.items;
if (result.status.type === "success") {
self.items = result.items;
}

// Push status to notification hub
piranha.notifications.push(result.status);
if (result.status !== 400) {
// Push status to notification hub
piranha.notifications.push(result.status);
} else {
// Unauthorized request
piranha.notifications.unauthorized();
}
})
.catch(function (error) { console.log("error:", error ); });
}
Expand Down
82 changes: 53 additions & 29 deletions core/Piranha.Manager/assets/src/js/piranha.comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,32 +44,50 @@ piranha.comment = new Vue({
approve: function (id) {
var self = this;

fetch(piranha.baseUrl + "manager/api/comment/approve/" + id + (self.contentId != null ? "/" + self.contentId : ""))
.then(function (response) { return response.json(); })
.then(function (result) {
if (result.status) {
// Push status to notification hub
piranha.notifications.push(result.status);
}
self.contentId = result.contentId;
self.items = result.comments;
fetch(piranha.baseUrl + "manager/api/comment/approve", {
method: "post",
headers: piranha.utils.antiForgeryHeaders(),
body: JSON.stringify({
id: id,
parentId: self.contentId
})
.catch(function (error) { console.log("error:", error ); });
})
.then(function (response) { return response.json(); })
.then(function (result) {
if (result.status) {
// Push status to notification hub
piranha.notifications.push(result.status);
}
self.contentId = result.contentId;
self.items = result.comments;
})
.catch(function (error) {
console.log("error:", error );
});
},
unapprove: function (id) {
var self = this;

fetch(piranha.baseUrl + "manager/api/comment/unapprove/" + id + (self.contentId != null ? "/" + self.contentId : ""))
.then(function (response) { return response.json(); })
.then(function (result) {
if (result.status) {
// Push status to notification hub
piranha.notifications.push(result.status);
}
self.contentId = result.contentId;
self.items = result.comments;
fetch(piranha.baseUrl + "manager/api/comment/unapprove", {
method: "post",
headers: piranha.utils.antiForgeryHeaders(),
body: JSON.stringify({
id: id,
parentId: self.contentId
})
.catch(function (error) { console.log("error:", error ); });
})
.then(function (response) { return response.json(); })
.then(function (result) {
if (result.status) {
// Push status to notification hub
piranha.notifications.push(result.status);
}
self.contentId = result.contentId;
self.items = result.comments;
})
.catch(function (error) {
console.log("error:", error );
});
},
toggleApproved: function (item) {
item.isApproved = !item.isApproved;
Expand All @@ -83,16 +101,22 @@ piranha.comment = new Vue({
remove: function (id) {
var self = this;

fetch(piranha.baseUrl + "manager/api/comment/delete/" + id)
.then(function (response) { return response.json(); })
.then(function (result) {
// Push status to notification hub
piranha.notifications.push(result);
fetch(piranha.baseUrl + "manager/api/comment/delete", {
method: "delete",
headers: piranha.utils.antiForgeryHeaders(),
body: JSON.stringify(id)
})
.then(function (response) { return response.json(); })
.then(function (result) {
// Push status to notification hub
piranha.notifications.push(result);

// Refresh the list
self.load(self.contentId);
})
.catch(function (error) { console.log("error:", error ); });
// Refresh the list
self.load(self.contentId);
})
.catch(function (error) {
console.log("error:", error );
});
},
setStatus: function (status) {
this.state = status;
Expand Down
13 changes: 8 additions & 5 deletions core/Piranha.Manager/assets/src/js/piranha.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ piranha.config = new Vue({

fetch(piranha.baseUrl + "manager/api/config/save", {
method: "post",
headers: {
"Content-Type": "application/json",
},
headers: piranha.utils.antiForgeryHeaders(),
body: JSON.stringify({
hierarchicalPageSlugs: self.model.hierarchicalPageSlugs,
expandedSitemapLevels: self.model.expandedSitemapLevels,
Expand All @@ -80,8 +78,13 @@ piranha.config = new Vue({
})
.then(function (response) { return response.json(); })
.then(function (result) {
// Push status to notification hub
piranha.notifications.push(result.status);
if (result.status !== 400) {
// Push status to notification hub
piranha.notifications.push(result.status);
} else {
// Unauthorized request
piranha.notifications.unauthorized();
}
})
.catch(function (error) {
console.log("error:", error);
Expand Down
10 changes: 6 additions & 4 deletions core/Piranha.Manager/assets/src/js/piranha.contentedit.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,7 @@ piranha.contentedit = new Vue({

fetch(route, {
method: "post",
headers: {
"Content-Type": "application/json",
},
headers: piranha.utils.antiForgeryHeaders(),
body: JSON.stringify(model)
})
.then(function (response) { return response.json(); })
Expand Down Expand Up @@ -233,7 +231,11 @@ piranha.contentedit = new Vue({
onConfirm: function () {
var groupId = self.groupId;

fetch(piranha.baseUrl + "manager/api/content/delete/" + self.id)
fetch(piranha.baseUrl + "manager/api/content/delete", {
method: "delete",
headers: piranha.utils.antiForgeryHeaders(),
body: JSON.stringify(self.id)
})
.then(function (response) { return response.json(); })
.then(function (result) {
piranha.notifications.push(result);
Expand Down
6 changes: 5 additions & 1 deletion core/Piranha.Manager/assets/src/js/piranha.contentlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ piranha.contentlist = new Vue({
confirmIcon: "fas fa-trash",
confirmText: piranha.resources.texts.delete,
onConfirm: function () {
fetch(piranha.baseUrl + "manager/api/content/delete/" + id)
fetch(piranha.baseUrl + "manager/api/content/delete", {
method: "delete",
headers: piranha.utils.antiForgeryHeaders(),
body: JSON.stringify(id)
})
.then(function (response) { return response.json(); })
.then(function (result) {
piranha.notifications.push(result);
Expand Down
1 change: 1 addition & 0 deletions core/Piranha.Manager/assets/src/js/piranha.dropzone.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ piranha.dropzone = new function () {
var defaultOptions = {
paramName: 'Uploads',
url: piranha.baseUrl + "manager/api/media/upload",
headers: piranha.utils.antiForgeryHeaders(false),
thumbnailWidth: 70,
thumbnailHeight: 70,
previewsContainer: selector + " .media-list",
Expand Down
40 changes: 23 additions & 17 deletions core/Piranha.Manager/assets/src/js/piranha.languageedit.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,25 @@ piranha.languageedit = new Vue({
self.loading = true;
fetch(piranha.baseUrl + "manager/api/language", {
method: "post",
headers: {
"Content-Type": "application/json",
},
headers: piranha.utils.antiForgeryHeaders(),
body: JSON.stringify({
items: JSON.parse(JSON.stringify(self.items))
})
})
.then(function (response) { return response.json(); })
.then(function (result) {
//if (result.status.type === "success")
//{
if (result.status.type === "success") {
self.bind(result);
//}

// Push status to notification hub
// piranha.notifications.push(result.status);
}

if (result.status !== 400) {
// Push status to notification hub
piranha.notifications.push(result.status);
} else {
// Unauthorized request
piranha.notifications.unauthorized();
self.loading = false;
}
})
.catch(function (error) {
console.log("error:", error);
Expand All @@ -80,20 +83,23 @@ piranha.languageedit = new Vue({
self.loading = true;
fetch(piranha.baseUrl + "manager/api/language/" + item.id, {
method: "delete",
headers: {
"Content-Type": "application/json",
},
headers: piranha.utils.antiForgeryHeaders(),
body: JSON.stringify(item)
})
.then(function (response) { return response.json(); })
.then(function (result) {
//if (result.status.type === "success")
//{
if (result.status.type === "success") {
self.bind(result);
//}
}

// Push status to notification hub
// piranha.notifications.push(result.status);
if (result.status !== 400) {
// Push status to notification hub
piranha.notifications.push(result.status);
} else {
// Unauthorized request
piranha.notifications.unauthorized();
self.loading = false;
}
})
.catch(function (error) {
console.log("error:", error);
Expand Down
83 changes: 52 additions & 31 deletions core/Piranha.Manager/assets/src/js/piranha.media.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,22 @@ piranha.media = new Vue({

fetch(piranha.baseUrl + "manager/api/media/move/" + (folderId || ""), {
method: "POST",
headers: {
'Content-Type': 'application/json'
},
headers: piranha.utils.antiForgeryHeaders(),
body: JSON.stringify(selections)
})
.then(function (response) { return response.json(); })
.then(function (result) {
if (result.type === "success") {
piranha.media.refresh();
}
// Push status to notification hub
piranha.notifications.push(result);

if (result.status !== 400) {
// Push status to notification hub
piranha.notifications.push(result.status);
} else {
// Unauthorized request
piranha.notifications.unauthorized();
}
})
.catch(function (error) { console.log("error:", error); });
},
Expand Down Expand Up @@ -166,7 +170,6 @@ piranha.media = new Vue({
piranha.media.load(piranha.media.currentFolderId);
},
addFolder: function () {
//this.saveFolder("#mediaFolderModal", "mediaFolderForm", {
this.saveFolder(null, null, {
parentId: this.currentFolderId,
name: this.folder.name
Expand All @@ -193,9 +196,7 @@ piranha.media = new Vue({

fetch(piranha.baseUrl + "manager/api/media/folder/save", {
method: "post",
headers: {
"Content-Type": "application/json",
},
headers: piranha.utils.antiForgeryHeaders(),
body: JSON.stringify(folder)
})
.then(function (response) { return response.json(); })
Expand All @@ -215,8 +216,13 @@ piranha.media = new Vue({
self.refresh();
}

// Push status to notification hub
piranha.notifications.push(result.status);
if (result.status !== 400) {
// Push status to notification hub
piranha.notifications.push(result.status);
} else {
// Unauthorized request
piranha.notifications.unauthorized();
}
})
.catch(function (error) {
console.log("error:", error);
Expand All @@ -226,19 +232,22 @@ piranha.media = new Vue({
var self = this;

fetch(piranha.baseUrl + "manager/api/media/delete", {
method: "post",
headers: {
"Content-Type": "application/json",
},
method: "delete",
headers: piranha.utils.antiForgeryHeaders(),
body: JSON.stringify([id])
})
.then(function (response) { return response.json(); })
.then(function (result) {
// Refresh
self.refresh();

// Push status to notification hub
piranha.notifications.push(result);
if (result.status !== 400) {
// Push status to notification hub
piranha.notifications.push(result.status);
} else {
// Unauthorized request
piranha.notifications.unauthorized();
}
})
.catch(function (error) { console.log("error:", error ); });
},
Expand All @@ -254,19 +263,22 @@ piranha.media = new Vue({
confirmText: piranha.resources.texts.delete,
onConfirm: function () {
fetch(piranha.baseUrl + "manager/api/media/delete", {
method: "post",
headers: {
"Content-Type": "application/json",
},
method: "delete",
headers: piranha.utils.antiForgeryHeaders(),
body: JSON.stringify(selections)
})
.then(function (response) { return response.json(); })
.then(function (result) {
// Refresh
self.refresh();

// Push status to notification hub
piranha.notifications.push(result);
if (result.status !== 400) {
// Push status to notification hub
piranha.notifications.push(result.status);
} else {
// Unauthorized request
piranha.notifications.unauthorized();
}
})
.catch(function (error) { console.log("error:", error); });
}
Expand All @@ -275,18 +287,27 @@ piranha.media = new Vue({
removeFolder: function (id) {
var self = this;

fetch(piranha.baseUrl + "manager/api/media/folder/delete/" + id)
.then(function (response) { return response.json(); })
.then(function (result) {
self.bind(result);
fetch(piranha.baseUrl + "manager/api/media/folder/delete", {
method: "delete",
headers: piranha.utils.antiForgeryHeaders(),
body: JSON.stringify(id)
})
.then(function (response) { return response.json(); })
.then(function (result) {
self.bind(result);

history.pushState({ folderId: id }, "", piranha.baseUrl + "manager/media" + (id ? "/" + id : ""));
document.title = result.currentFolderName ? result.currentFolderName : "Media";
history.pushState({ folderId: id }, "", piranha.baseUrl + "manager/media" + (id ? "/" + id : ""));
document.title = result.currentFolderName ? result.currentFolderName : "Media";

if (result.status !== 400) {
// Push status to notification hub
piranha.notifications.push(result.status);
})
.catch(function (error) { console.log("error:", error ); });
} else {
// Unauthorized request
piranha.notifications.unauthorized();
}
})
.catch(function (error) { console.log("error:", error ); });
}
},
computed: {
Expand Down
13 changes: 8 additions & 5 deletions core/Piranha.Manager/assets/src/js/piranha.mediapicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,7 @@ piranha.mediapicker = new Vue({
if (self.folderName !== "") {
fetch(piranha.baseUrl + "manager/api/media/folder/save" + (self.filter ? "?filter=" + self.filter : ""), {
method: "post",
headers: {
"Content-Type": "application/json",
},
headers: piranha.utils.antiForgeryHeaders(),
body: JSON.stringify({
parentId: self.currentFolderId,
name: self.folderName
Expand All @@ -167,8 +165,13 @@ piranha.mediapicker = new Vue({
self.items = result.media;
}

// Push status to notification hub
piranha.notifications.push(result.status);
if (result.status !== 400) {
// Push status to notification hub
piranha.notifications.push(result.status);
} else {
// Unauthorized request
piranha.notifications.unauthorized();
}
})
.catch(function (error) {
console.log("error:", error);
Expand Down
7 changes: 7 additions & 0 deletions core/Piranha.Manager/assets/src/js/piranha.notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ piranha.notifications = new Vue({
items: [],
},
methods: {
unauthorized: function() {
this.push({
type: "danger",
body: "Request sender could not be verified by the server.",
hide: true
});
},
push: function (notification) {

notification.style = {
Expand Down
49 changes: 30 additions & 19 deletions core/Piranha.Manager/assets/src/js/piranha.pageedit.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,7 @@ piranha.pageedit = new Vue({

fetch(route, {
method: "post",
headers: {
"Content-Type": "application/json",
},
headers: piranha.utils.antiForgeryHeaders(),
body: JSON.stringify(model)
})
.then(function (response) { return response.json(); })
Expand Down Expand Up @@ -314,29 +312,38 @@ piranha.pageedit = new Vue({
revert: function () {
var self = this;

fetch(piranha.baseUrl + "manager/api/page/revert/" + self.id)
.then(function (response) { return response.json(); })
.then(function (result) {
self.bind(result);
fetch(piranha.baseUrl + "manager/api/page/revert", {
method: "post",
headers: piranha.utils.antiForgeryHeaders(),
body: JSON.stringify(self.id)
})
.then(function (response) { return response.json(); })
.then(function (result) {
self.bind(result);

piranha.notifications.push(result.status);
})
.catch(function (error) { console.log("error:", error );
piranha.notifications.push(result.status);
})
.catch(function (error) {
console.log("error:", error );
});
},
detach: function () {
var self = this;

fetch(piranha.baseUrl + "manager/api/page/detach/" + self.id)
.then(function (response) { return response.json(); })
.then(function (result) {
self.bind(result);
fetch(piranha.baseUrl + "manager/api/page/detach", {
method: "post",
headers: piranha.utils.antiForgeryHeaders(),
body: JSON.stringify(self.id)
})
.then(function (response) { return response.json(); })
.then(function (result) {
self.bind(result);

piranha.notifications.push(result.status);
})
.catch(function (error) { console.log("error:", error );
piranha.notifications.push(result.status);
})
.catch(function (error) {
console.log("error:", error );
});

},
remove: function () {
var self = this;
Expand All @@ -348,7 +355,11 @@ piranha.pageedit = new Vue({
confirmIcon: "fas fa-trash",
confirmText: piranha.resources.texts.delete,
onConfirm: function () {
fetch(piranha.baseUrl + "manager/api/page/delete/" + self.id)
fetch(piranha.baseUrl + "manager/api/page/delete", {
method: "delete",
headers: piranha.utils.antiForgeryHeaders(),
body: JSON.stringify(self.id)
})
.then(function (response) { return response.json(); })
.then(function (result) {
piranha.notifications.push(result);
Expand Down
10 changes: 6 additions & 4 deletions core/Piranha.Manager/assets/src/js/piranha.pagelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ piranha.pagelist = new Vue({
confirmIcon: "fas fa-trash",
confirmText: piranha.resources.texts.delete,
onConfirm: function () {
fetch(piranha.baseUrl + "manager/api/page/delete/" + id)
fetch(piranha.baseUrl + "manager/api/page/delete", {
method: "delete",
headers: piranha.utils.antiForgeryHeaders(),
body: JSON.stringify(id)
})
.then(function (response) { return response.json(); })
.then(function (result) {
piranha.notifications.push(result);
Expand All @@ -60,9 +64,7 @@ piranha.pagelist = new Vue({
callback: function (l, e) {
fetch(piranha.baseUrl + "manager/api/page/move", {
method: "post",
headers: {
"Content-Type": "application/json"
},
headers: piranha.utils.antiForgeryHeaders(),
body: JSON.stringify({
id: $(e).attr("data-id"),
items: $(l).nestable("serialize")
Expand Down
51 changes: 29 additions & 22 deletions core/Piranha.Manager/assets/src/js/piranha.postedit.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,7 @@ piranha.postedit = new Vue({

fetch(route, {
method: "post",
headers: {
"Content-Type": "application/json",
},
headers: piranha.utils.antiForgeryHeaders(),
body: JSON.stringify(model)
})
.then(function (response) { return response.json(); })
Expand Down Expand Up @@ -278,27 +276,32 @@ piranha.postedit = new Vue({
revert: function () {
var self = this;

fetch(piranha.baseUrl + "manager/api/post/revert/" + self.id)
.then(function (response) { return response.json(); })
.then(function (result) {
self.bind(result);
fetch(piranha.baseUrl + "manager/api/post/revert", {
method: "post",
headers: piranha.utils.antiForgeryHeaders(),
body: JSON.stringify(self.id)
})
.then(function (response) { return response.json(); })
.then(function (result) {
self.bind(result);

Vue.nextTick(function () {
$("#selectedCategory").select2({
tags: true,
selectOnClose: true,
placeholder: piranha.resources.texts.addCategory
});
$("#selectedTags").select2({
tags: true,
selectOnClose: false,
placeholder: piranha.resources.texts.addTags
});
Vue.nextTick(function () {
$("#selectedCategory").select2({
tags: true,
selectOnClose: true,
placeholder: piranha.resources.texts.addCategory
});
$("#selectedTags").select2({
tags: true,
selectOnClose: false,
placeholder: piranha.resources.texts.addTags
});
});

piranha.notifications.push(result.status);
})
.catch(function (error) { console.log("error:", error );
piranha.notifications.push(result.status);
})
.catch(function (error) {
console.log("error:", error );
});
},
remove: function () {
Expand All @@ -311,7 +314,11 @@ piranha.postedit = new Vue({
confirmIcon: "fas fa-trash",
confirmText: piranha.resources.texts.delete,
onConfirm: function () {
fetch(piranha.baseUrl + "manager/api/post/delete/" + self.id)
fetch(piranha.baseUrl + "manager/api/post/delete", {
method: "delete",
headers: piranha.utils.antiForgeryHeaders(),
body: JSON.stringify(self.id)
})
.then(function (response) { return response.json(); })
.then(function (result) {
piranha.notifications.push(result);
Expand Down
20 changes: 10 additions & 10 deletions core/Piranha.Manager/assets/src/js/piranha.siteedit.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ piranha.siteedit = new Vue({

fetch(piranha.baseUrl + "manager/api/site/save", {
method: "post",
headers: {
"Content-Type": "application/json",
},
headers: piranha.utils.antiForgeryHeaders(),
body: JSON.stringify(model)
})
.then(function (response) { return response.json(); })
Expand All @@ -104,9 +102,7 @@ piranha.siteedit = new Vue({

fetch(piranha.baseUrl + "manager/api/site/savecontent", {
method: "post",
headers: {
"Content-Type": "application/json",
},
headers: piranha.utils.antiForgeryHeaders(),
body: JSON.stringify(content)
})
.then(function (contentResponse) { return contentResponse.json(); })
Expand All @@ -121,7 +117,13 @@ piranha.siteedit = new Vue({
self.callback = null;
}
} else {
piranha.notifications.push(contentResult);
if (result.status !== 400) {
// Push status to notification hub
piranha.notifications.push(contentResult);
} else {
// Unauthorized request
piranha.notifications.unauthorized();
}
}
})
.catch(function (error) {
Expand Down Expand Up @@ -216,9 +218,7 @@ piranha.siteedit = new Vue({

fetch(piranha.baseUrl + "manager/api/site/delete", {
method: "delete",
headers: {
"Content-Type": "application/json"
},
headers: piranha.utils.antiForgeryHeaders(),
body: JSON.stringify(self.id)
})
.then(function (response) { return response.json(); })
Expand Down
23 changes: 22 additions & 1 deletion core/Piranha.Manager/assets/src/js/piranha.utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,28 @@ piranha.utils = {
},
strLength: function (str) {
return str != null ? str.length : 0;
}
},
antiForgery: function () {
const cookies = document.cookie.split(";");
for (let i = 0; i < cookies.length; i++) {
let c = cookies[i].trim().split("=");
if (c[0] === piranha.antiForgery.cookieName) {
return c[1];
}
}
return "";
},
antiForgeryHeaders: function (isJson) {
var headers = {};

if (isJson === undefined || isJson === true)
{
headers["Content-Type"] = "application/json";
}
headers[piranha.antiForgery.headerName] = piranha.utils.antiForgery();

return headers;
}
};

Date.prototype.addDays = function(days) {
Expand Down
4 changes: 3 additions & 1 deletion core/Piranha.Manager/assets/src/scss/inc/_actions.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
.actions {
white-space: nowrap;

a {
a, button {
background-color: transparent;
border: none;
display: inline-block;
width: 1.5rem;
height: 1.5rem;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
position: fixed;
left: 4rem;
bottom: 0;
z-index: 2000; // TODO: verify z-index later
z-index: 20000; // TODO: verify z-index later

.notification {
width: 300px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,12 @@
<td class="actions one">
@if ((await Auth.AuthorizeAsync(User, Piranha.AspNetCore.Identity.Permissions.RolesDelete)).Succeeded)
{
<a class="danger" href="@Url.Action("Delete", new {id = role.Id})">
<span class="fas fa-trash"></span>
</a>
<form method="post" action="~/manager/role/delete">
<input type="hidden" name="id" value="@role.Id">
<button class="danger">
<span class="fas fa-trash"></span>
</button>
</form>
}
</td>
</tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
namespace Piranha.AspNetCore.Identity.Controllers
{
[Area("Manager")]
[AutoValidateAntiforgeryToken]
public class RoleController : ManagerController
{
private readonly IDb _db;
Expand Down Expand Up @@ -66,7 +67,7 @@ public IActionResult Save(RoleEditModel model)
return View("Edit", model);
}

[HttpGet]
[HttpPost]
[Route("/manager/role/delete")]
[Authorize(Policy = Permissions.RolesDelete)]
public IActionResult Delete(Guid id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ namespace Piranha.AspNetCore.Identity.Controllers
/// Manager controller for managing users accounts.
/// </summary>
[Area("Manager")]
[AutoValidateAntiforgeryToken]
public class UserController : ManagerController
{
private readonly IDb _db;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ piranha.useredit= new Vue({
console.log(JSON.stringify(self.userModel));
fetch(piranha.baseUrl + "manager/user/save", {
method: "post",
headers: {
"Content-Type": "application/json"
},
headers: piranha.utils.antiForgeryHeaders(),
body: JSON.stringify(self.userModel)
})
.then(function (response) {
Expand Down Expand Up @@ -102,9 +100,7 @@ piranha.useredit= new Vue({
var ok = false;
fetch(piranha.baseUrl + "manager/user/delete", {
method: "delete",
headers: {
"Content-Type": "application/json"
},
headers: piranha.utils.antiForgeryHeaders(),
body: JSON.stringify(userId)
})
.then(function (response) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ piranha.userlist = new Vue({
onConfirm: function () {
fetch(piranha.baseUrl + "manager/user/delete", {
method: "delete",
headers: {
"Content-Type": "application/json"
},
headers: piranha.utils.antiForgeryHeaders(),
body: JSON.stringify(user.id)
})
.then(function (response) { return response.json(); })
Expand Down