mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2024-12-13 07:56:23 +00:00
616124446f
WARNING: Please turn off lolisafe before upgrading, then run "node database/migration.js" once after upgrading. Ignore all errors/warnings about duplicate column name. Afterwards make sure your config.js follows the new format in config.sample.js (specifically fileLength and generateThumbnails options). * generateImageThumbnails and generateVideoThumbnails options in config.js is now renamed to an object named generateThumbnails, with image and video as its properties. * fileLength option is now an object with min, max, default and userChangeable as its properties. * User may now change their preferred file length (following the previous option, of course). * Updated a bunch of responses messages. Mainly appending a dot to the messages. * New APIs: /fileLength/config to get an object of the current fileLength config (exactly what is in the config.js file). /fileLength/change to change user's preferred file length. * And maybe some others ...?
35 lines
1.1 KiB
JavaScript
35 lines
1.1 KiB
JavaScript
const config = require('../config.js')
|
|
const db = require('knex')(config.database)
|
|
const randomstring = require('randomstring')
|
|
const utils = require('./utilsController.js')
|
|
|
|
const tokenController = {}
|
|
|
|
tokenController.verify = async (req, res, next) => {
|
|
const token = req.body.token
|
|
if (token === undefined) return res.status(401).json({ success: false, description: 'No token provided.' })
|
|
|
|
const user = await db.table('users').where('token', token).first()
|
|
if (!user) return res.status(401).json({ success: false, description: 'Invalid token.' })
|
|
return res.json({ success: true, username: user.username })
|
|
}
|
|
|
|
tokenController.list = async (req, res, next) => {
|
|
const user = await utils.authorize(req, res)
|
|
return res.json({ success: true, token: user.token })
|
|
}
|
|
|
|
tokenController.change = async (req, res, next) => {
|
|
const user = await utils.authorize(req, res)
|
|
const newtoken = randomstring.generate(64)
|
|
|
|
await db.table('users').where('token', user.token).update({
|
|
token: newtoken,
|
|
timestamp: Math.floor(Date.now() / 1000)
|
|
})
|
|
|
|
res.json({ success: true, token: newtoken })
|
|
}
|
|
|
|
module.exports = tokenController
|