[refactoring] settings middleware
This commit is contained in:
@@ -5,6 +5,17 @@ const path = require('path')
|
||||
const fs = require('fs')
|
||||
const package = require('../../../package.json')
|
||||
|
||||
/**
|
||||
* Settings controller: store instance settings
|
||||
* Current supported settings:
|
||||
*
|
||||
*
|
||||
* Usage:
|
||||
* backend/fediverse/api:
|
||||
*
|
||||
* frontend:
|
||||
*/
|
||||
|
||||
const settingsController = {
|
||||
settings: { initialized: false },
|
||||
user_locale: {},
|
||||
|
||||
@@ -24,19 +24,21 @@ api.use(bodyParser.json())
|
||||
const jwt = expressJwt({
|
||||
secret: config.secret,
|
||||
credentialsRequired: false,
|
||||
getToken: function fromHeaderOrQuerystring (req) {
|
||||
if (req.headers.authorization && req.headers.authorization.split(' ')[0] === 'Bearer') {
|
||||
return req.headers.authorization.split(' ')[1]
|
||||
} else if (req.cookies && req.cookies['auth._token.local']) {
|
||||
const [ prefix, token ] = req.cookies['auth._token.local'].split(' ')
|
||||
if (prefix === 'Bearer') { return token }
|
||||
}
|
||||
}
|
||||
// getToken: function fromHeaderOrQuerystring (req) {
|
||||
// if (req.headers.authorization && req.headers.authorization.split(' ')[0] === 'Bearer') {
|
||||
// return req.headers.authorization.split(' ')[1]
|
||||
// } else if (req.cookies && req.cookies['auth._token.local']) {
|
||||
// const [ prefix, token ] = req.cookies['auth._token.local'].split(' ')
|
||||
// if (prefix === 'Bearer') { return token }
|
||||
// }
|
||||
// }
|
||||
})
|
||||
|
||||
// api.use(jwt)
|
||||
|
||||
// AUTH
|
||||
api.post('/auth/login', userController.login)
|
||||
api.get('/auth/user', jwt, fillUser, userController.current)
|
||||
api.get('/auth/user', fillUser, userController.current)
|
||||
|
||||
api.post('/user/recover', userController.forgotPassword)
|
||||
api.post('/user/check_recover_code', userController.checkRecoverCode)
|
||||
@@ -44,56 +46,56 @@ api.post('/user/recover_password', userController.updatePasswordWithRecoverCode)
|
||||
|
||||
// register and add users
|
||||
api.post('/user/register', userController.register)
|
||||
api.post('/user', jwt, isAuth, isAdmin, userController.create)
|
||||
api.post('/user', isAuth, isAdmin, userController.create)
|
||||
|
||||
// update user
|
||||
api.put('/user', jwt, isAuth, userController.update)
|
||||
api.put('/user', isAuth, userController.update)
|
||||
|
||||
// delete user
|
||||
api.delete('/user/:id', jwt, isAuth, isAdmin, userController.remove)
|
||||
api.delete('/user/:id', isAuth, isAdmin, userController.remove)
|
||||
|
||||
//
|
||||
// api.delete('/user', userController.remove)
|
||||
|
||||
// get all users
|
||||
api.get('/users', jwt, isAuth, isAdmin, userController.getAll)
|
||||
api.get('/users', isAuth, isAdmin, userController.getAll)
|
||||
|
||||
// update a tag (modify color)
|
||||
api.put('/tag', jwt, isAuth, isAdmin, eventController.updateTag)
|
||||
api.put('/tag', isAuth, isAdmin, eventController.updateTag)
|
||||
|
||||
// update a place (modify address..)
|
||||
api.put('/place', jwt, isAuth, isAdmin, eventController.updatePlace)
|
||||
api.put('/place', isAuth, isAdmin, eventController.updatePlace)
|
||||
|
||||
// add event
|
||||
api.post('/user/event', jwt, fillUser, upload.single('image'), userController.addEvent)
|
||||
api.post('/user/event', fillUser, upload.single('image'), userController.addEvent)
|
||||
|
||||
// update event
|
||||
api.put('/user/event', jwt, isAuth, upload.single('image'), userController.updateEvent)
|
||||
api.put('/user/event', isAuth, upload.single('image'), userController.updateEvent)
|
||||
|
||||
// remove event
|
||||
api.delete('/user/event/:id', jwt, isAuth, userController.delEvent)
|
||||
api.delete('/user/event/:id', isAuth, userController.delEvent)
|
||||
|
||||
// get tags/places
|
||||
api.get('/event/meta', eventController.getMeta)
|
||||
|
||||
// get unconfirmed events
|
||||
api.get('/event/unconfirmed', jwt, isAuth, isAdmin, eventController.getUnconfirmed)
|
||||
api.get('/event/unconfirmed', isAuth, isAdmin, eventController.getUnconfirmed)
|
||||
|
||||
// add event notification
|
||||
api.post('/event/notification', eventController.addNotification)
|
||||
api.delete('/event/notification/:code', eventController.delNotification)
|
||||
|
||||
api.get('/settings', settingsController.getAllRequest)
|
||||
api.post('/settings', jwt, fillUser, isAdmin, settingsController.setRequest)
|
||||
api.post('/settings', fillUser, isAdmin, settingsController.setRequest)
|
||||
|
||||
api.get('/settings/user_locale', settingsController.getUserLocale)
|
||||
|
||||
// confirm event
|
||||
api.get('/event/confirm/:event_id', jwt, isAuth, isAdmin, eventController.confirm)
|
||||
api.get('/event/unconfirm/:event_id', jwt, isAuth, isAdmin, eventController.unconfirm)
|
||||
api.get('/event/confirm/:event_id', isAuth, isAdmin, eventController.confirm)
|
||||
api.get('/event/unconfirm/:event_id', isAuth, isAdmin, eventController.unconfirm)
|
||||
|
||||
// get event
|
||||
api.get('/event/:event_id', jwt, fillUser, eventController.get)
|
||||
api.get('/event/:event_id', fillUser, eventController.get)
|
||||
|
||||
// export events (rss/ics)
|
||||
api.get('/export/:type', exportController.export)
|
||||
|
||||
Reference in New Issue
Block a user