<commit_before>var app = require('express')();
var http = require('http').Server(app);
var express = require('express');
var io = require('socket.io')(http);
var path = require('path');
var favicon = require('static-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var session = require('express-session');

var user = {};

var passport = require('passport')
  , TwitterStrategy = require('passport-twitter').Strategy;
app.use(session({ secret: 'SECRET' }));
app.use(passport.initialize());
app.use(passport.session());


passport.serializeUser(function(user, done) {
  done(null, user.id);
});

passport.deserializeUser(function(id, done) {
  done(null, user);
});

passport.use(new TwitterStrategy({
    consumerKey: '5WcVdkvcBv0FNjzelpsObRlEn',
    consumerSecret: '<KEY>',
    //callbackURL: "http://sochessJs.herokuapp.com/"
    callbackURL: "http://tests.sochessJs.com:5000/auth/twitter/callback"
  },
  function(token, tokenSecret, profile, done) {
		user.token=token;
		user.profile=profile;
		user.id = user.profile._json.screen_name;
    done(null, user);
    /*User.findOrCreate('', function(err, user) {
      if (err) { return done(err); }
      done(null, user);
    });*/
  }
));

app.get('/auth/twitter', passport.authenticate('twitter'));

app.get('/auth/twitter/callback', 
  passport.authenticate('twitter', { successRedirect: '/',
                                     failureRedirect: '/login' }));
//var redirect = require('express-redirect');


//redirect(app);
app.use(express.static(__dirname + '/public'));

app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');

app.use(bodyParser.json());
app.use(bodyParser.urlencoded());
app.use(cookieParser());

var un = 0;
var g = {
	complete:false
};

var loginR = function(player,room,user){
	for(var i in rooms){
		if(rooms[i].id === room){
			//console.log('room id: '+room);
			//console.log(rooms[i].id + ' = ' + room);
			if(rooms[i].players.length <= 1){
				rooms[i].players.push([player,user]);
			}
			return;
		}
	}
}

var roomName = function(query){
	for(var i in rooms){
		for(var j in rooms[i].players){
			if(rooms[i].players[j][0]===query){
				return rooms[i].id;
			}
		}
	}
}

var isConnected = function(player){
	for(var i in rooms){
		for(var j in rooms[i].players){
			if(rooms[i].players[j][0] === player){
				console.log('already connected');
				return true;
			}
		}
	}
	return false;
}

var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz';

var generateId = function(){
	var roomId = '';
	for(var i = 0; i<9;i++){
		roomId += chars.charAt(Math.floor(Math.random() * chars.length));
	}
	for(var i in rooms){
		if(rooms[i].id===roomId)
			generateId();
	}
	return roomId;
}

app.get('/user/:user',function(req,res){
	
});

app.get('/game/:gameId/user/:userId/player/:playerN',function(req,res){
	if(g.complete)
		res.redirect('/');
	if(un===2)
		g.complete = true;
	if(req.params.playerN > 2){
		res.sendStatus(403);
	}else{
		res.render('game');
	}
	io.on('connection', function(socket){
		socket.on('user_connected',function(m){
			if(!isConnected(socket.id)){
				loginR(socket.id,m.roomId,m.uname);
				socket.join(m.roomId);
			}
			if(m.player_number === '2'){
				io.to(m.roomId).emit('activation'+m.roomId,{});
			}
			//io.to(req.params.gameId).emit('sendo'+req.params.gameId,rooms);
		});
		socket.on('moved'+req.params.gameId,function(m){
			io.to(req.params.gameId).emit('move'+req.params.gameId,m);
		});
		// FOR CHECKMATE
		socket.on('cm'+req.params.gameId,function(m){
			io.to(req.params.gameId).emit('checkMate'+req.params.gameId,m);
		});
		socket.on('disconnect',function(){
			room_id = roomName(socket.id);
			deleteElement(room_id);
			io.to(room_id).emit('dcnt'+room_id,'dsº');
		});
		socket.on('user_disconnected'+req.params.gameId,function(m){
		});

	});

});

app.get('/',function(req,res){
	//res.sendFile(__dirname+'/index.html');
	console.log(user.id);	
	res.render('index',{id:user.id});
});
<commit_msg>handling sessions<commit_after>var app = require('express')();
var http = require('http').Server(app);
var express = require('express');
var io = require('socket.io')(http);
var path = require('path');
var favicon = require('static-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var session = require('express-session');

var user = {};

var passport = require('passport')
  , TwitterStrategy = require('passport-twitter').Strategy;
app.use(session({ secret: 'SECRET' }));
app.use(passport.initialize());
app.use(passport.session());


passport.serializeUser(function(user, done) {
  done(null, user.id);
});

passport.deserializeUser(function(id, done) {
  done(null, user);
});

passport.use(new TwitterStrategy({
    consumerKey: '<KEY>',
    consumerSecret: '<KEY>',
    //callbackURL: "http://sochessJs.herokuapp.com/"
    callbackURL: "http://tests.sochessJs.com:5000/auth/twitter/callback"
  },
  function(token, tokenSecret, profile, done) {
		user.token=token;
		user.profile=profile;
		user.id = user.profile._json.screen_name;
    done(null, user);
    /*User.findOrCreate('', function(err, user) {
      if (err) { return done(err); }
      done(null, user);
    });*/
  }
));

app.get('/auth/twitter', passport.authenticate('twitter'));

app.get('/auth/twitter/callback', 
  passport.authenticate('twitter', { successRedirect: '/',
                                     failureRedirect: '/login' }));
//var redirect = require('express-redirect');


//redirect(app);
app.use(express.static(__dirname + '/public'));

app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');

app.use(bodyParser.json());
app.use(bodyParser.urlencoded());
app.use(cookieParser());

var un = 0;
var g = {
	complete:false
};

var loginR = function(player,room,user){
	for(var i in rooms){
		if(rooms[i].id === room){
			//console.log('room id: '+room);
			//console.log(rooms[i].id + ' = ' + room);
			if(rooms[i].players.length <= 1){
				rooms[i].players.push([player,user]);
			}
			return;
		}
	}
}

var roomName = function(query){
	for(var i in rooms){
		for(var j in rooms[i].players){
			if(rooms[i].players[j][0]===query){
				return rooms[i].id;
			}
		}
	}
}

var isConnected = function(player){
	for(var i in rooms){
		for(var j in rooms[i].players){
			if(rooms[i].players[j][0] === player){
				console.log('already connected');
				return true;
			}
		}
	}
	return false;
}

var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz';

var generateId = function(){
	var roomId = '';
	for(var i = 0; i<9;i++){
		roomId += chars.charAt(Math.floor(Math.random() * chars.length));
	}
	for(var i in rooms){
		if(rooms[i].id===roomId)
			generateId();
	}
	return roomId;
}

app.get('/user/:user',function(req,res){
	
});

app.get('/game/:gameId/user/:userId/player/:playerN',function(req,res){
	var roomExistance = roomsExist(req.params.gameId);
	if(req.user && roomExistance){
	if(g.complete)
		res.redirect('/');
	if(un===2)
		g.complete = true;
	if(req.params.playerN > 2){
		res.sendStatus(403);
	}else{
		res.render('game');
	}
	io.on('connection', function(socket){
		socket.on('user_connected',function(m){
			if(!isConnected(socket.id)){
				loginR(socket.id,m.roomId,m.uname);
				socket.join(m.roomId);
			}
			if(m.player_number === '2'){
				io.to(m.roomId).emit('activation'+m.roomId,{});
			}
			//io.to(req.params.gameId).emit('sendo'+req.params.gameId,rooms);
		});
		socket.on('moved'+req.params.gameId,function(m){
			io.to(req.params.gameId).emit('move'+req.params.gameId,m);
		});
		// FOR CHECKMATE
		socket.on('cm'+req.params.gameId,function(m){
			io.to(req.params.gameId).emit('checkMate'+req.params.gameId,m);
		});
		socket.on('disconnect',function(){
			room_id = roomName(socket.id);
			deleteElement(room_id);
			io.to(room_id).emit('dcnt'+room_id,'dsº');
		});
		socket.on('user_disconnected'+req.params.gameId,function(m){
		});
	});
	}else{
		res.redirect('/auth/twitter');
	}
});

app.get('/',function(req,res){
	//res.sendFile(__dirname+'/index.html');
	
	if(req.user)	{
		res.render('index',{id:user.id});
	}else{
		res.redirect('/auth/twitter');
	}
});

{'fraction_non_alphanumeric': 0.20909420728020317, 'fraction_numerical': 0.006530414802273551, 'mean_word_length': 4.349288486416559, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '386631', 'n_tokens_mistral': 3275, 'n_tokens_neox': 3038, 'n_words': 448}