2017-06-10 22:15:25 +02:00
|
|
|
import 'express-validator'
|
|
|
|
import * as express from 'express'
|
|
|
|
|
2017-05-22 20:58:25 +02:00
|
|
|
import { logger } from '../helpers'
|
2016-08-04 22:32:36 +02:00
|
|
|
|
2017-06-10 22:15:25 +02:00
|
|
|
function ensureIsAdmin (req: express.Request, res: express.Response, next: express.NextFunction) {
|
2016-08-04 22:32:36 +02:00
|
|
|
const user = res.locals.oauth.token.user
|
2017-04-26 21:42:36 +02:00
|
|
|
if (user.isAdmin() === false) {
|
2016-08-04 22:32:36 +02:00
|
|
|
logger.info('A non admin user is trying to access to an admin content.')
|
|
|
|
return res.sendStatus(403)
|
|
|
|
}
|
|
|
|
|
|
|
|
return next()
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2017-05-15 22:22:03 +02:00
|
|
|
export {
|
|
|
|
ensureIsAdmin
|
|
|
|
}
|