2016-08-04 16:32:36 -04:00
|
|
|
'use strict'
|
|
|
|
|
|
|
|
const logger = require('../helpers/logger')
|
|
|
|
|
|
|
|
const adminMiddleware = {
|
2016-10-02 06:19:02 -04:00
|
|
|
ensureIsAdmin
|
2016-08-04 16:32:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function ensureIsAdmin (req, res, next) {
|
|
|
|
const user = res.locals.oauth.token.user
|
2017-04-26 15:42:36 -04:00
|
|
|
if (user.isAdmin() === false) {
|
2016-08-04 16:32:36 -04:00
|
|
|
logger.info('A non admin user is trying to access to an admin content.')
|
|
|
|
return res.sendStatus(403)
|
|
|
|
}
|
|
|
|
|
|
|
|
return next()
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
module.exports = adminMiddleware
|