<commit_before>//https://github.com/visionmedia/express-resource

var checkAuthServ = require('./services/authorisations/check');

function csrf(req, res, next) {
	res.locals.token = req.session._csrf;
	next();
}

function setViewVars(req, res, next) {
	console.log('setViewVars');

	res.locals.allowAdmin = false;
	res.locals.user = req.user;

	if (req.user) {
		checkAuthServ.run(req.user, 'suggestion', 'manage', function (err, val) {
			res.locals.allowAdmin = val;
			return next();
		});
	} else {
		//console.log('No user');
		return next();
	}
}

module.exports = function (app) {

	app.get('/', setViewVars, require('./controllers/web/videos').index);
	app.get('/about', setViewVars, require('./controllers/web/pages').about);
	
	app.get('/videos', setViewVars, require('./controllers/web/videos').index);
	app.get('/videos/new', csrf, setViewVars, require('./controllers/web/videos').new);
	app.get('/videos/:video', setViewVars, require('./controllers/web/videos').show);
	app.get('/videos/:video/edit', csrf, setViewVars, require('./controllers/web/videos').edit);

	app.namespace('/api/v1', function(){
		var videos =        require('./controllers/api/v1/videos');
		var suggestions =   require('./controllers/api/v1/suggestions');<commit_msg>changed name of res on route check auth<commit_after>//https://github.com/visionmedia/express-resource

var checkAuthServ = require('./services/authorisations/check');

function csrf(req, res, next) {
	res.locals.token = req.session._csrf;
	next();
}

function setViewVars(req, res, next) {
	console.log('setViewVars');

	res.locals.allowAdmin = false;
	res.locals.user = req.user;

	if (req.user) {
		checkAuthServ.run(req.user, 'video', 'manage', function (err, val) {
			res.locals.allowAdmin = val;
			return next();
		});
	} else {
		//console.log('No user');
		return next();
	}
}

module.exports = function (app) {

	app.get('/', setViewVars, require('./controllers/web/videos').index);
	app.get('/about', setViewVars, require('./controllers/web/pages').about);
	
	app.get('/videos', setViewVars, require('./controllers/web/videos').index);
	app.get('/videos/new', csrf, setViewVars, require('./controllers/web/videos').new);
	app.get('/videos/:video', setViewVars, require('./controllers/web/videos').show);
	app.get('/videos/:video/edit', csrf, setViewVars, require('./controllers/web/videos').edit);

	app.namespace('/api/v1', function(){
		var videos =        require('./controllers/api/v1/videos');
		var suggestions =   require('./controllers/api/v1/suggestions');
{'fraction_non_alphanumeric': 0.19976312672720095, 'fraction_numerical': 0.002368732727990525, 'mean_word_length': 4.461206896551724, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '3125014', 'n_tokens_mistral': 912, 'n_tokens_neox': 878, 'n_words': 142}