<commit_before>var passport = require('passport');

module.exports = {
    login: function(req, res, next) {
        var auth = passport.authenticate('local', function(err, user) {
            if (err) return next(err);
            if (!user) {
                res.send({success: false})
            }

            req.logIn(user, function(err) {
                if (err) return next(err);
                res.send({success: true, user: user});
            })
        });

        auth(req, res, next);
    },
    logout: function(req, res, next) {
        req.logout();
        res.redirect('/home');
    },
    isAuthenticated: function(req, res, next) {
        if (!req.isAuthenticated()) {
            res.status(403);
            res.end();
        }
        else {
            next();
        }
    },
    isInRole: function(role) {
        return function(req, res, next) {
            if (req.isAuthenticated() && req.user.roles.indexOf(role) > -1) {
                next();
            }
            else {
                res.status(403);
                res.end();
            }
        }
    }
}<commit_msg>updated auth to redirect unauthorized users<commit_after>var passport = require('passport');

module.exports = {
  login: function (req, res, next) {
    var auth = passport.authenticate('local', function (err, user) {
      if (err) return next(err);
      if (!user) {
        res.send({success: false})
      }

      req.logIn(user, function (err) {
        if (err) return next(err);
        res.send({success: true, user: user});
      })
    });

    auth(req, res, next);
  },
  logout: function (req, res, next) {
    req.logout();
    res.redirect('/home');
  },
  isAuthenticated: function (req, res, next) {
    if (!req.isAuthenticated()) {
      res.status(403);
      res.render('not-authorized', {
        title: 'Unauthorized'
      });
    }
    else {
      next();
    }
  },
  isInRole: function (role) {
    return function (req, res, next) {
      if (req.isAuthenticated() && req.user.roles.indexOf(role) > -1) {
        next();
      }
      else {
        res.status(403);
        res.render('not-authorized', {
          title: 'Unauthorized'
        });
      }
    }
  }
};
{'fraction_non_alphanumeric': 0.15706570657065708, 'fraction_numerical': 0.0063006300630063005, 'mean_word_length': 1.6945454545454546, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1749695', 'n_tokens_mistral': 707, 'n_tokens_neox': 680, 'n_words': 144}