2018-01-23 20:06:30 +00:00
|
|
|
/* global swal, axios */
|
|
|
|
|
|
|
|
var page = {}
|
|
|
|
|
|
|
|
page.do = function (dest) {
|
|
|
|
var user = document.getElementById('user').value
|
|
|
|
var pass = document.getElementById('pass').value
|
|
|
|
|
|
|
|
if (user === undefined || user === null || user === '') {
|
|
|
|
return swal('Error', 'You need to specify a username', 'error')
|
|
|
|
}
|
|
|
|
if (pass === undefined || pass === null || pass === '') {
|
|
|
|
return swal('Error', 'You need to specify a username', 'error')
|
|
|
|
}
|
|
|
|
|
2018-01-24 15:31:23 +00:00
|
|
|
axios.post('api/' + dest, {
|
2018-01-23 20:06:30 +00:00
|
|
|
username: user,
|
|
|
|
password: pass
|
|
|
|
})
|
|
|
|
.then(function (response) {
|
|
|
|
if (response.data.success === false) {
|
|
|
|
return swal('Error', response.data.description, 'error')
|
|
|
|
}
|
|
|
|
|
|
|
|
localStorage.token = response.data.token
|
2018-01-24 15:31:23 +00:00
|
|
|
window.location = 'dashboard'
|
2018-01-23 20:06:30 +00:00
|
|
|
})
|
|
|
|
.catch(function (error) {
|
|
|
|
console.log(error)
|
2018-02-24 19:33:31 +00:00
|
|
|
return swal('An error occurred', 'There was an error with the request, please check the console for more information.', 'error')
|
2018-01-23 20:06:30 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
page.verify = function () {
|
|
|
|
page.token = localStorage.token
|
|
|
|
if (page.token === undefined) return
|
|
|
|
|
2018-01-24 15:31:23 +00:00
|
|
|
axios.post('api/tokens/verify', {
|
2018-01-23 20:06:30 +00:00
|
|
|
token: page.token
|
|
|
|
})
|
|
|
|
.then(function (response) {
|
|
|
|
if (response.data.success === false) {
|
|
|
|
return swal('Error', response.data.description, 'error')
|
|
|
|
}
|
|
|
|
|
2018-01-24 15:31:23 +00:00
|
|
|
window.location = 'dashboard'
|
2018-01-23 20:06:30 +00:00
|
|
|
})
|
|
|
|
.catch(function (error) {
|
|
|
|
console.log(error)
|
2018-02-24 19:33:31 +00:00
|
|
|
return swal('An error occurred', 'There was an error with the request, please check the console for more information.', 'error')
|
2018-01-23 20:06:30 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
window.onload = function () {
|
|
|
|
page.verify()
|
|
|
|
}
|