Skip to content

Commit

Permalink
Merge pull request #121 from Moros1138/120-csrf-token-mismatch-when-s…
Browse files Browse the repository at this point in the history
…essions-run-longer-than-2-hours

120 csrf token mismatch when sessions run longer than 2 hours
  • Loading branch information
Moros1138 committed Jul 12, 2024
2 parents f4c8f92 + 6b490b3 commit 8d6f9c6
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 97 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ All notable changes to this project will be documented in this file. Each batch

It is a summary of changes that would be pertinent to the end user of the PGEtinker website. For a comprehensive history of changes made to the project, please refer to the repository's commit history.

## 20204-07-07
## 2024-07-12

- Fixed [Issue #120](https://github.com/Moros1138/PGEtinker/issues/120)


## 2024-07-07

- Fixed bug involving shared code persistence
- Changed threshold for responsive navbar
Expand Down
118 changes: 65 additions & 53 deletions resources/js/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,45 +226,50 @@ export default class PGEtinker
if(!this.preCompile())
return;

axios.post("/api/share", {
code: this.editorPanel.getValue()
}).then((response) =>
{
this.compileSuccessHandler(response.data);
axios.get('/sanctum/csrf-cookie').then(_ => {
axios.post("/api/share", {
code: this.editorPanel.getValue()
}).then((response) =>
{
this.compileSuccessHandler(response.data);

shareDialog(response.data.shareURL, response.data.shareThumbURL)
.finally(() =>
{

});

shareDialog(response.data.shareURL, response.data.shareThumbURL)
.finally(() =>
{

});
}).catch((error) =>
{
this.setActiveTab("editor");
playIconElem.classList.toggle("hidden", false);
stopIconElem.classList.toggle("hidden", true);
spanElem.innerHTML = "Run";

}).catch((error) =>
{
this.setActiveTab("editor");
playIconElem.classList.toggle("hidden", false);
stopIconElem.classList.toggle("hidden", true);
spanElem.innerHTML = "Run";


if(error.response)
{
if(error.response.status)
if(error.response)
{
if(error.response.status == 503)
if(error.response.status)
{
this.compileFailHandler("pgetinker.cpp:1:1: error: PGEtinker service has gone offline. try again later.\n");
if(error.response.status == 503)
{
this.compileFailHandler("pgetinker.cpp:1:1: error: PGEtinker service has gone offline. try again later.\n");
return;
}
}

if(error.response.data.stderr)
{
this.compileFailHandler(error.response.data.stderr);
return;
}
}

if(error.response.data.stderr)
{
this.compileFailHandler(error.response.data.stderr);
return;
}
}

this.compileFailHandler("pgetinker.cpp:1:1: error: compilation failed in a way that's not being handled. please make a bug report.\n");

this.compileFailHandler("pgetinker.cpp:1:1: error: compilation failed in a way that's not being handled. please make a bug report.\n");
});
}).catch(() =>
{
this.compileFailHandler("pgetinker.cpp:1:1: error: calling the compiler api failed.\n");
});
}

Expand Down Expand Up @@ -313,37 +318,44 @@ export default class PGEtinker

return new Promise<void>((resolve, reject) =>
{
axios.post("/api/compile", {
code: this.editorPanel.getValue()
}).then((response) =>
{
this.compileSuccessHandler(response.data);
resolve();
}).catch((error) =>
{

if(error.response)
axios.get('/sanctum/csrf-cookie').then(_ => {
axios.post("/api/compile", {
code: this.editorPanel.getValue()
}).then((response) =>
{
if(error.response.status)
this.compileSuccessHandler(response.data);
resolve();
}).catch((error) =>
{

if(error.response)
{
if(error.response.status == 503)
if(error.response.status)
{
this.compileFailHandler("pgetinker.cpp:1:1: error: PGEtinker service has gone offline. try again later.\n");
if(error.response.status == 503)
{
this.compileFailHandler("pgetinker.cpp:1:1: error: PGEtinker service has gone offline. try again later.\n");
reject();
return;
}
}

if(error.response.data.stderr)
{
this.compileFailHandler(error.response.data.stderr);
reject();
return;
}
}

if(error.response.data.stderr)
{
this.compileFailHandler(error.response.data.stderr);
reject();
return;
}
}
this.compileFailHandler("pgetinker.cpp:1:1: error: compilation failed in a way that's not being handled. please make a bug report.\n");
this.compileFailHandler("pgetinker.cpp:1:1: error: compilation failed in a way that's not being handled. please make a bug report.\n");
reject();
});
}).catch(() =>
{
this.compileFailHandler("pgetinker.cpp:1:1: error: calling the compiler api failed.\n");
reject();
});

});
}

Expand Down
1 change: 1 addition & 0 deletions resources/js/components/EditorPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ export default class EditorPanel

try
{
await axios.get('/sanctum/csrf-cookie');
await this.monacoWrapper.getLanguageClientWrapper().start();
}
catch(e)
Expand Down
8 changes: 6 additions & 2 deletions resources/js/lib/monacoWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,16 @@ export const runCppWrapper = async() =>
const userConfig = createUserConfig('/workspace', "", '/workspace/pgetinker.cpp');
const wrapper = new MonacoEditorLanguageClientWrapper();

try {
try
{
await axios.get('/sanctum/csrf-cookie');
await wrapper.init(userConfig);

// open files, so the LS can pick it up
await vscode.workspace.openTextDocument(pgetinkerCppUri);
} catch (e) {
}
catch (e)
{
console.error(e);
}

Expand Down
75 changes: 39 additions & 36 deletions resources/js/lib/newsDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,45 +8,48 @@ export default function newsDialog()
dialog.classList.toggle("dialog", true);
dialog.classList.toggle("news", true);

axios.get("/api/news").then((response) =>
axios.get('/sanctum/csrf-cookie').then(_ =>
{

let entries = [];

response.data.entries.forEach((entry) =>
axios.get("/api/news").then((response) =>
{
entries.push(`<div class="${entry.type}">${entry.message}</div>`);
});

dialog.innerHTML = `
<div class="window">
<div class="header">News and Updates</div>
<div class="content">
<h3>PGEtinker has been updated. Here's what's been done:</h3>
<h3>${response.data.date}</h3>
<div class="entries">${entries.join("")}</div>
<p>
For more details visit the <a href="https://github.com/Moros1138/PGEtinker" target="_blank">PGEtinker github repository</a>.
</p>
<p>
Version: ${version.substring(0, 7)}
</p>
</div>
<div class="footer">
<button class="ok">Close</button>
</div>
</div>`;

dialog.querySelector("button.ok").addEventListener("click", (event) =>
{
dialog.remove();
resolve();

let entries = [];

response.data.entries.forEach((entry) =>
{
entries.push(`<div class="${entry.type}">${entry.message}</div>`);
});

dialog.innerHTML = `
<div class="window">
<div class="header">News and Updates</div>
<div class="content">
<h3>PGEtinker has been updated. Here's what's been done:</h3>
<h3>${response.data.date}</h3>
<div class="entries">${entries.join("")}</div>
<p>
For more details visit the <a href="https://github.com/Moros1138/PGEtinker" target="_blank">PGEtinker github repository</a>.
</p>
<p>
Version: ${version.substring(0, 7)}
</p>
</div>
<div class="footer">
<button class="ok">Close</button>
</div>
</div>`;

dialog.querySelector("button.ok").addEventListener("click", (event) =>
{
dialog.remove();
resolve();
});

document.body.appendChild(dialog);
});

document.body.appendChild(dialog);
});

});

});

}
13 changes: 8 additions & 5 deletions resources/js/lib/supportersDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,15 @@ export default function supportersDialog()

return new Promise((resolve) =>
{
axios.get("/api/supporters").then((response) =>
axios.get('/sanctum/csrf-cookie').then(_ =>
{
renderSupportersDialog(response.data.supporters).then(() => resolve());
}).catch((reason) =>
{
renderSupportersDialog(reason.response.data.supporters).then(() => resolve());
axios.get("/api/supporters").then((response) =>
{
renderSupportersDialog(response.data.supporters).then(() => resolve());
}).catch((reason) =>
{
renderSupportersDialog(reason.response.data.supporters).then(() => resolve());
});
});
});
}

0 comments on commit 8d6f9c6

Please sign in to comment.