use createXhrWithFormKey in the lottery

master
justcool393 2022-10-14 05:43:23 -07:00
parent bb9ab04a90
commit 6efb9b41b4
3 changed files with 6 additions and 14 deletions

View File

@ -297,8 +297,6 @@ document.onpaste = function(event) {
} }
function handle_action(type, cid, thing) { function handle_action(type, cid, thing) {
const btns = document.getElementsByClassName(`action-${cid}`) const btns = document.getElementsByClassName(`action-${cid}`)
for (const btn of btns) for (const btn of btns)
{ {

View File

@ -74,13 +74,11 @@ function postPostToastNonShopActions(t, url, button1, button2, className) {
} }
} }
function createXhrWithFormKey(url, method="POST", form=null) { function createXhrWithFormKey(url, method="POST", form=new FormData()) {
const xhr = new XMLHttpRequest(); const xhr = new XMLHttpRequest();
xhr.open(method, url); xhr.open(method, url);
xhr.setRequestHeader('xhr', 'xhr'); xhr.setRequestHeader('xhr', 'xhr');
if (!form) { if (!form) form = new FormData();
form = new FormData();
}
form.append("formkey", formkey()); form.append("formkey", formkey());
return [xhr, form]; // hacky but less stupid than what we were doing before return [xhr, form]; // hacky but less stupid than what we were doing before
} }

View File

@ -77,16 +77,12 @@ function endLotterySession() {
// Composed // Composed
function handleLotteryRequest(uri, method, callback = () => {}) { function handleLotteryRequest(uri, method, callback = () => {}) {
const xhr = new XMLHttpRequest();
const url = `/lottery/${uri}`;
xhr.open(method, url);
xhr.onload = handleLotteryResponse.bind(null, xhr, method, callback);
const form = new FormData(); const form = new FormData();
form.append("formkey", formkey()); form.append("formkey", formkey());
form.append("quantity", purchaseQuantity) form.append("quantity", purchaseQuantity);
const xhr = createXhrWithFormKey(`/lottery/${uri}`, method, form);
xhr.send(form); xhr[0].onload = handleLotteryResponse.bind(null, xhr[0], method, callback);
xhr[0].send(xhr[1]);
} }
function handleLotteryResponse(xhr, method, callback) { function handleLotteryResponse(xhr, method, callback) {