<commit_before>/**
 * Created by prism on 6/22/15.
 */

var express = require('express'),
    mongoose = require('mongoose'),
    manager = require('./models/manager'),
    bodyParser = require('body-parser');

incomeRoute = require('./routes/income')(manager);  // injecting manager model(s) :D impressive isn't it ?
initialAmount = require('./routes/initial')(manager);
loan = require('./routes/loan')(manager);

var app = express();


app.enable('trust proxy');
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
app.use('/api/income',incomeRoute);
app.use('/api/initial',initialAmount);
app.use('/api/loan',loan);

var port = process.env.PORT || 4000,
    db = mongoose.connect( process.env.DB || 'mongodb://localhost/hiren_expense');

<commit_msg>Added authentication middleware<commit_after>/**
 * Created by prism on 6/22/15.
 */

var express = require('express'),
    mongoose = require('mongoose'),
    manager = require('./models/manager'),
    user = require('./models/users'),
    bodyParser = require('body-parser'),
    jwt = require('jwt-simple'),
    moment = require('moment');

incomeRoute = require('./routes/income')(manager);  // injecting manager model(s) :D impressive isn't it ?
initialAmount = require('./routes/initial')(manager);
loan = require('./routes/loan')(manager);

var app = express();

/*
 |--------------------------------------------------------------------------
 | Login Required Middleware
 |--------------------------------------------------------------------------
 */
function ensureAuthenticated(req, res, next) {
    if (!req.headers.authorization) {
        return res.status(401).send({ message: 'Please make sure your request has an Authorization header' });
    }
    var token = req.headers.authorization.split(' ')[1];

    var payload = null;
    try {
        payload = jwt.decode(token, "some secret strings ? ;) , what about Hiren ? :P hehe ");
    }
    catch (err) {
        return res.status(401).send({ message: err.message });
    }

    if (payload.exp <= moment().unix()) {
        return res.status(401).send({ message: 'Token has expired' });
    }
    req.user = payload.sub;
    next();
}


app.enable('trust proxy');
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
app.use('/api/income',incomeRoute);
app.use('/api/initial',initialAmount);
app.use('/api/loan',loan);

var port = process.env.PORT || 4000,
    db = mongoose.connect( process.env.DB || 'mongodb://localhost/hiren_expense'),
    TOKEN_SECRET = process.env.TOKEN_SECRET || 'A hard to guess string';


{'fraction_non_alphanumeric': 0.2299961345187476, 'fraction_numerical': 0.010823347506764593, 'mean_word_length': 3.018633540372671, 'pattern_counts': {'":': 0, '<': 4, '<?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': '4946907', 'n_tokens_mistral': 799, 'n_tokens_neox': 754, 'n_words': 166}