Skip to content

Commit

Permalink
Fix event token param bug
Browse files Browse the repository at this point in the history
  • Loading branch information
lowercasename committed Oct 9, 2023
1 parent cc6fcb4 commit dbbb941
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
4 changes: 3 additions & 1 deletion views/event.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -423,9 +423,9 @@ window.eventData = {{{ json jsonData }}};
$(this).closest(".comment").find(".replyContainer").slideToggle();
})
$(document).ready(function() {
// Save the editing token from the URL, if it is valid
const eventID = $('#eventName').attr('data-event-id');
const url = new URL(window.location.href);
const urlParams = new URLSearchParams(window.location.search);
if (urlParams.has('e')) {
$.ajax({
Expand Down Expand Up @@ -463,6 +463,8 @@ window.eventData = {{{ json jsonData }}};
if (urlParams.has('show_edit')) {
$('#editModal').modal('show');
url.searchParams.delete('show_edit');
history.replaceState(history.state, '', url.href);
}
// From https://davidwalsh.name/javascript-download
Expand Down
19 changes: 11 additions & 8 deletions views/eventgroup.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -229,29 +229,30 @@ window.groupData = {{{ json jsonData }}};
<script>
$(document).ready(function() {
// Save the editing token from the URL, if it is valid
const eventID = $('#eventName').attr('data-event-id');
const eventGroupID = window.groupData.id;
const url = new URL(window.location.href);
const urlParams = new URLSearchParams(window.location.search);
if (urlParams.has('e')) {
$.ajax({
type: "POST",
url: `/verifytoken/group/${eventID}`,
url: `/verifytoken/group/${eventGroupID}`,
data: { editToken: urlParams.get('e') },
success: function(response, status, xhr) {
if (xhr.status === 200) {
addStoredToken(eventID, urlParams.get('e'));
addStoredToken(eventGroupID, urlParams.get('e'));
}
},
error: function(response, status, xhr) {
// The editing token is wrong - remove it
removeStoredToken(eventID);
removeStoredToken(eventGroupID);
window.location = window.location.pathname;
}
});
} else if (getStoredToken(eventID)) {
const editToken = getStoredToken(eventID);
} else if (getStoredToken(eventGroupID)) {
const editToken = getStoredToken(eventGroupID);
$.ajax({
type: "POST",
url: `/verifytoken/group/${eventID}`,
url: `/verifytoken/group/${eventGroupID}`,
data: { editToken },
success: function(response, status, xhr) {
if (xhr.status === 200) {
Expand All @@ -260,13 +261,15 @@ window.groupData = {{{ json jsonData }}};
},
error: function(response, status, xhr) {
// The editing token is wrong - remove it
removeStoredToken(eventID);
removeStoredToken(eventGroupID);
}
});
}
if (urlParams.has('show_edit')) {
$('#editModal').modal('show');
url.searchParams.delete('show_edit');
history.replaceState(history.state, '', url.href);
}
new ClipboardJS('#copyEventLink');
Expand Down

0 comments on commit dbbb941

Please sign in to comment.