diff options
| author | pitu <[email protected]> | 2017-01-17 00:37:54 -0300 |
|---|---|---|
| committer | pitu <[email protected]> | 2017-01-17 00:37:54 -0300 |
| commit | bdfd512c10986a9b4f137e668be6bd80dbd8f617 (patch) | |
| tree | f64f3cbcd5888916f8a388f62873732687db934d /public/js/upload.js | |
| parent | Login screen on dashboard (diff) | |
| download | host.fuwn.me-bdfd512c10986a9b4f137e668be6bd80dbd8f617.tar.xz host.fuwn.me-bdfd512c10986a9b4f137e668be6bd80dbd8f617.zip | |
token handling and verification
Diffstat (limited to 'public/js/upload.js')
| -rw-r--r-- | public/js/upload.js | 49 |
1 files changed, 28 insertions, 21 deletions
diff --git a/public/js/upload.js b/public/js/upload.js index bb60f28..c99ecb4 100644 --- a/public/js/upload.js +++ b/public/js/upload.js @@ -8,7 +8,7 @@ window.onload = function () { var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function() { if (xhr.readyState == XMLHttpRequest.DONE) { - USINGTOKEN = JSON.parse(xhr.responseText).token; + USINGTOKEN = JSON.parse(xhr.responseText).private; prepareTokenThing(); } } @@ -20,14 +20,14 @@ window.onload = function () { if(!USINGTOKEN) return getInfo(); if(!localStorage.token){ - document.getElementById('tokenContainer').style.display = 'flex' document.getElementById('tokenSubmit').addEventListener('click', function(){ getInfo(document.getElementById('token').value) }); - }else{ - getInfo(localStorage.token); + return document.getElementById('tokenContainer').style.display = 'flex'; } + getInfo(localStorage.token); + } function prepareDropzone(){ @@ -91,23 +91,25 @@ window.onload = function () { xhr.onreadystatechange = function() { if (xhr.readyState == XMLHttpRequest.DONE) { - if(xhr.responseText !== 'not-authorized'){ - - div = document.createElement('div'); - div.id = 'dropzone'; - div.innerHTML = 'Click here or drag and drop files'; - div.style.display = 'flex'; - - document.getElementById('btnGithub').style.display = 'none'; - document.getElementById('tokenContainer').style.display = 'none'; - document.getElementById('uploadContainer').appendChild(div); - document.getElementById('panel').style.display = 'block'; - - if(xhr.responseText.maxFileSize) maxSize = JSON.parse(xhr.responseText).maxFileSize; - if(token) localStorage.token = token; - - prepareDropzone(); - } + + if(xhr.responseText === 'not-authorized') + return notAuthorized(); + + div = document.createElement('div'); + div.id = 'dropzone'; + div.innerHTML = 'Click here or drag and drop files'; + div.style.display = 'flex'; + + document.getElementById('btnGithub').style.display = 'none'; + document.getElementById('tokenContainer').style.display = 'none'; + document.getElementById('uploadContainer').appendChild(div); + document.getElementById('panel').style.display = 'block'; + + if(xhr.responseText.maxFileSize) maxSize = JSON.parse(xhr.responseText).maxFileSize; + if(token) localStorage.token = token; + + prepareDropzone(); + } } xhr.open('GET', '/api/info', true); @@ -117,4 +119,9 @@ window.onload = function () { xhr.send(null); } + + function notAuthorized() { + localStorage.removeItem("token"); + location.reload(); + } };
\ No newline at end of file |