mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2024-12-16 01:16:22 +00:00
c3d61733af
Added iamdustan/smoothscroll polyfill in dashboard pages. This will polyfill smooth scroll (when executed programmatically) for older browers. No-JS uploader's notice button when on private mode will now also say "Log in to upload", although auth page will still require JS. All front-end buttons will now use outlined version. I'm lovin' it. Auth page will now show a loading spinner if the user has a saved token. Afterwards, they will still be redirected to dashboard. Better error handlers in home, dashboard, and auth pages. Removed <hr> from uploads & users lists in dashboard. "Manage your token" menu will no longer try to make an API request prior to displaying its page. Reloading the page will already trigger token verification anyway. Updated public/images/fb_share.png. Updated README.md. A few other tweaks.
1 line
5.2 KiB
Plaintext
1 line
5.2 KiB
Plaintext
{"version":3,"sources":["auth.js"],"names":["const","lsKeys","token","page","localStorage","user","pass","unhide","document","querySelector","classList","add","remove","onAxiosError","error","console","statusText","520","521","522","523","524","525","526","527","530","response","status","description","data","swal","do","dest","trigger","value","trim","axios","post","username","password","then","success","window","location","catch","verify","onload","form","addEventListener","event","preventDefault","checkValidity","currentTarget"],"mappings":"AAEAA,IAAMC,OAAS,CACbC,MAAO,SAGHC,KAAO,CAEXD,MAAOE,aAAaH,OAAOC,OAG3BG,KAAM,KACNC,KAAM,KAGRC,OAAW,WACTC,SAASC,cAAc,WAAWC,UAAUC,IAAI,aAChDH,SAASC,cAAc,UAAUC,UAAUE,OAAO,cAIpDC,aAAiB,SAAGC,GAClBC,QAAQD,MAAMA,GAGdd,IAYMgB,EAZmB,CACvBC,IAAK,gBACLC,IAAK,qBACLC,IAAK,uBACLC,IAAK,wBACLC,IAAK,qBACLC,IAAK,uBACLC,IAAK,0BACLC,IAAK,gBACLC,IAAK,oBAG6BX,EAAMY,SAASC,SAAWb,EAAMY,SAASV,WACvEY,EAAcd,EAAMY,SAASG,MAAQf,EAAMY,SAASG,KAAKD,YAC3Dd,EAAMY,SAASG,KAAKD,YACpB,sFAEJ,OAAOE,KAAQhB,EAAMY,SAAS,OAAM,IAAIV,EAAcY,EAAa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AAG,WAAYkB,EAAMG,kBAGxBjD,KAAKD,MACPC,KAAK0C,SAEL1C,KAAKI","file":"auth.js","sourcesContent":["/* global swal, axios */\n\nconst lsKeys = {\n token: 'token'\n}\n\nconst page = {\n // user token\n token: localStorage[lsKeys.token],\n\n // HTML elements\n user: null,\n pass: null\n}\n\npage.unhide = () => {\n document.querySelector('#loader').classList.add('is-hidden')\n document.querySelector('#login').classList.remove('is-hidden')\n}\n\n// Handler for Axios errors\npage.onAxiosError = error => {\n console.error(error)\n\n // Better Cloudflare errors\n const cloudflareErrors = {\n 520: 'Unknown Error',\n 521: 'Web Server Is Down',\n 522: 'Connection Timed Out',\n 523: 'Origin Is Unreachable',\n 524: 'A Timeout Occurred',\n 525: 'SSL Handshake Failed',\n 526: 'Invalid SSL Certificate',\n 527: 'Railgun Error',\n 530: 'Origin DNS Error'\n }\n\n const statusText = cloudflareErrors[error.response.status] || error.response.statusText\n const description = error.response.data && error.response.data.description\n ? error.response.data.description\n : 'There was an error with the request, please check the console for more information.'\n\n return swal(`${error.response.status} ${statusText}`, description, 'error')\n}\n\npage.do = (dest, trigger) => {\n const user = page.user.value.trim()\n if (!user)\n return swal('An error occurred!', 'You need to specify a username.', 'error')\n\n const pass = page.pass.value.trim()\n if (!pass)\n return swal('An error occurred!', 'You need to specify a password.', 'error')\n\n trigger.classList.add('is-loading')\n axios.post(`api/${dest}`, {\n username: user,\n password: pass\n }).then(response => {\n if (response.data.success === false) {\n trigger.classList.remove('is-loading')\n return swal(`Unable to ${dest}!`, response.data.description, 'error')\n }\n\n localStorage.token = response.data.token\n window.location = 'dashboard'\n }).catch(error => {\n trigger.classList.remove('is-loading')\n page.onAxiosError(error)\n })\n}\n\npage.verify = () => {\n axios.post('api/tokens/verify', {\n token: page.token\n }).then(response => {\n if (response.data.success === false) {\n page.unhide()\n return swal('An error occurred!', response.data.description, 'error')\n }\n\n // Redirect to dashboard if token is valid\n window.location = 'dashboard'\n }).catch(error => {\n page.unhide()\n page.onAxiosError(error)\n })\n}\n\nwindow.onload = () => {\n page.user = document.querySelector('#user')\n page.pass = document.querySelector('#pass')\n\n // Prevent default form's submit action\n const form = document.querySelector('#authForm')\n form.addEventListener('submit', event => {\n event.preventDefault()\n })\n\n document.querySelector('#loginBtn').addEventListener('click', event => {\n if (!form.checkValidity()) return\n page.do('login', event.currentTarget)\n })\n\n document.querySelector('#registerBtn').addEventListener('click', event => {\n if (!form.checkValidity()) return\n page.do('register', event.currentTarget)\n })\n\n if (page.token)\n page.verify()\n else\n page.unhide()\n}\n"]} |