2019-04-24 21:01:54 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
2019-04-25 09:25:33 +00:00
|
|
|
const passport = require('passport');
|
2019-05-09 16:23:54 +00:00
|
|
|
const httpStatus = require('http-status');
|
|
|
|
|
const compose = require('../helpers/middleware.helper');
|
2019-04-24 21:01:54 +00:00
|
|
|
|
2019-06-21 08:40:28 +00:00
|
|
|
const isRegisteredUserEmail = passport.authenticate('local-email', { session: false });
|
|
|
|
|
const isRegisteredUserPhone = passport.authenticate('local-phone', { session: false });
|
2019-05-09 16:23:54 +00:00
|
|
|
const isLoggedUser = passport.authenticate('jwt', { session: false });
|
|
|
|
|
const isAdministratorUser = compose([isLoggedUser,
|
|
|
|
|
(req, res, next) => {
|
|
|
|
|
const user = req.user;
|
|
|
|
|
if (user.role >= 8) {
|
|
|
|
|
next();
|
|
|
|
|
} else {
|
|
|
|
|
return res.status(httpStatus.UNAUTHORIZED).send('UNAUTHORIZED');
|
|
|
|
|
}
|
2019-04-24 21:01:54 +00:00
|
|
|
}
|
2019-05-09 16:23:54 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
module.exports = {
|
2019-06-21 08:40:28 +00:00
|
|
|
isRegisteredUserEmail,
|
|
|
|
|
isRegisteredUserPhone,
|
2019-05-09 16:23:54 +00:00
|
|
|
isLoggedUser,
|
|
|
|
|
isAdministratorUser
|
2019-04-24 21:01:54 +00:00
|
|
|
};
|