From 652a9ef7a3a3f1f0672922af2af93c45a6cf7a27 Mon Sep 17 00:00:00 2001 From: reality Date: Mon, 29 Jul 2013 20:08:25 +0000 Subject: [PATCH] web login works, with access settings for certain modules [#538] --- modules/warning/config.json | 4 +++- modules/web/web.js | 31 +++++++++++++++++++++++-------- public/styles.css | 4 +++- views/layout.jade | 7 ++++++- views/login.jade | 1 + 5 files changed, 36 insertions(+), 11 deletions(-) diff --git a/modules/warning/config.json b/modules/warning/config.json index 9fb677f..8f816a0 100644 --- a/modules/warning/config.json +++ b/modules/warning/config.json @@ -1,4 +1,6 @@ { "dependencies": [ "report", "users", "web" ], - "dbType": "redis" + "dbType": "redis", + "requireWebLogin": true, + "webAccess": "power_users" } diff --git a/modules/web/web.js b/modules/web/web.js index 7484988..c986750 100644 --- a/modules/web/web.js +++ b/modules/web/web.js @@ -24,11 +24,16 @@ var webInterface = function(dbot) { this.app.use(this.app.router); passport.serializeUser(function(user, done) { - done(null, user); + console.log('serialising ' + user); + done(null, user.id); }); - passport.deserializeUser(function(obj, done) { - done(null, obj); + passport.deserializeUser(function(id, done) { + dbot.api.users.getUser(id, function(user) { + console.log(id); + console.log(user); + done(null, user); + }); }); passport.use(new LocalStrategy(function(username, password, callback) { @@ -68,6 +73,10 @@ var webInterface = function(dbot) { var shim = Object.create(resp); shim.render = (function(view, one, two) { // Render with express.js + _.extend(one, { + 'name': dbot.config.name, + 'user': req.user + }); resp.render(this.module + '/' + view, one, two); }).bind(this); shim.render_core = resp.render; @@ -92,6 +101,7 @@ var webInterface = function(dbot) { this.app.get('/', function(req, res) { res.render('index', { 'name': dbot.config.name, + 'user': req.user, 'routes': indexModules }); }); @@ -107,10 +117,14 @@ var webInterface = function(dbot) { 'failureRedirect': '/login', 'failureFlash': true }), function(req, res) { - res.render('login', { - 'user': req.user, - 'message': 'Successfully logged in!' - }); + if(req.body.redirect) { + res.redirect(req.body.redirect); + } else { + res.render('login', { + 'user': req.user, + 'message': 'Successfully logged in!' + }); + } }); this.app.get('/logout', function(req, res) { @@ -167,7 +181,8 @@ var webInterface = function(dbot) { } } else { res.render('login', { - 'message': 'You need to log in to access this module.' + 'message': 'You need to log in to access this module.', + 'redirect': module }); } } else { diff --git a/public/styles.css b/public/styles.css index 8e8dfaa..2dc68a7 100644 --- a/public/styles.css +++ b/public/styles.css @@ -230,8 +230,10 @@ div.imgwrap > img { margin-right:10px; margin-left:10px; } -#footer a { +#bread { float:right; + margin-left: 2px; + margin-right: 2px; padding-left:2px; padding-right:2px; background-color:#f5f5f5; diff --git a/views/layout.jade b/views/layout.jade index c7b9b65..c78c770 100644 --- a/views/layout.jade +++ b/views/layout.jade @@ -16,7 +16,12 @@ html(lang='en') div.container#main block content div#footer - a#project(href='/project') About + p#project + a#bread(href='/project') About + if user + span#bread Logged in as #{user.primaryNick} + else + a#bread(href='/login') Login script(type="text/javascript", src="/bootstrap/js/bootstrap.min.js") script(type="text/javascript", src="/d3/d3.v3.min.js") diff --git a/views/login.jade b/views/login.jade index 66c4020..940f4b4 100644 --- a/views/login.jade +++ b/views/login.jade @@ -8,6 +8,7 @@ block content p #{message} div#login form(action='/login', method='post') + input(type="hidden", name="redirect", value=redirect) p key Username input(type="text", name="username")