mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2024-12-13 16:06:21 +00:00
1 line
6.1 KiB
Plaintext
1 line
6.1 KiB
Plaintext
{"version":3,"sources":["auth.js"],"names":["const","lsKeys","token","page","localStorage","user","pass","loaderSection","document","querySelector","classList","add","loginSection","remove","floatingBtn","error","console","statusText","response","status","description","data","swal","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,KAGRH,OAAW,WACTH,IAAMO,EAAgBC,SAASC,cAAc,WACzCF,GAAeA,EAAcG,UAAUC,IAAI,aAE/CX,IAAMY,EAAeJ,SAASC,cAAc,oBACxCG,GAAcA,EAAaF,UAAUG,OAAO,aAEhDb,IAAMc,EAAcN,SAASC,cAAc,mCACvCK,GAAaA,EAAYJ,UAAUG,OAAO,cAIhDV,aAAiB,SAAGY,GAClBC,QAAQD,MAAMA,GAGdf,IAYMiB,EAZmB,CACvB,IAAK,gBACL,IAAK,qBACL,IAAK,uBACL,IAAK,wBACL,IAAK,qBACL,IAAK,uBACL,IAAK,0BACL,IAAK,gBACL,IAAK,oBAG6BF,EAAMG,SAASC,SAAWJ,EAAMG,SAASD,WACvEG,EAAcL,EAAMG,SAASG,MAAQN,EAAMG,SAASG,KAAKD,YAC3DL,EAAMG,SAASG,KAAKD,YACpB,uFAEJ,OAAOE,KAAQP,EAAMG,SAAS,OAAM,IAAID,EAAcG,EAAa,UAGrEjB,GAAO,SAAIoB,EAAMC,GACfxB,IAAMK,EAAOF,KAAKE,KAAKoB,MAAMC,OAC7B,IAAKrB,EAAM,OAAOiB,KAAK,qBAAsB,kCAAmC,SAEhFtB,IAAMM,EAAOH,KAAKG,KAAKmB,MAAMC,OAC7B,IAAKpB,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G,WAAYJ,EAAMK,kBAI1B5C,KAAKD,MAAOC,KAAK+C,SAChB/C,KAAKkC","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 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 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.\\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"]} |