<commit_before>var sys = require("sys"),
my_http = require("http"),
path = require("path"),
url = require("url");
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var cookieParser = require('cookie-parser');
var session = require('express-session');

var Firebase = require("firebase")
var WebSocketServer = require('websocket').server;
var reqobj = require("request")

var fb = new Firebase("improvplusplus.firebaseIO.com");
var sessionStore = new session.MemoryStore();

var server = my_http.createServer(app).listen(3000,'0.0.0.0');

wsServer = new WebSocketServer({
    httpServer: server

    var users = fb.child("users");
    users.set({
	PatrickPistor:{
	    Password: "password"
	},
	ChrisTran:{
	    Password: "password"
	},
	KevinKong:{
	    Password: "password"
	}
    })
});

var history = [];
var clients = [];
var num_msgs = 0;

app.use(bodyParser.urlencoded());
app.use(cookieParser());
app.use(session({
    store: sessionStore,
    secret: 'keyboard cat'
}));

var sess;

app.post('/login', function(req, res) {
    var info = {};
    info['username'] = req.body.username;
    info['password'] = req.body.password;

    var auth = fb.child("users").child(req.body.username).on("value", function(snapshot)) {
        if (snapshot.val() === req.body.password) {
            info['loginStatus'] = 'OK';
	    req.session.user_id = req.body.username;
	    res.send(JSON.stringify(info));
        }
        else {
	    info['loginStatus'] = 'notFound';
            res.status(404).send(JSON.stringify(info));
	}
    }, function (errorObject) {
	var info = {};
	info['loginStatus'] = 'notFound';
	res.status(404).send(JSON.stringify(info));   
    }
});

app.get('/get/username', function(req, res) {
    console.log(req.sessionID);
    sessionStore.get(req.sessionID, function(error, session) {
        if(!session.user_id) {
            res.status(404).send(JSON.stringify({"status":404}));
        } else {
            res.send(JSON.stringify({"username":session.user_id}))
        }
    });

});

app.use('/', express.static('public'));

wsServer.on('request', function(request) {
    var connection = request.accept(null, request.origin);
    var index = clients.push(connection) - 1;
    var username = false;
    var result = false;

    connection.on('message', function(message) {
        if(message.type === 'utf8') {
            var obj = message.utf8Data;
            var json_msg = JSON.parse(obj);
            username = json_msg.username;
	
	    //get number of messages
	    fb.child("num_msgs").on("value", function(snapshot) {
		num_msgs = snapshot.val();
	    }, 
	    function (errorObject) {<commit_msg>log the session<commit_after>var sys = require("sys"),
my_http = require("http"),
path = require("path"),
url = require("url");
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var cookieParser = require('cookie-parser');
var session = require('express-session');

var Firebase = require("firebase")
var WebSocketServer = require('websocket').server;
var reqobj = require("request")

var fb = new Firebase("improvplusplus.firebaseIO.com");
var sessionStore = new session.MemoryStore();

var server = my_http.createServer(app).listen(3000,'0.0.0.0');

wsServer = new WebSocketServer({
    httpServer: server

    var users = fb.child("users");
    users.set({
	PatrickPistor:{
	    Password: "password"
	},
	ChrisTran:{
	    Password: "password"
	},
	KevinKong:{
	    Password: "password"
	}
    })
});

var history = [];
var clients = [];
var num_msgs = 0;

app.use(bodyParser.urlencoded());
app.use(cookieParser());
app.use(session({
    store: sessionStore,
    secret: 'keyboard cat'
}));

var sess;

app.post('/login', function(req, res) {
    var info = {};
    info['username'] = req.body.username;
    info['password'] = <PASSWORD>;

    var auth = fb.child("users").child(req.body.username).on("value", function(snapshot)) {
        if (snapshot.val() === req.body.password) {
            info['loginStatus'] = 'OK';
	    req.session.user_id = req.body.username;
	    res.send(JSON.stringify(info));
        }
        else {
	    info['loginStatus'] = 'notFound';
            res.status(404).send(JSON.stringify(info));
	}
    }, function (errorObject) {
	var info = {};
	info['loginStatus'] = 'notFound';
	res.status(404).send(JSON.stringify(info));   
    }
});

app.get('/get/username', function(req, res) {
    sessionStore.get(req.sessionID, function(error, session) {
        console.log(session);
        if(!session.user_id) {
            res.status(404).send(JSON.stringify({"status":404}));
        } else {
            res.send(JSON.stringify({"username":session.user_id}))
        }
    });

});

app.use('/', express.static('public'));

wsServer.on('request', function(request) {
    var connection = request.accept(null, request.origin);
    var index = clients.push(connection) - 1;
    var username = false;
    var result = false;

    connection.on('message', function(message) {
        if(message.type === 'utf8') {
            var obj = message.utf8Data;
            var json_msg = JSON.parse(obj);
            username = json_msg.username;
	
	    //get number of messages
	    fb.child("num_msgs").on("value", function(snapshot) {
		num_msgs = snapshot.val();
	    }, 
	    function (errorObject) {
{'fraction_non_alphanumeric': 0.17453798767967146, 'fraction_numerical': 0.00896023893970506, 'mean_word_length': 3.3490259740259742, 'pattern_counts': {'":': 4, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '587697', 'n_tokens_mistral': 1760, 'n_tokens_neox': 1681, 'n_words': 326}