mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2024-12-15 17:06:22 +00:00
1981159805
Better solution for #215 Bumped v1 version string and rebuilt client asset
1 line
6.0 KiB
Plaintext
1 line
6.0 KiB
Plaintext
{"version":3,"sources":["auth.js"],"names":["const","lsKeys","token","page","localStorage","user","pass","unhide","loaderSection","document","querySelector","classList","add","loginSection","remove","floatingBtn","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","addEventListener","form","event","preventDefault","loginBtn","checkValidity","currentTarget","registerBtn","click"],"mappings":"AAEAA,IAAMC,OAAS,CACbC,MAAO,SAGHC,KAAO,CAEXD,MAAOE,aAAaH,OAAOC,OAG3BG,KAAM,KACNC,KAAM,KAGRC,OAAW,WACTP,IAAMQ,EAAgBC,SAASC,cAAc,WACzCF,GACFA,EAAcG,UAAUC,IAAI,aAE9BZ,IAAMa,EAAeJ,SAASC,cAAc,oBACxCG,GACFA,EAAaF,UAAUG,OAAO,aAEhCd,IAAMe,EAAcN,SAASC,cAAc,mCACvCK,GACFA,EAAYJ,UAAUG,OAAO,cAIjCE,aAAiB,SAAGC,GAClBC,QAAQD,MAAMA,GAGdjB,IAYMmB,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,UAGrEG,GAAO,SAAIC,EAAMC,GACfpC,IAAMK,EAAOF,KAAKE,KAAKgC,MAAMC,OAC7B,IAAKjC,EACH,OAAO4B,KAAK,qBAAsB,kCAAmC,S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pD,KAAKD,MACPC,KAAK6C,SAEL7C,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 const loaderSection = document.querySelector('#loader')\n if (loaderSection)\n loaderSection.classList.add('is-hidden')\n\n const loginSection = document.querySelector('#login.is-hidden')\n if (loginSection)\n loginSection.classList.remove('is-hidden')\n\n const floatingBtn = document.querySelector('.floating-home-button.is-hidden')\n if (floatingBtn)\n 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, 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.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 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 page.do('register', event.currentTarget)\n })\n\n if (page.token)\n page.verify()\n else\n page.unhide()\n})\n"]} |