mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2024-12-13 16:06:21 +00:00
52d336cc45
No more enforced curly for if/else/for/while/do blocks w/ one statement. With that said, auto-fixed all JS files to follow the rule. I'd also like to apologize for the inconveniences this commit cause, after all it was me who intentionally enforced curly rule back then. Why the change of heart? After doing some more non-JS codes recently, I realized it was pretty stupid of me to enforce that.
67 lines
1.7 KiB
JavaScript
67 lines
1.7 KiB
JavaScript
/* global swal, axios */
|
|
|
|
const page = {
|
|
// user token
|
|
token: localStorage.token,
|
|
|
|
// HTML elements
|
|
user: null,
|
|
pass: null
|
|
}
|
|
|
|
page.do = function (dest) {
|
|
const user = page.user.value
|
|
const pass = page.pass.value
|
|
|
|
if (!user)
|
|
return swal('An error occurred!', 'You need to specify a username', 'error')
|
|
|
|
if (!pass)
|
|
return swal('An error occurred!', 'You need to specify a username', 'error')
|
|
|
|
axios.post(`api/${dest}`, {
|
|
username: user,
|
|
password: pass
|
|
}).then(function (response) {
|
|
if (response.data.success === false)
|
|
return swal('An error occurred!', response.data.description, 'error')
|
|
|
|
localStorage.token = response.data.token
|
|
window.location = 'dashboard'
|
|
}).catch(function (error) {
|
|
console.error(error)
|
|
return swal('An error occurred!', 'There was an error with the request, please check the console for more information.', 'error')
|
|
})
|
|
}
|
|
|
|
page.verify = function () {
|
|
if (!page.token) return
|
|
|
|
axios.post('api/tokens/verify', {
|
|
token: page.token
|
|
}).then(function (response) {
|
|
if (response.data.success === false)
|
|
return swal('An error occurred!', response.data.description, 'error')
|
|
|
|
window.location = 'dashboard'
|
|
}).catch(function (error) {
|
|
console.error(error)
|
|
return swal('An error occurred!', 'There was an error with the request, please check the console for more information.', 'error')
|
|
})
|
|
}
|
|
|
|
window.onload = function () {
|
|
page.verify()
|
|
|
|
page.user = document.getElementById('user')
|
|
page.pass = document.getElementById('pass')
|
|
|
|
document.getElementById('loginBtn').addEventListener('click', function () {
|
|
page.do('login')
|
|
})
|
|
|
|
document.getElementById('registerBtn').addEventListener('click', function () {
|
|
page.do('register')
|
|
})
|
|
}
|