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

var db = {
  subscribers: [
    {
      subscriberId: 1,
      name: "<NAME>",
      email: "<EMAIL>",
      password: "<PASSWORD>"
    }
  ],
  sessions: [
    {
      sessionId: '123456',
      accessToken: 'asdfasdf',
      subscriberId: 2
    }
  ]
}

function subscriber_lookup(email) {
  var i;
  for(i = 0; i < db.subscribers.length; ++i) {
    if(db.subscribers[i].email == email)
      return db.subscribers[i];
  }
  return {};
}

function login(req, res, next) {
  var result;
  if(!req.body.email || !req.body.password) {
    res.writeHead(200, {
      'Content-Type': 'application/json'
    });
    res.end(JSON.stringify({
      error: {
      }
    }));
    return;
  }
  
  result = subscriber_lookup(req.body.email);
  if(!result.password || req.body.password != result.password) {
    res.writeHead(200, {
      'Content-Type': 'application/json'
    });
    res.end(JSON.stringify({
      error: {
      }
    }));
    return;
  }
  res.writeHead(200, {
    'Content-Type': 'application/json',
    'X-Access-Token': '<PASSWORD>'
  });
  res.end(JSON.stringify({
    success: {
    }
  }));
}

// login, login, register, verify, reset

var restModules = {
  subscriber : {
    noauth : {
      register : function(method, params, data) {
        return {
          success : {}
        };
      },
      verify : function(method, params, data) {
        return {
          success : {}
        };
      },
      reset : function(method, params, data) {
        return {
          success : {}
        };
      },
      login : function(method, params, data) {
        return {
          success : {}
        };
      }
    },
    auth : {
      logout : function(session, method, params, data) {
        return {
          success : {}
        };
      }
    }
  }
}

function lookupAccessToken(token) {
  var i;
  for(var i=0; i<db.sessions.length; ++i) {
    if(db.sessions[i].accessToken = accessToken)
      return db.session[i];
  }
  return null;
}

function wrapRes(res, result) {
  res.end(JSON.stringify(result));
}

module.exports = function(userDefinedModules) {
  return function(req, res, next) {
    var result;

    // grab the access token if it exists
    var accessToken = '';
    var session = null;
    if(req.headers['X-Access-Token']) {
      accessToken = req.headers['X-Access-Token'];
      session = lookupAccessToken(accessToken);
    }

    // respond to a bad url pathname
    var path = url.parse(req.url).pathname.split('/');<commit_msg>latest<commit_after>
var url = require('url');

var db = {
  subscribers: [
    {
      subscriberId: 1,
      name: "<NAME>",
      email: "<EMAIL>",
      password: "<PASSWORD>"
    }
  ],
  sessions: [
    {
      sessionId: '123456',
      accessToken: '<PASSWORD>',
      subscriberId: 2
    }
  ]
}

function subscriber_lookup(email) {
  var i;
  for(i = 0; i < db.subscribers.length; ++i) {
    if(db.subscribers[i].email == email)
      return db.subscribers[i];
  }
  return {};
}

function login(req, res, next) {
  var result;
  if(!req.body.email || !req.body.password) {
    res.writeHead(200, {
      'Content-Type': 'application/json'
    });
    res.end(JSON.stringify({
      error: {
      }
    }));
    return;
  }
  
  result = subscriber_lookup(req.body.email);
  if(!result.password || req.body.password != result.password) {
    res.writeHead(200, {
      'Content-Type': 'application/json'
    });
    res.end(JSON.stringify({
      error: {
      }
    }));
    return;
  }
  res.writeHead(200, {
    'Content-Type': 'application/json',
    'X-Access-Token': '<PASSWORD>'
  });
  res.end(JSON.stringify({
    success: {
    }
  }));
}

// login, login, register, verify, reset

var restModules = {
  subscriber : {
    noauth : {
      register : function(method, params, data) {
        return {
          success : {}
        };
      },
      verify : function(method, params, data) {
        return {
          success : {}
        };
      },
      reset : function(method, params, data) {
        return {
          success : {}
        };
      },
      login : function(method, params, data) {
        return {
          success : {}
        };
      }
    },
    auth : {
      logout : function(session, method, params, data) {
        return {
          success : {}
        };
      }
    }
  }
}

function lookupAccessToken(token) {
  var i;
  for(var i=0; i<db.sessions.length; ++i) {
    if(db.sessions[i].accessToken = accessToken)
      return db.session[i];
  }
  return null;
}

function wrapRes(res, result) {
  res.writeHead('200', {
    'Content-Type': 'application/json'
  });
  res.end(JSON.stringify(result));
}

module.exports = function(userDefinedModules) {
  return function(req, res, next) {
    var result;

    // grab the access token if it exists
    var accessToken = '';
    var session = null;
    if(req.headers['X-Access-Token']) {
      accessToken = req.headers['X-Access-Token'];
      session = lookupAccessToken(accessToken);
    }

    // respond to a bad url pathname
    var path = url.parse(req.url).pathname.split('/');
{'fraction_non_alphanumeric': 0.15889127464376343, 'fraction_numerical': 0.008003123170017569, 'mean_word_length': 2.111111111111111, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 12, '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': '1417822', 'n_tokens_mistral': 1736, 'n_tokens_neox': 1712, 'n_words': 324}