filesafe/public/js/auth.js
Bobby Wibowo 0067c8fe83
Updates
* Refactored all instances of "err" into "error".

* Added bulk delete feature (API route: /api/uploads/bulkdelete). It accepts an array of IDs (its key must be "ids" in the JSON POST request). Don't forget it still requires a token in the headers. (https://s.fiery.me/6rjMAYoC.mp4)

* Removed fontello.css from auth.html.

* Updated a bunch of styling.

* Added "copy link to clipboard" button to thumbs view.

* Added "view thumbnail" button to list view. Clicking the row will no longer trigger thumb view, instead you have to press that button.

* Updated icons.

* ... and perhaps some others that I can't remember?
2018-03-30 06:22:08 +07:00

65 lines
1.7 KiB
JavaScript

/* global swal, axios */
const page = {}
page.do = dest => {
const user = document.getElementById('user').value
const 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')
}
axios.post('api/' + dest, {
username: user,
password: pass
})
.then(response => {
if (response.data.success === false) {
return swal('Error', response.data.description, 'error')
}
localStorage.token = response.data.token
window.location = 'dashboard'
})
.catch(error => {
console.log(error)
return swal('An error occurred', 'There was an error with the request, please check the console for more information.', 'error')
})
}
page.onkeypress = function (event, element) {
event = event || window.event
if (!event) { return }
if (event.keyCode === 13 || event.which === 13) {
return this.do('login')
}
}
page.verify = () => {
page.token = localStorage.token
if (page.token === undefined) { return }
axios.post('api/tokens/verify', {
token: page.token
})
.then(response => {
if (response.data.success === false) {
return swal('Error', response.data.description, 'error')
}
window.location = 'dashboard'
})
.catch(error => {
console.log(error)
return swal('An error occurred', 'There was an error with the request, please check the console for more information.', 'error')
})
}
window.onload = () => {
page.verify()
}