Skip to content
Snippets Groups Projects
Commit 49e0a849 authored by Lloyd Hilaiel's avatar Lloyd Hilaiel
Browse files

fix manage page, now we explicitly call /wsapi/csrf so that the page itself...

fix manage page, now we explicitly call /wsapi/csrf so that the page itself can be cached. issue #74
parent 1c387edd
No related branches found
No related tags found
No related merge requests found
......@@ -39,6 +39,21 @@ $(function() {
}
});
var csrf = undefined;
// execute a function with a csrf token, fetching it if required
function withCSRF(cb) {
if (csrf === undefined) {
$.get("/wsapi/csrf", function(result) {
alert(result);
csrf = result.body;
cb();
});
} else {
setTimeout(cb, 0);
}
}
function display_saved_ids()
{
var emails = {};
......@@ -48,9 +63,11 @@ function display_saved_ids()
$('#cancellink').click(function() {
if (confirm('Are you sure you want to cancel your account?')) {
$.post("/wsapi/account_cancel", {csrf: window.csrf}, function(result) {
window.localStorage.emails = null;
document.location="/";
withCSRF(function() {
$.post("/wsapi/account_cancel", {"csrf": csrf}, function(result) {
window.localStorage.emails = null;
document.location="/";
});
});
}
});
......@@ -81,13 +98,15 @@ function display_saved_ids()
meta.append(deauth);
deauth.click(function() {
var t = JSON.parse(window.localStorage.emails);
// remove email from server
$.post("/wsapi/remove_email", {"email" : e, "csrf": window.csrf}, function(response) {
// we delete from store only once we got response
delete t[e];
window.localStorage.emails = JSON.stringify(t);
display_saved_ids();
});
withCSRF(function() {
// remove email from server
$.post("/wsapi/remove_email", {"email" : e, "csrf": csrf}, function(response) {
// we delete from store only once we got response
delete t[e];
window.localStorage.emails = JSON.stringify(t);
display_saved_ids();
});
});
});
var d = new Date(data.created);
......
<script>
window.csrf = "<%= csrf %>";
</script>
<div class="why">
<p>
Manage your email addresses in BrowserID.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment