You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
819 B

  1. "use strict";
  2. var Promise = require('bluebird'),
  3. moment = require('moment-timezone');
  4. /**
  5. * Authentication middleware
  6. *
  7. * @param {Express Request} req Express Request object
  8. * @param {Express Response} res Express Response object
  9. * @param {Function} next Next callback function
  10. * @return {any} void
  11. */
  12. module.exports = (req, res, next) => {
  13. // Is user authenticated ?
  14. if (!req.isAuthenticated()) {
  15. return res.redirect('/login');
  16. }
  17. // Check permissions
  18. if(!rights.check(req, 'read')) {
  19. return res.render('error-forbidden');
  20. }
  21. // Set i18n locale
  22. req.i18n.changeLanguage(req.user.lang);
  23. res.locals.userMoment = moment;
  24. res.locals.userMoment.locale(req.user.lang);
  25. // Expose user data
  26. res.locals.user = req.user;
  27. return next();
  28. };