From 3788aa9399c61125988e1f54a9266e9a1673f12d Mon Sep 17 00:00:00 2001 From: reality Date: Sun, 28 Jul 2013 18:11:10 +0000 Subject: [PATCH] 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) {