Security.ts 671 B

123456789101112131415161718192021222324252627
  1. import {isUndefined} from "util";
  2. import {UserManager} from "../../manager/UserManager";
  3. export class Security {
  4. private static userManager;
  5. public static controlAccess(req, res, next) {
  6. //set global user if exist in session
  7. if (!isUndefined(req.session.user)) {
  8. res.locals.app = {};
  9. res.locals.app.user = req.session.user;
  10. }
  11. //if access secure
  12. if (req.originalUrl.search("member") != -1) {
  13. if (!isUndefined(req.session.user)) {
  14. next();
  15. } else {
  16. res.redirect("/login");
  17. }
  18. } else {
  19. next();
  20. }
  21. }
  22. }