<commit_before>var   user = require('./user')

exports.requireLogin = function (req, res, next) {
  if (!req.loggedIn) {
    if ( !req.headers['x-requested-with'] || req.headers['x-requested-with'] != "XMLHttpRequest" ){
      req.session.redirectTo=req.headers.referer||'/';
      res.redirect('/login');
    }else{
      req.session.redirectTo=req.headers.referer||'/';
      res.send(401);
      return;
    }
  }
  next();
};

exports.requireAdmin = function (req, res, next) {
  if (!req.loggedIn) {
    res.redirect('/login');
  }
  if ( !req.user.admin ){
    req.flash('error', 'And just where do you think you are going?');
    res.redirect('/');
  }
  next();
};




exports.everyauthBoot = function(everyauth, app){

  everyauth.everymodule
    .handleLogout( function (req, res) {
      app.mixpanel.track('Logged Out', {distinct_id: req.session.distinctId});
      delete req.session.redirectTo;
      req.logout();
      this.redirect(res, this.logoutRedirectPath());
    })
    .findUserById(function(userId, callback){
      User.findById(userId, function(err, user){
        callback(err, user);
      });
    });

  everyauth.twitter
    .consumerKey(app.config.COURSESHARK_TWITTER_CONSUMER_KEY)
    .consumerSecret(app.config.COURSESHARK_TWITTER_CONSUMER_SECRET)
    .findOrCreateUser(function(session, accessToken, accessTokenSecret, twitterUserData){
      var promise = this.Promise();
      user.findOrCreateTwitterData(twitterUserData, promise, session, app.mixpanel);
      return promise;
    })
    .sendResponse( function (res, data) {
      var session = data.session;
      var redirectTo = session.redirectTo||'/';
      delete session.redirectTo;
      res.redirect(redirectTo);
    })
    .redirectPath('/');

  everyauth.google
    .appId(app.config.COURSESHARK_GOOGLE_CLIENT_ID)
    .appSecret(app.config.COURSESHARK_GOOGLE_CLIENT_SECRET)<commit_msg>Logout response from server<commit_after>var   user = require('./user')

exports.requireLogin = function (req, res, next) {
  if (!req.loggedIn) {
    if ( !req.headers['x-requested-with'] || req.headers['x-requested-with'] != "XMLHttpRequest" ){
      req.session.redirectTo=req.headers.referer||'/';
      res.redirect('/login');
    }else{
      req.session.redirectTo=req.headers.referer||'/';
      res.send(401);
      return;
    }
  }
  next();
};

exports.requireAdmin = function (req, res, next) {
  if (!req.loggedIn) {
    res.redirect('/login');
  }
  if ( !req.user.admin ){
    req.flash('error', 'And just where do you think you are going?');
    res.redirect('/');
  }
  next();
};




exports.everyauthBoot = function(everyauth, app){

  everyauth.everymodule
    .handleLogout( function (req, res) {
      app.mixpanel.track('Logged Out', {distinct_id: req.session.distinctId});
      delete req.session.redirectTo;
      req.logout();
      res.json(1);
    })
    .findUserById(function(userId, callback){
      User.findById(userId, function(err, user){
        callback(err, user);
      });
    });

  everyauth.twitter
    .consumerKey(app.config.COURSESHARK_TWITTER_CONSUMER_KEY)
    .consumerSecret(app.config.COURSESHARK_TWITTER_CONSUMER_SECRET)
    .findOrCreateUser(function(session, accessToken, accessTokenSecret, twitterUserData){
      var promise = this.Promise();
      user.findOrCreateTwitterData(twitterUserData, promise, session, app.mixpanel);
      return promise;
    })
    .sendResponse( function (res, data) {
      var session = data.session;
      var redirectTo = session.redirectTo||'/';
      delete session.redirectTo;
      res.redirect(redirectTo);
    })
    .redirectPath('/');

  everyauth.google
    .appId(app.config.COURSESHARK_GOOGLE_CLIENT_ID)
    .appSecret(app.config.COURSESHARK_GOOGLE_CLIENT_SECRET)
{'fraction_non_alphanumeric': 0.14933333333333335, 'fraction_numerical': 0.0018666666666666666, 'mean_word_length': 3.392271662763466, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4970280', 'n_tokens_mistral': 1270, 'n_tokens_neox': 1238, 'n_words': 201}