From 143918fbb939d4b1fd1d0df5439957700dcce9ad Mon Sep 17 00:00:00 2001 From: Dennis Eriksen Date: Mon, 8 Apr 2013 10:42:28 +0200 Subject: started on dashboard --- router.js | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) (limited to 'router.js') diff --git a/router.js b/router.js index 4896474..cf774e0 100644 --- a/router.js +++ b/router.js @@ -30,6 +30,34 @@ module.exports = function(app) { }); + /* + * GET dashboard + * + * '/dashboard' + */ + + app.get('/dashboard', function(req, res) { + if (req.session.user == undefined) { + if (req.cookies.user == undefined || req.cookies.pass == undefined) { + res.redirect('/login'); + } else { + AM.autoLogin(req.cookies.user, req.cookies.pass, function(o) { + req.session.user = o; + res.redirect('/dashboard'); + }); + } + res.redirect('/login'); + } else { + if (req.cookies.user == undefined || req.cookies.pass == undefined) { + res.render('index', { title: 'waaaat' }); + } else { + res.render('index', { title: 'mordi' }); + } + } + }); + + + /* * GET login page * @@ -43,7 +71,7 @@ module.exports = function(app) { AM.autoLogin(req.cookies.user, req.cookies.pass, function(o) { if (o != null) { req.session.user = o; - res.redirect('/account'); + res.redirect('/dashboard'); } else { res.render('login', { title: 'Logg inn' }); } }); } @@ -58,11 +86,11 @@ module.exports = function(app) { res.send(e, 400); } else { req.session.user = o; - if (req.param('remember-me') == 'true') { - res.cookie('user', o.user, { maxAge: 900000 }); - res.cookieI('pass', o.pass, { maxAge: 90000 }); + if (req.param('remember-me') == 'on') { + res.cookie('user', o.user, { maxAge: 900000000 }); + res.cookie('pass', o.pass, { maxAge: 900000000 }); } - res.send(o, 200); + res.redirect('/dashboard'); } }); }); -- cgit v1.2.3