From d1d62be6f23c8812bb3f4d024fec95ace28a55fb Mon Sep 17 00:00:00 2001 From: reality Date: Sat, 27 Jul 2013 17:19:53 +0000 Subject: [PATCH 01/18] basic skellington for web login stuff [#538] --- modules/web/strings.js | 5 +++ modules/web/web.js | 71 +++++++++++++++++++++++++++++++++++++++--- 2 files changed, 72 insertions(+), 4 deletions(-) create mode 100644 modules/web/strings.js diff --git a/modules/web/strings.js b/modules/web/strings.js new file mode 100644 index 0000000..9cf6415 --- /dev/null +++ b/modules/web/strings.js @@ -0,0 +1,5 @@ +{ + "web_pass_set": { + "en": "Congratulations, your account is now set up to log into the web interface!" + } +} diff --git a/modules/web/web.js b/modules/web/web.js index 75d3c08..8841947 100644 --- a/modules/web/web.js +++ b/modules/web/web.js @@ -1,6 +1,10 @@ var express = require('express'), + passport = require('passport'), + passHash = require('password-hash'), + flash = require('connect-flash'), _ = require('underscore')._, - fs = require('fs'); + fs = require('fs'), + LocalStrategy = require('passport-local').Strategy; var webInterface = function(dbot) { this.config = dbot.config.modules.web; @@ -9,6 +13,39 @@ var webInterface = function(dbot) { this.app.use(express.static(this.pub)); this.app.set('view engine', 'jade'); + this.app.use(express.cookieParser()); + this.app.use(express.methodOverride()); + this.app.use(express.session({ 'secret': 'wat' })); + this.app.use(flash()); + + this.app.use(passport.initialize()); + this.app.use(passport.session()); + this.app.use(app.router); + + passport.use(new LocalStrategy(function(username, pass, callback) { + var splitUser = username.split('@'), + server = splitUser[1], + username = splitUser[0]; + + dbot.api.users.resolveUser(server, username, function(user) { + if(user) { + this.api.getWebUser(user.id, function(webUser) { + if(webUser) { + var hash = passHash.generate(pass); + if(webUser.password === hash) { + return callback(null, user); + } else { + return callback(null, false, { 'message': 'Incorrect password.' }); + } + } else { + return callback(null, false, { 'message': 'Use ~setwebpass to set up your account for web login.' }); + } + }); + } else { + return callback(null, false, { 'message': 'Unknown user' }); + } + }.bind(this)); + }.bind(this)); var server = this.app.listen(this.config.webPort); @@ -44,15 +81,16 @@ var webInterface = function(dbot) { } }); - console.log(indexModules); - - // TODO: get list of loaded modules this.app.get('/', function(req, res) { res.render('index', { 'name': dbot.config.name, 'routes': indexModules }); }); + + this.app.get('/login', function(req, res) { + + }); }.bind(this); this.onDestroy = function() { @@ -67,6 +105,31 @@ var webInterface = function(dbot) { } else { return 'http://' + this.config.webHost + ':' + this.config.webPort + '/' + path; } + }, + + 'getWebUser': function(id) { + this.db.read('web_users', id, function(err, webUser) { + if(!err) callback(webUser); + }); + } + }; + + this.commands = { + '~setwebpassword': function(event) { + var newPass = event.input[1]; + this.api.getWebUser(event.rUser.id, function(webUser) { + if(!webUser) { + webUser = { + 'id': event.rUser.id, + 'password': false + } + } + webUser.password = passHash.generate(newPass); + + this.db.save('web_users', webUser.id, webUser, function(result) { + event.reply(dbot.t('web_pass_set')); + }); + }); } }; }; From f53b8263079e1e9f66d454c569f008833940e688 Mon Sep 17 00:00:00 2001 From: reality Date: Sat, 27 Jul 2013 17:31:00 +0000 Subject: [PATCH 02/18] login and logout web routes [#538] --- modules/web/web.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/modules/web/web.js b/modules/web/web.js index 8841947..ed4fb3c 100644 --- a/modules/web/web.js +++ b/modules/web/web.js @@ -89,7 +89,22 @@ var webInterface = function(dbot) { }); this.app.get('/login', function(req, res) { - + res.render('login', function(req, res) { + 'user': req.user, + 'message': req.flash('error'); + }); + }); + + this.app.post('/login', passport.authenticate('local', { + 'failureRedirect': '/login', + 'failureFlash': true + }), function(req, res) { + res.redirect('/'); + }); + + this.app.get('/logout', function(req, res) { + req.logout(); + res.redirect('/'); }); }.bind(this); From 12e11e78c15b16c32d05c7d7e741bed11405dcb9 Mon Sep 17 00:00:00 2001 From: reality Date: Sat, 27 Jul 2013 18:14:00 +0000 Subject: [PATCH 03/18] some other stuff and the login view. there is some stupid issue picking up the credentials from the form though idk --- modules/web/web.js | 18 +++++++++++++----- views/login.jade | 19 +++++++++++++++++++ 2 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 views/login.jade diff --git a/modules/web/web.js b/modules/web/web.js index ed4fb3c..c3b8630 100644 --- a/modules/web/web.js +++ b/modules/web/web.js @@ -20,9 +20,17 @@ var webInterface = function(dbot) { this.app.use(passport.initialize()); this.app.use(passport.session()); - this.app.use(app.router); + this.app.use(this.app.router); - passport.use(new LocalStrategy(function(username, pass, callback) { + passport.serializeUser(function(user, done) { + done(null, user); + }); + + passport.deserializeUser(function(obj, done) { + done(null, obj); + }); + + passport.use(new LocalStrategy(function(username, password, callback) { var splitUser = username.split('@'), server = splitUser[1], username = splitUser[0]; @@ -45,7 +53,7 @@ var webInterface = function(dbot) { return callback(null, false, { 'message': 'Unknown user' }); } }.bind(this)); - }.bind(this)); + }.bind(this))); var server = this.app.listen(this.config.webPort); @@ -89,9 +97,9 @@ var webInterface = function(dbot) { }); this.app.get('/login', function(req, res) { - res.render('login', function(req, res) { + res.render('login', { 'user': req.user, - 'message': req.flash('error'); + 'message': req.flash('error') }); }); diff --git a/views/login.jade b/views/login.jade new file mode 100644 index 0000000..66c4020 --- /dev/null +++ b/views/login.jade @@ -0,0 +1,19 @@ +extends layout + +block content + div#backlink + a(href='/') « Home + br + if message + p #{message} + div#login + form(action='/login', method='post') + p + key Username + input(type="text", name="username") + p + key Password + input(type="password", name="password") + p + input(type="submit", value="Log In") + From 3788aa9399c61125988e1f54a9266e9a1673f12d Mon Sep 17 00:00:00 2001 From: reality Date: Sun, 28 Jul 2013 18:11:10 +0000 Subject: [PATCH 04/18] it fucking works (web login that is) [#538] --- modules/project/pages.js | 6 +++++- modules/web/config.json | 3 ++- modules/web/{strings.js => strings.json} | 0 modules/web/web.js | 19 ++++++++++++------- 4 files changed, 19 insertions(+), 9 deletions(-) rename modules/web/{strings.js => strings.json} (100%) diff --git a/modules/project/pages.js b/modules/project/pages.js index 529d634..92a7fe0 100644 --- a/modules/project/pages.js +++ b/modules/project/pages.js @@ -30,7 +30,11 @@ var pages = function(dbot) { /* TODO: merge back into github module */ var milestones; request({"url":"https://api.github.com/repos/" + dbot.config.modules.github.defaultrepo + "/milestones?state=open","headers":{"User-Agent":"reality/depressionbot (project module)"}}, function(error, response, body){ - milestones = JSON.parse(body); + try { + milestones = JSON.parse(body); + } catch(err) { + milestones = {}; + } }); diff --git a/modules/web/config.json b/modules/web/config.json index a92a66f..1015dd8 100644 --- a/modules/web/config.json +++ b/modules/web/config.json @@ -1,5 +1,6 @@ { "webHost": "nourishedcloud.com", "webPort": 8080, - "externalPath": false + "externalPath": false, + "dbType": "redis" } diff --git a/modules/web/strings.js b/modules/web/strings.json similarity index 100% rename from modules/web/strings.js rename to modules/web/strings.json diff --git a/modules/web/web.js b/modules/web/web.js index c3b8630..02eada7 100644 --- a/modules/web/web.js +++ b/modules/web/web.js @@ -14,6 +14,7 @@ var webInterface = function(dbot) { this.app.use(express.static(this.pub)); this.app.set('view engine', 'jade'); this.app.use(express.cookieParser()); + this.app.use(express.bodyParser()); this.app.use(express.methodOverride()); this.app.use(express.session({ 'secret': 'wat' })); this.app.use(flash()); @@ -39,8 +40,7 @@ var webInterface = function(dbot) { if(user) { this.api.getWebUser(user.id, function(webUser) { if(webUser) { - var hash = passHash.generate(pass); - if(webUser.password === hash) { + if(passHash.verify(password, webUser.password)) { return callback(null, user); } else { return callback(null, false, { 'message': 'Incorrect password.' }); @@ -107,7 +107,10 @@ var webInterface = function(dbot) { 'failureRedirect': '/login', 'failureFlash': true }), function(req, res) { - res.redirect('/'); + res.render('login', { + 'user': req.user, + 'message': 'Successfully logged in!' + }); }); this.app.get('/logout', function(req, res) { @@ -130,16 +133,17 @@ var webInterface = function(dbot) { } }, - 'getWebUser': function(id) { + 'getWebUser': function(id, callback) { this.db.read('web_users', id, function(err, webUser) { - if(!err) callback(webUser); + callback(webUser); }); } }; this.commands = { - '~setwebpassword': function(event) { + '~setwebpass': function(event) { var newPass = event.input[1]; + console.log(newPass); this.api.getWebUser(event.rUser.id, function(webUser) { if(!webUser) { webUser = { @@ -152,9 +156,10 @@ var webInterface = function(dbot) { this.db.save('web_users', webUser.id, webUser, function(result) { event.reply(dbot.t('web_pass_set')); }); - }); + }.bind(this)); } }; + this.commands['~setwebpass'].regex = [/^~setwebpass ([^ ]+)$/, 2] }; exports.fetch = function(dbot) { From 5214feba0047ad6496ac2a37eecb4d8e32e33c06 Mon Sep 17 00:00:00 2001 From: reality Date: Mon, 29 Jul 2013 19:03:24 +0000 Subject: [PATCH 05/18] OH BABY [#538] --- modules/web/web.js | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/modules/web/web.js b/modules/web/web.js index 02eada7..03bc8cb 100644 --- a/modules/web/web.js +++ b/modules/web/web.js @@ -63,7 +63,7 @@ var webInterface = function(dbot) { if(_.has(pages, p)) { var func = pages[p]; var mod = func.module; - this.app.get(p, (function(req, resp) { + this.app.get(p, this.api.hasAccess, (function(req, resp) { // Crazy shim to seperate module views. var shim = Object.create(resp); shim.render = (function(view, one, two) { @@ -137,6 +137,40 @@ var webInterface = function(dbot) { this.db.read('web_users', id, function(err, webUser) { callback(webUser); }); + }, + + 'hasAccess': function(req, res, next) { + var module = req.route.path.split('/')[1]; + module = dbot.modules[module]; + + if(module.config.requireWebLogin == true) { + if(req.isAuthenticated()) { + if(!_.isUndefined(module.config.webAccess)) { + var allowedUsers = dbot.config.admins; + if(module.config.webAccess == 'moderators') { + allowedUsers = _.union(allowedUsers, dbot.config.moderators); + } + if(module.config.webAccess == 'power_users') { + allowedUsers = _.union(allowedUsers, dbot.config.moderators); + allowedUsers = _.union(allowedUsers, dbot.config.power_users); + } + + if(_.include(allowedUsers, req.user.primaryNick)) { + return next(); + } else { + res.render('index', { + 'message': 'You don\'t have access to this module.' + }); + } + } else { + return next(); + } + } else { + res.render('login', { + 'message': 'You need to log in to access this module.' + }); + } + } } }; From 78b9bf2525fcee190e9345880923830fa5ea266b Mon Sep 17 00:00:00 2001 From: reality Date: Mon, 29 Jul 2013 19:12:16 +0000 Subject: [PATCH 06/18] dope --- modules/web/web.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/web/web.js b/modules/web/web.js index 03bc8cb..7484988 100644 --- a/modules/web/web.js +++ b/modules/web/web.js @@ -170,6 +170,8 @@ var webInterface = function(dbot) { 'message': 'You need to log in to access this module.' }); } + } else { + return next(); } } }; From 652a9ef7a3a3f1f0672922af2af93c45a6cf7a27 Mon Sep 17 00:00:00 2001 From: reality Date: Mon, 29 Jul 2013 20:08:25 +0000 Subject: [PATCH 07/18] 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") From 0b087e2f7b424231d03a8fd4670631fd9a7c3ae9 Mon Sep 17 00:00:00 2001 From: reality Date: Mon, 29 Jul 2013 20:14:43 +0000 Subject: [PATCH 08/18] loginform --- views/login.jade | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/views/login.jade b/views/login.jade index 940f4b4..8367976 100644 --- a/views/login.jade +++ b/views/login.jade @@ -7,7 +7,7 @@ block content if message p #{message} div#login - form(action='/login', method='post') + form(name='loginform' action='/login', method='post') input(type="hidden", name="redirect", value=redirect) p key Username From abfcee0e48352ee4fb6bd883e6878b07f08f9986 Mon Sep 17 00:00:00 2001 From: reality Date: Mon, 29 Jul 2013 20:16:53 +0000 Subject: [PATCH 09/18] idk --- views/login.jade | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/views/login.jade b/views/login.jade index 8367976..940f4b4 100644 --- a/views/login.jade +++ b/views/login.jade @@ -7,7 +7,7 @@ block content if message p #{message} div#login - form(name='loginform' action='/login', method='post') + form(action='/login', method='post') input(type="hidden", name="redirect", value=redirect) p key Username From 13334e3b4dedddd4f6f8b404d22bc2c71e9b554a Mon Sep 17 00:00:00 2001 From: reality Date: Mon, 29 Jul 2013 20:25:07 +0000 Subject: [PATCH 10/18] each --- modules/web/web.js | 1 + views/warning/warnings.jade | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/web/web.js b/modules/web/web.js index c986750..a3bbd5f 100644 --- a/modules/web/web.js +++ b/modules/web/web.js @@ -91,6 +91,7 @@ var webInterface = function(dbot) { var moduleNames = _.keys(dbot.modules); var indexModules = []; + // fix the thingy _.each(moduleNames, function(moduleName) { var modulePath = '/' + moduleName; if(_.include(routes, modulePath)) { diff --git a/views/warning/warnings.jade b/views/warning/warnings.jade index 18bfc70..2aac88b 100644 --- a/views/warning/warnings.jade +++ b/views/warning/warnings.jade @@ -12,7 +12,7 @@ block content th Warner th Reason tbody - for warning, key in warnings + each warning, key in warnings tr td #{new Date(warning.time)} td #{warning.warner} From 2c6729a7f4578433b343f187b8e267b2d27f1d18 Mon Sep 17 00:00:00 2001 From: reality Date: Mon, 29 Jul 2013 20:33:13 +0000 Subject: [PATCH 11/18] thing --- modules/web/web.js | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/web/web.js b/modules/web/web.js index a3bbd5f..517e39e 100644 --- a/modules/web/web.js +++ b/modules/web/web.js @@ -169,6 +169,7 @@ var webInterface = function(dbot) { allowedUsers = _.union(allowedUsers, dbot.config.moderators); allowedUsers = _.union(allowedUsers, dbot.config.power_users); } + console.log(allowedUsers); if(_.include(allowedUsers, req.user.primaryNick)) { return next(); From 70f41df08ae795d7a352e195dd88506ee3118e82 Mon Sep 17 00:00:00 2001 From: reality Date: Mon, 29 Jul 2013 20:36:27 +0000 Subject: [PATCH 12/18] more thing --- modules/web/web.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/web/web.js b/modules/web/web.js index 517e39e..7bc2eb1 100644 --- a/modules/web/web.js +++ b/modules/web/web.js @@ -169,6 +169,8 @@ var webInterface = function(dbot) { allowedUsers = _.union(allowedUsers, dbot.config.moderators); allowedUsers = _.union(allowedUsers, dbot.config.power_users); } + + console.log(module.config.webAccess); console.log(allowedUsers); if(_.include(allowedUsers, req.user.primaryNick)) { From 329b45e895554115c1ed9c58e04d409ff5187e12 Mon Sep 17 00:00:00 2001 From: reality Date: Mon, 29 Jul 2013 20:44:12 +0000 Subject: [PATCH 13/18] redirect not re-render upon failed auth --- modules/web/web.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/modules/web/web.js b/modules/web/web.js index 7bc2eb1..b6c3bf6 100644 --- a/modules/web/web.js +++ b/modules/web/web.js @@ -170,15 +170,10 @@ var webInterface = function(dbot) { allowedUsers = _.union(allowedUsers, dbot.config.power_users); } - console.log(module.config.webAccess); - console.log(allowedUsers); - if(_.include(allowedUsers, req.user.primaryNick)) { return next(); } else { - res.render('index', { - 'message': 'You don\'t have access to this module.' - }); + res.redirect('index'); } } else { return next(); From b069ce4b0dee9a66386494f0162e4cb72c09f11e Mon Sep 17 00:00:00 2001 From: reality Date: Mon, 29 Jul 2013 20:45:35 +0000 Subject: [PATCH 14/18] fix more redirects --- modules/web/web.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/modules/web/web.js b/modules/web/web.js index b6c3bf6..14f5c93 100644 --- a/modules/web/web.js +++ b/modules/web/web.js @@ -121,10 +121,7 @@ var webInterface = function(dbot) { if(req.body.redirect) { res.redirect(req.body.redirect); } else { - res.render('login', { - 'user': req.user, - 'message': 'Successfully logged in!' - }); + res.redirect('/'); } }); @@ -173,7 +170,7 @@ var webInterface = function(dbot) { if(_.include(allowedUsers, req.user.primaryNick)) { return next(); } else { - res.redirect('index'); + res.redirect('/'); } } else { return next(); From 1b50a3583ccbb1fe2ba115cc2e85fb39c7153ccf Mon Sep 17 00:00:00 2001 From: reality Date: Mon, 29 Jul 2013 20:50:48 +0000 Subject: [PATCH 15/18] fix the whatsit --- modules/warning/pages.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/warning/pages.js b/modules/warning/pages.js index 72c5129..876250f 100644 --- a/modules/warning/pages.js +++ b/modules/warning/pages.js @@ -35,9 +35,9 @@ var pages = function(dbot) { }); }, - '/warning/:server/:user': function(req, res) { + '/warning/:server/:uid': function(req, res) { var server = req.params.server, - user = req.params.user; + user = req.params.uid; dbot.api.users.resolveUser(server, user, function(user) { var warnings = []; From 21b2b4eec3b843e89d4cdfb0bd6fae2e18a5c089 Mon Sep 17 00:00:00 2001 From: reality Date: Mon, 29 Jul 2013 21:04:12 +0000 Subject: [PATCH 16/18] i dont have a clue what even fucking fixed that --- modules/warning/pages.js | 4 +++- views/warning/warnings.jade | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/warning/pages.js b/modules/warning/pages.js index 876250f..0c4cf08 100644 --- a/modules/warning/pages.js +++ b/modules/warning/pages.js @@ -47,16 +47,18 @@ var pages = function(dbot) { }, function(warning) { warnings.push(warning); }, function(err) { + console.log(warnings); async.eachSeries(warnings, function(warning, callback) { dbot.api.users.getUser(warning.warner, function(user) { warning.warner = user.primaryNick; callback(false); }); }, function(err) { + console.log(warnings); res.render('warnings', { 'name': dbot.config.name, 'server': server, - 'warnings': warnings + 'warns': warnings }); }); }); diff --git a/views/warning/warnings.jade b/views/warning/warnings.jade index 2aac88b..a9c8ab6 100644 --- a/views/warning/warnings.jade +++ b/views/warning/warnings.jade @@ -12,7 +12,7 @@ block content th Warner th Reason tbody - each warning, key in warnings + each warning, key in warns tr td #{new Date(warning.time)} td #{warning.warner} From 9a99d5eb47c8ccd73fa0f84c6c5ad39084af649c Mon Sep 17 00:00:00 2001 From: reality Date: Mon, 29 Jul 2013 21:08:41 +0000 Subject: [PATCH 17/18] fix up report for use with login --- modules/report/config.json | 4 +++- modules/report/pages.js | 6 +++--- views/report/channels.jade | 4 ++-- views/report/notifies.jade | 2 +- views/report/servers.jade | 2 +- 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/modules/report/config.json b/modules/report/config.json index 975bd13..3e32ba1 100644 --- a/modules/report/config.json +++ b/modules/report/config.json @@ -2,5 +2,7 @@ "ignorable": true, "notifyVoice": false, "dependencies": [ "users" ], - "dbType": "redis" + "dbType": "redis", + "requireWebLogin": true, + "webAccess": "power_users" } diff --git a/modules/report/pages.js b/modules/report/pages.js index e8bbc89..c199048 100644 --- a/modules/report/pages.js +++ b/modules/report/pages.js @@ -2,14 +2,14 @@ var _ = require('underscore')._; var pages = function(dbot) { return { - '/notify': function(req, res) { + '/report': function(req, res) { res.render('servers', { 'name': dbot.config.name, 'servers': _.keys(dbot.config.servers) }); }, - '/notify/:server': function(req, res) { + '/report/:server': function(req, res) { var server = req.params.server; res.render('channels', { 'name': dbot.config.name, @@ -18,7 +18,7 @@ var pages = function(dbot) { }); }, - '/notify/:server/:channel': function(req, res) { + '/report/:server/:channel': function(req, res) { var server = req.params.server, channel = req.params.channel, notifies = []; diff --git a/views/report/channels.jade b/views/report/channels.jade index b2a0b7e..50a74c0 100644 --- a/views/report/channels.jade +++ b/views/report/channels.jade @@ -3,8 +3,8 @@ extends ../layout block content h3 Channels on #{server} div#backlink - a(href='/warning') « Server List + a(href='/report') « Server List ul#quotelist -each channel in channels - a(href='/notify/'+server+'/'+encodeURIComponent(channel)) + a(href='/report/'+server+'/'+encodeURIComponent(channel)) li.quotes #{channel} diff --git a/views/report/notifies.jade b/views/report/notifies.jade index 1b4c04d..c076e4c 100644 --- a/views/report/notifies.jade +++ b/views/report/notifies.jade @@ -2,7 +2,7 @@ extends ../layout block content div#backlink - a(href='/notify/'+server) « Server Channels + a(href='/report/'+server) « Server Channels p div#profile_datatable table.table.table-hover.data diff --git a/views/report/servers.jade b/views/report/servers.jade index 924eb19..3401db0 100644 --- a/views/report/servers.jade +++ b/views/report/servers.jade @@ -6,5 +6,5 @@ block content a(href='/') « Home ul#quotelist -each server in servers - a(href='/notify/'+server) + a(href='/report/'+server) li.quotes #{server} From 450ffce0e238227f62bc5fe849cc0539c3cd5eb3 Mon Sep 17 00:00:00 2001 From: reality Date: Sat, 3 Aug 2013 01:53:36 +0000 Subject: [PATCH 18/18] stagger pend notifies --- modules/report/report.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/modules/report/report.js b/modules/report/report.js index b196147..6a91c20 100644 --- a/modules/report/report.js +++ b/modules/report/report.js @@ -50,10 +50,21 @@ var report = function(dbot) { this.listener = function(event) { if(_.has(this.pending, event.rUser.id)) { - _.each(this.pending[event.rUser.id], function(message) { - dbot.say(event.server, event.rUser.currentNick, message); - }); - delete this.pending[event.rUser.id]; + var i=0, + pending = this.pending[event.rUser.id]; + + var notifyUser = function(pending) { + if(i >= msg.length) { + delete this.pending[event.rUser.id]; + return; + } + dbot.say(event.server, pending[i], message); + setTimeout(function() { + i++; notifyUser(pending); + }, 1000); + }.bind(this); + + notifyUser(pending); } }.bind(this); this.on = 'JOIN';