<commit_before>module.exports = function(app){

  require('./api')(app);

  require('./provider')(app);

  app.post("/eman",function(req, res) { res.end("hello"); });

  app.get('/dbSync', require("./tools/dbSync"));

  app.get('/', index);

  app.post('/otp/validate', validateOTP);

  app.get('/dashboard', dashboard);

  app.post('/otp/validate', validateOTP);

  app.post('/login', login);

  app.get('/testSearch', function(req, res) {

    var path = require('path'), 
        coneedsAPI = require(path.resolve('./models/api'));

    var modelsPath = path.resolve('./models/orm');
    var User = require(path.join(modelsPath, '/user'))(req.db);

    User.searchProfessional('brown', function(err, data) {
      console.log(err, data);
    });

    res.send('test');
  });

}

var Q = require('q');
var path = require('path'),
    modelsPath = path.resolve('./models/orm');

var utilities = require(path.resolve('./libraries/g8labs/utilities'));
var config = utilities.config.load('config', 'config');
var configProvider = utilities.config.load('config', 'config-provider');
var globe = require(path.resolve('./libraries/providers/globe')+'/globeapi')();
var helperFunctions = utilities.helperFunctions;

var index = function(req, res) {

  var User = require(path.join(modelsPath, '/user'))(req.db);
  var iCode;

    // accommodate GET and POST or even invoice code passed
    if (req.body.code) {
      iCode = req.body.code;
    }

   if (!iCode) {
    iCode = req.query.code;
  } 

  if (!iCode) {
    iCode = req.params.code;
  }

  Q.ninvoke(User, 'find', {code: iCode})
  .then(function(users){
    if (users.length > 0 && users[0].otp_code) {
      res.render('index', {show_otp: true, code: iCode});
    } else {
      res.render('index', {show_otp: false, code: iCode});
    }
  })
  .fail(function(err){
    console.log(err);
     res.render('index', {show_otp: false, code: iCode});
  })
  
  
};

var validateOTP = function(req, res) {
  var User = require(path.join(modelsPath, '/user'))(req.db);
  var iCode, otpCode;
  // accommodate GET and POST or even invoice code passed
  if (req.body.code) {
    iCode = req.body.code;
  }

  otpCode = req.body.otp_code;

  if (!iCode) {
    iCode = req.query.code;
  } 

  if (!iCode) {
    iCode = req.params.code;
  }

  return Q.ninvoke(User, 'find', {code: iCode})
  .then(function(users){
    if (users.length > 0 && users[0].otp_code &&
      users[0].otp_code == otpCode) {
      // res.render('dashboard', {});
      req.session.user = users[0];
      res.redirect('/dashboard');
    } else {
      res.redirect('/?code='+iCode);
      // res.render('index', {show_otp: true, code: iCode});
    }
  })
  .fail(function(err){
    console.log(err);
    res.redirect('/?code='+iCode);
     // res.render('index', {show_otp: true, code: iCode});
  })
}

var dashboard = function(req, res) {
  console.log(req.session.user);
  res.render('dashboard', {});
}


var login = function(request, response) {
  var User = require(path.join(modelsPath, '/user'))(request.db);
  var subscriberNumber, code;

  var appShortCode = configProvider.globe.short_code; // full short code
  var appId = configProvider.globe.app_id; // application id
  var appSecret = configProvider.globe.app_secret; // application secret

  // Getting the login url
  var auth = globe.Auth(appId, appSecret);<commit_msg>pass user object to dashboard views<commit_after>module.exports = function(app){

  require('./api')(app);

  require('./provider')(app);

  app.post("/eman",function(req, res) { res.end("hello"); });

  app.get('/dbSync', require("./tools/dbSync"));

  app.get('/', index);

  app.post('/otp/validate', validateOTP);

  app.get('/dashboard', dashboard);

  app.post('/otp/validate', validateOTP);

  app.post('/login', login);

  app.get('/testSearch', function(req, res) {

    var path = require('path'), 
        coneedsAPI = require(path.resolve('./models/api'));

    var modelsPath = path.resolve('./models/orm');
    var User = require(path.join(modelsPath, '/user'))(req.db);

    User.searchProfessional('brown', function(err, data) {
      console.log(err, data);
    });

    res.send('test');
  });

}

var Q = require('q');
var path = require('path'),
    modelsPath = path.resolve('./models/orm');

var utilities = require(path.resolve('./libraries/g8labs/utilities'));
var config = utilities.config.load('config', 'config');
var configProvider = utilities.config.load('config', 'config-provider');
var globe = require(path.resolve('./libraries/providers/globe')+'/globeapi')();
var helperFunctions = utilities.helperFunctions;

var index = function(req, res) {

  var User = require(path.join(modelsPath, '/user'))(req.db);
  var iCode;

    // accommodate GET and POST or even invoice code passed
    if (req.body.code) {
      iCode = req.body.code;
    }

   if (!iCode) {
    iCode = req.query.code;
  } 

  if (!iCode) {
    iCode = req.params.code;
  }

  Q.ninvoke(User, 'find', {code: iCode})
  .then(function(users){
    if (users.length > 0 && users[0].otp_code) {
      res.render('index', {show_otp: true, code: iCode});
    } else {
      res.render('index', {show_otp: false, code: iCode});
    }
  })
  .fail(function(err){
    console.log(err);
     res.render('index', {show_otp: false, code: iCode});
  })
  
  
};

var validateOTP = function(req, res) {
  var User = require(path.join(modelsPath, '/user'))(req.db);
  var iCode, otpCode;
  // accommodate GET and POST or even invoice code passed
  if (req.body.code) {
    iCode = req.body.code;
  }

  otpCode = req.body.otp_code;

  if (!iCode) {
    iCode = req.query.code;
  } 

  if (!iCode) {
    iCode = req.params.code;
  }

  return Q.ninvoke(User, 'find', {code: iCode})
  .then(function(users){
    if (users.length > 0 && users[0].otp_code &&
      users[0].otp_code == otpCode) {
      // res.render('dashboard', {});
      req.session.user = users[0];
      res.redirect('/dashboard');
    } else {
      res.redirect('/?code='+iCode);
      // res.render('index', {show_otp: true, code: iCode});
    }
  })
  .fail(function(err){
    console.log(err);
    res.redirect('/?code='+iCode);
     // res.render('index', {show_otp: true, code: iCode});
  })
}

var dashboard = function(req, res) {
  res.render('dashboard', {user: req.session.user});
}

var login = function(request, response) {
  var User = require(path.join(modelsPath, '/user'))(request.db);
  var subscriberNumber, code;

  var appShortCode = configProvider.globe.short_code; // full short code
  var appId = configProvider.globe.app_id; // application id
  var appSecret = configProvider.globe.app_secret; // application secret

  // Getting the login url
  var auth = globe.Auth(appId, appSecret);
{'fraction_non_alphanumeric': 0.18830008931229533, 'fraction_numerical': 0.0020839535576064306, 'mean_word_length': 3.362987012987013, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '1823655', 'n_tokens_mistral': 2371, 'n_tokens_neox': 2286, 'n_words': 463}