mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2024-12-15 00:46:22 +00:00
1 line
6.9 KiB
Plaintext
1 line
6.9 KiB
Plaintext
{"version":3,"sources":["auth.js"],"names":["const","lsKeys","token","page","localStorage","user","pass","cloudflareErrors","loaderSection","document","querySelector","classList","add","loginSection","remove","floatingBtn","error","console","content","createElement","innerHTML","toString","swal","title","icon","response","onError","statusText","status","description","data","dest","trigger","value","trim","axios","post","username","password","then","success","window","location","catch","onAxiosError","unhide","code","removeItem","addEventListener","form","event","preventDefault","loginBtn","checkValidity","do","currentTarget","registerBtn","click","verify"],"mappings":"AAEAA,IAAMC,OAAS,CACbC,MAAO,SAGHC,KAAO,CAEXD,MAAOE,aAAaH,OAAOC,OAG3BG,KAAM,KACNC,KAAM,KAGNC,iBAAkB,CAChB,IAAK,gBACL,IAAK,qBACL,IAAK,uBACL,IAAK,wBACL,IAAK,qBACL,IAAK,uBACL,IAAK,0BACL,IAAK,gBACL,IAAK,oBAITJ,OAAW,WACTH,IAAMQ,EAAgBC,SAASC,cAAc,WACzCF,GAAeA,EAAcG,UAAUC,IAAI,aAE/CZ,IAAMa,EAAeJ,SAASC,cAAc,oBACxCG,GAAcA,EAAaF,UAAUG,OAAO,aAEhDd,IAAMe,EAAcN,SAASC,cAAc,mCACvCK,GAAaA,EAAYJ,UAAUG,OAAO,YAChD,EAGAX,QAAY,SAAGa,GACbC,QAAQD,MAAMA,GAEdhB,IAAMkB,EAAUT,SAASU,cAAc,OAKvC,OAJAD,EAAQE,UAAY,kBACPJ,EAAMK,WAAU,8EAGtBC,KAAK,CACVC,MAAO,qBACPC,KAAM,QAFNN,QAGAA,GADJ,EAMAf,aAAiB,SAAGa,GAClB,IAAKA,EAAMS,SACT,OAAOtB,KAAKuB,QAAQV,GAGtBhB,IAAM2B,EAAaxB,KAAKI,iBAAiBS,EAAMS,SAASG,SAAWZ,EAAMS,SAASE,WAC5EE,EAAcb,EAAMS,SAASK,MAAQd,EAAMS,SAASK,KAAK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SAASC,cAAc,aACpCuC,EAAKD,iBAAiB,UAAQ,SAAEE,GAC9BA,EAAMC,gBAFR,IAKAnD,IAAMoD,EAAW3C,SAASC,cAAc,aACpC0C,GACFA,EAASJ,iBAAiB,SAAO,SAAEE,GAC5BD,EAAKI,iBACVlD,KAAKmD,GAAG,QAASJ,EAAMK,cAFzB,IAMFvD,IAAMwD,EAAc/C,SAASC,cAAc,gBACvC8C,GACFA,EAAYR,iBAAiB,SAAO,SAAEE,GACpC,IAAKD,EAAKI,gBAER,OAAOD,EAASK,QAElBtD,KAAKmD,GAAG,WAAYJ,EAAMK,cAF5B,IAMEpD,KAAKD,MAAOC,KAAKuD,SAChBvD,KAAK0C,QAFZ","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 // Better Cloudflare errors\n 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\npage.unhide = () => {\n const loaderSection = document.querySelector('#loader')\n if (loaderSection) loaderSection.classList.add('is-hidden')\n\n const loginSection = document.querySelector('#login.is-hidden')\n if (loginSection) loginSection.classList.remove('is-hidden')\n\n const floatingBtn = document.querySelector('.floating-home-button.is-hidden')\n if (floatingBtn) floatingBtn.classList.remove('is-hidden')\n}\n\n// Handler for regular JS errors\npage.onError = error => {\n console.error(error)\n\n const content = document.createElement('div')\n content.innerHTML = `\n <p><code>${error.toString()}</code></p>\n <p>Please check your console for more information.</p>\n `\n return swal({\n title: 'An error occurred!',\n icon: 'error',\n content\n })\n}\n\n// Handler for Axios errors\npage.onAxiosError = error => {\n if (!error.response) {\n return page.onError(error)\n }\n\n const statusText = page.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.\\nPlease 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) return swal('An error occurred!', 'You need to specify a username.', 'error')\n\n const pass = page.pass.value.trim()\n if (!pass) 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 if (error.response.data && error.response.data.code === 10001) {\n localStorage.removeItem(lsKeys.token)\n }\n page.unhide()\n page.onAxiosError(error)\n })\n}\n\nwindow.addEventListener('DOMContentLoaded', () => {\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 const loginBtn = document.querySelector('#loginBtn')\n if (loginBtn) {\n loginBtn.addEventListener('click', event => {\n if (!form.checkValidity()) return\n page.do('login', event.currentTarget)\n })\n }\n\n const registerBtn = document.querySelector('#registerBtn')\n if (registerBtn) {\n registerBtn.addEventListener('click', event => {\n if (!form.checkValidity()) {\n // Workaround for browsers to display native form error messages\n return loginBtn.click()\n }\n page.do('register', event.currentTarget)\n })\n }\n\n if (page.token) page.verify()\n else page.unhide()\n})\n"]} |