var express = require('express');
var config = require('config');
var db = require('./db')();
var session = require('express-session');
var MongoStore = require('connect-mongo')(session);
var app = express();

app.set('trust proxy', 1);
app.set('view engine', 'jade');

app.locals.pretty = true;
app.locals.domain = config.domain;

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

app.use(session({
	name: 'session',
	secret: 'foo',
	resave: false,
	saveUninitialized: true,
    store: new MongoStore({ mongooseConnection: db })
}));

app.use(function (req, res, next) {
	res.locals.ip = req.connection.remoteAddress;
	res.locals.loggedIn = req.session.loggedIn || false;

	next();
});

app.get('/', function (req, res) {
	//req.session.user = 'Demo';
	res.render('index', { title: 'localdns.in', user: req.session.user });
});

app.get('/login', function (req, res) {
    res.render('login', { title: 'Login' });
});

module.exports = app;

@@ -87,16 +87,53 @@
 db')();%0A
+var User = require('./models/user');%0A
 var sess
@@ -162,24 +162,24 @@
 -session');%0A
-
 var MongoSto
@@ -742,16 +742,17 @@
 s) %7B%0A%09//
+ 
 req.sess
@@ -759,21 +759,70 @@
 ion.
-user = 'Demo'
+email = 'mat.lomax@gmail.com';%0A%09// req.session.loggedIn = true
 ;%0A%09r
@@ -936,16 +936,16 @@
  res) %7B%0A
-
     res.
@@ -986,16 +986,370 @@
 );%0A%7D);%0A%0A
+app.get('/update', function (req, res) %7B%0A    if (!res.locals.loggedIn) %7B%0A%09%09res.sendStatus(403);%0A%09%09return res.end();%0A%09%7D%0A%0A%09var user = User.findOne(%7B email: req.session.email %7D, function (err, doc) %7B%0A%09%09if (!err && doc) %7B%0A%09%09%09doc.ip = res.locals.ip;%0A%09%09%09doc.save();%0A%09%09%09res.sendStatus(204);%0A%09%09%7D else %7B%0A%09%09%09res.sendStatus(404);%0A%09%09%7D%0A%0A%09%09return res.end();%0A%09%7D);%0A%7D);%0A%0A
 module.e

Add update endpoint