<commit_before>var express = require('express');
var Barc = require('barcode-generator');
var Ticket = require('../models/Ticket');
var User   = require('../models/User');
var _      = require('underscore');
var async  = require('async');
var i18n   = require('i18next');

module.exports = function (config) {
var router = express.Router();


function auth(req, res, next) {
  if (!req.user) {
    req.session.lastPage = req.path;
    req.flash('info', req.t('login.announcement.shielded', { page: req.path }));
    return res.redirect('/login');
  }
  next();
}

function adminAuth(req, res, next) {
  if (!req.user || !req.user.admin) {
    req.session.lastPage = req.path;
    req.flash('info', req.t('login.announcement.shielded', { page: req.path }));
    return res.redirect('/login');
  }
  next();
}

/* GET home page. */
router.get('/', function (req, res) {
  res.render('index', { title: 'AutonomIT', ticketSaleStarts:config.ticketSaleStarts });
});


/*router.get('/about', function (req,res) {
  res.render('about', {title: 'About'});
});*/


router.get('/partners', function (req,res) {
  res.render('partners',{title:'Partners'});
});

router.get('/partners/:partner', function (req, res) {
  res.render('partners/'+ req.params.partner, {title: 'Partners - ' + req.params.partner, path: '/partners'});
});

router.get('/profile', auth, function (req, res) {
  User.findOne({email:req.session.passport.user}, function (err,user) {
    if (!err && user)
    {
      res.render('profile', {isbus_quickhack: config.verenigingen[user.vereniging].bus});
    }
    else
    {
      req.flash('error', 'lolwtf');
      res.redirect('/profile');
    }
  });
});

router.get('/opensource',function (req,res) {
  res.render('opensource', {title:'Help het internet helpen'});
});

router.post('/profile', auth, function (req, res) {
  req.sanitize('vegetarian').toBoolean();
  req.sanitize('bus').toBoolean();

  if(req.body.lezing1 !== "" && req.body.lezing1 !== null &&req.body.lezing1 !== 'laurenz-eveleens' && req.body.lezing1 !== 'jan-smits'){
    req.flash('error', req.t('profile.announcement.error'));
    return res.redirect('/profile');
  }
  if(req.body.lezing2 !== "" && req.body.lezing2 !== null &&req.body.lezing2 !== 'mark-bakker' && req.body.lezing2 !== 'emile-nijssen'){
    req.flash('error', req.t('profile.announcement.error'));
    return res.redirect('/profile');
  }
  if(req.body.lezing3 !== "" && req.body.lezing3 !== null && req.body.lezing3 !== 'gert-jan-van-rootselaar' && req.body.lezing3 !== 'martijn-dashorst'){
    req.flash('error', req.t('profile.announcement.error'));
    return res.redirect('/profile');
  }

  User.findOne({email:req.session.passport.user}, function (err, user) {
    if (!err)
    {
      user.vegetarian = req.body.vegetarian ? true : false;
      user.bus        = req.body.bus ? true : false;
      user.specialNeeds = req.body.specialNeeds;
      user.lezing1 = req.body.lezing1;
      user.lezing2 = req.body.lezing2;
      user.lezing3 = req.body.lezing3;
      console.log(user.specialNeeds);
      user.save();
      req.flash('success', req.t('profile.announcement.saved'));
      res.redirect('/profile');
    }
    else
    {
      console.log(err);
      req.flash('error', req.t('profile.announcement.error'));
      res.redirect('/profile');
    }
  });

});

/*router.get('/location', function (req, res) {
  res.render('location', {title: 'Locatie'});
});*/

router.get('/busses', function (req, res) {
  res.render('busses', {title: 'Bussen'});
});

router.get('/speakers', function (req, res) {
  var s = config.speakers.filter(function(speaker){
    return !speaker.hidden;
  });
  var p = config.presenters.filter(function(presenter){
    return !presenter.hidden;
  });
  res.render('speakers', {title: 'Programma', speakers: s, presenters: p});
});

router.get('/speakers/:talk', function (req, res) {
  var s = config.speakers.filter(function(speaker){
    return (speaker.talk.replace(/\s/g, '-').replace('?', '').replace(':', '').replace('!', '').toLowerCase() === req.params.talk);
  })[0];

  if(!Boolean(s)){
    res.render('error', {message: 'Not found', error: {status: 404}});
    return;
  }

  res.render('speakers/talk', {path: '/speakers', speaker: s});
});


router.get('/partners/:partner', function (req, res) {
  res.render('partners/'+ req.params.partner, {title: 'Partners - ' + req.params.partner, path: '/partners'});
});

router.get('/organisation', function (req, res) {
  res.render('organisation', {title: 'Organisatie'});
});

router.get('/contact', function (req, res) {
  res.render('contact', {title: 'Contact'});
});

router.get('/mailing', function (req,res) {
  res.render('mailing');
});

router.get('/programme', function (req,res) {
  res.render('programme', {title:'Programma'});
});


router.get('/users', adminAuth, function (req,res,next) {
  var query = {};

  if (req.query.email) {
    query.email = { $regex: new RegExp(req.query.email, 'i') };
  }
  if (req.query.firstname) {
    query.firstname = { $regex: new RegExp(req.query.firstname, 'i') };
  }
  if (req.query.surname) {
    query.surname = { $regex: new RegExp(req.query.surname, 'i') };
  }
  if (req.query.vereniging) {
    query.vereniging = { $regex: new RegExp(req.query.vereniging, 'i') };
  }
  if (req.query.ticket) {
    query.ticket = { $regex: new RegExp(req.query.ticket, 'i') };
  }
  if (req.query.aanwezig) {
    query.aanwezig = { $regex: new RegExp(req.query.aanwezig, 'i') };
  }<commit_msg>add more links to programme<commit_after>var express = require('express');
var Barc = require('barcode-generator');
var Ticket = require('../models/Ticket');
var User   = require('../models/User');
var _      = require('underscore');
var async  = require('async');
var i18n   = require('i18next');

module.exports = function (config) {
var router = express.Router();


function auth(req, res, next) {
  if (!req.user) {
    req.session.lastPage = req.path;
    req.flash('info', req.t('login.announcement.shielded', { page: req.path }));
    return res.redirect('/login');
  }
  next();
}

function adminAuth(req, res, next) {
  if (!req.user || !req.user.admin) {
    req.session.lastPage = req.path;
    req.flash('info', req.t('login.announcement.shielded', { page: req.path }));
    return res.redirect('/login');
  }
  next();
}

/* GET home page. */
router.get('/', function (req, res) {
  res.render('index', { title: 'AutonomIT', ticketSaleStarts:config.ticketSaleStarts });
});


/*router.get('/about', function (req,res) {
  res.render('about', {title: 'About'});
});*/


router.get('/partners', function (req,res) {
  res.render('partners',{title:'Partners'});
});

router.get('/partners/:partner', function (req, res) {
  res.render('partners/'+ req.params.partner, {title: 'Partners - ' + req.params.partner, path: '/partners'});
});

router.get('/profile', auth, function (req, res) {
  User.findOne({email:req.session.passport.user}, function (err,user) {
    if (!err && user)
    {
      res.render('profile', {isbus_quickhack: config.verenigingen[user.vereniging].bus});
    }
    else
    {
      req.flash('error', 'lolwtf');
      res.redirect('/profile');
    }
  });
});

router.get('/opensource',function (req,res) {
  res.render('opensource', {title:'Help het internet helpen'});
});

router.post('/profile', auth, function (req, res) {
  req.sanitize('vegetarian').toBoolean();
  req.sanitize('bus').toBoolean();

  if(req.body.lezing1 !== "" && req.body.lezing1 !== null &&req.body.lezing1 !== 'laurenz-eveleens' && req.body.lezing1 !== 'jan-smits'){
    req.flash('error', req.t('profile.announcement.error'));
    return res.redirect('/profile');
  }
  if(req.body.lezing2 !== "" && req.body.lezing2 !== null &&req.body.lezing2 !== 'mark-bakker' && req.body.lezing2 !== 'emile-nijssen'){
    req.flash('error', req.t('profile.announcement.error'));
    return res.redirect('/profile');
  }
  if(req.body.lezing3 !== "" && req.body.lezing3 !== null && req.body.lezing3 !== 'gert-jan-van-rootselaar' && req.body.lezing3 !== 'martijn-dashorst'){
    req.flash('error', req.t('profile.announcement.error'));
    return res.redirect('/profile');
  }

  User.findOne({email:req.session.passport.user}, function (err, user) {
    if (!err)
    {
      user.vegetarian = req.body.vegetarian ? true : false;
      user.bus        = req.body.bus ? true : false;
      user.specialNeeds = req.body.specialNeeds;
      user.lezing1 = req.body.lezing1;
      user.lezing2 = req.body.lezing2;
      user.lezing3 = req.body.lezing3;
      console.log(user.specialNeeds);
      user.save();
      req.flash('success', req.t('profile.announcement.saved'));
      res.redirect('/profile');
    }
    else
    {
      console.log(err);
      req.flash('error', req.t('profile.announcement.error'));
      res.redirect('/profile');
    }
  });

});

/*router.get('/location', function (req, res) {
  res.render('location', {title: 'Locatie'});
});*/

router.get('/busses', function (req, res) {
  res.render('busses', {title: 'Bussen'});
});

router.get('/speakers', function (req, res) {
  var s = config.speakers.filter(function(speaker){
    return !speaker.hidden;
  });
  var p = config.presenters.filter(function(presenter){
    return !presenter.hidden;
  });
  res.render('speakers', {title: 'Programma', speakers: s, presenters: p});
});

router.get('/speakers/:talk', function (req, res) {
  var s = config.speakers.filter(function(speaker){
    return (speaker.talk.replace(/\s/g, '-').replace('?', '').replace(':', '').replace('!', '').toLowerCase() === req.params.talk);
  })[0];

  if(!Boolean(s)){
    res.render('error', {message: 'Not found', error: {status: 404}});
    return;
  }

  res.render('speakers/talk', {path: '/speakers', speaker: s});
});


router.get('/partners/:partner', function (req, res) {
  res.render('partners/'+ req.params.partner, {title: 'Partners - ' + req.params.partner, path: '/partners'});
});

router.get('/organisation', function (req, res) {
  res.render('organisation', {title: 'Organisatie'});
});

router.get('/contact', function (req, res) {
  res.render('contact', {title: 'Contact'});
});

router.get('/mailing', function (req,res) {
  res.render('mailing');
});

router.get('/programme', function (req,res) {
  res.render('programme', {title:'Programma'});
});

router.get('/program', function (req,res) {
  res.render('programme', {title:'Programma'});
});
router.get('/schedule', function (req,res) {
  res.render('programme', {title:'Programma'});
});
router.get('/dagprogramma', function (req,res) {
  res.render('programme', {title:'Programma'});
});
router.get('/programma', function (req,res) {
  res.render('programme', {title:'Programma'});
});

router.get('/users', adminAuth, function (req,res,next) {
  var query = {};

  if (req.query.email) {
    query.email = { $regex: new RegExp(req.query.email, 'i') };
  }
  if (req.query.firstname) {
    query.firstname = { $regex: new RegExp(req.query.firstname, 'i') };
  }
  if (req.query.surname) {
    query.surname = { $regex: new RegExp(req.query.surname, 'i') };
  }
  if (req.query.vereniging) {
    query.vereniging = { $regex: new RegExp(req.query.vereniging, 'i') };
  }
  if (req.query.ticket) {
    query.ticket = { $regex: new RegExp(req.query.ticket, 'i') };
  }
  if (req.query.aanwezig) {
    query.aanwezig = { $regex: new RegExp(req.query.aanwezig, 'i') };
  }
{'fraction_non_alphanumeric': 0.21976478848516764, 'fraction_numerical': 0.004563805511672811, 'mean_word_length': 3.880085653104925, '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': '3047769', 'n_tokens_mistral': 4096, 'n_tokens_neox': 4057, 'n_words': 688}