mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2024-12-13 16:06:21 +00:00
05b905bc9b
Upgraded dependencies. Stop adding cache-control header to album zip files unless config.cacheControl is enabled. Updated CSS files. Moved thumbnail-related styling to thumbs.css. Various other fixes & improvements. Moved render.js from public/js to public/js/s. Removed sharex.js in favor of public/js/s/utils.js. Moved getPrettyDate() & getPrettyBytes() to that JS file as well. Added lsKeys global variable wherever applicable. Previously the idea was only used in dashboard.js. Added No-JS version of album public pages. You'll only have to add ?nojs to the URL. Viewing the regular version with JS disabled will show a notice with a link to the No-JS version of the particular album. Overall page size of the regular version will now be lower as well, since there'll be no need to add noscript tag for each thumbs. No longer show Administrator section to non-admin in the dashboard. Moderators will ONLY be able to see manage users menu as well. Simplified FAQ wherever applicable. Added a new FAQ about bug report or feature request. Updated link for Firefox extension. Also pushed Firefox link before Chrome, cause I like it more. Added browser settings menu to dashboard. This allows you to choose file size unit (kilobyte vs kibibyte) for that specific browser. The preference will be used on homepage, dashboard and album pages. This also allows you to set chunk size and maximum parallel uploads for the homepage uploader. All menu links in the dashboard will now scroll to the content once loaded. Previously it would only do so with manage uploads/users when switching pages. Refactored all instances of for-in & for-of loop from browser JS files. For the sake of uniformity, for now.
79 lines
2.1 KiB
JavaScript
79 lines
2.1 KiB
JavaScript
/* global swal, axios */
|
|
|
|
const lsKeys = {
|
|
token: 'token'
|
|
}
|
|
|
|
const page = {
|
|
// user token
|
|
token: localStorage[lsKeys.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 password.', 'error')
|
|
|
|
axios.post(`api/${dest}`, {
|
|
username: user.trim(),
|
|
password: pass.trim()
|
|
}).then(function (response) {
|
|
if (response.data.success === false)
|
|
return swal(`Unable to ${dest}!`, 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.log(error)
|
|
const description = error.response.data && error.response.data.description
|
|
? error.response.data.description
|
|
: 'There was an error with the request, please check the console for more information.'
|
|
return swal(`${error.response.status} ${error.response.statusText}`, description, 'error')
|
|
})
|
|
}
|
|
|
|
window.onload = function () {
|
|
page.verify()
|
|
|
|
page.user = document.querySelector('#user')
|
|
page.pass = document.querySelector('#pass')
|
|
|
|
// Prevent default form's submit action
|
|
document.querySelector('#authForm').addEventListener('submit', function (event) {
|
|
event.preventDefault()
|
|
})
|
|
|
|
document.querySelector('#loginBtn').addEventListener('click', function () {
|
|
page.do('login')
|
|
})
|
|
|
|
document.querySelector('#registerBtn').addEventListener('click', function () {
|
|
page.do('register')
|
|
})
|
|
}
|