From 977de65914ffd443d4f1fed5c0fd1e21cf35019a Mon Sep 17 00:00:00 2001 From: reality Date: Tue, 21 Oct 2014 21:25:50 +0000 Subject: [PATCH] web changes for posting --- modules/web/api.js | 3 +-- modules/web/web.js | 18 +++++++++++++++--- views/layout.jade | 1 + 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/modules/web/api.js b/modules/web/api.js index a168f44..446012d 100644 --- a/modules/web/api.js +++ b/modules/web/api.js @@ -28,7 +28,6 @@ var api = function(dbot) { accessNeeded, allowedNicks; -console.log('haxess called'); if(mConfig.requireWebLogin == true) { if(req.isAuthenticated()) { if(_.has(mConfig, 'pageAccess') && _.has(mConfig.pageAccess, path)) { @@ -49,7 +48,7 @@ console.log('haxess called'); } } - if(_.include(allowedUsers, req.user.primaryNick)) { + if(_.include(accessNeeded(), req.user.primaryNick)) { return next(); } else { res.redirect('/'); diff --git a/modules/web/web.js b/modules/web/web.js index 597f115..5ef33af 100644 --- a/modules/web/web.js +++ b/modules/web/web.js @@ -34,6 +34,18 @@ var webInterface = function(dbot) { passport.deserializeUser(function(id, done) { dbot.api.users.getUser(id, function(err, user) { + // Get user access level. Sigh. + if(user) { + user.access = 'user'; + if(_.include(dbot.config.admins, user.primaryNick)) { + user.access = 'admin'; + } else if(_.include(dbot.config.moderators, user.primaryNick)) { + user.access = 'moderator'; + } else if(_.include(dbot.config.power_users, user.primaryNick)) { + user.access = 'power_user'; + } + } + console.log(user); done(null, user); }); }); @@ -76,10 +88,10 @@ var webInterface = function(dbot) { for(var p in pages) { if(_.has(pages, p)) { var func = pages[p], - mod = func.module; + mod = func.module, + type = func.type || 'get'; -console.log('adding ' + p); - this.app.get(p, this.api.hasAccess, (function(req, resp) { + this.app[type](p, this.api.hasAccess, (function(req, resp) { // Crazy shim to seperate module views. var shim = Object.create(resp); shim.render = (function(view, one, two) { diff --git a/views/layout.jade b/views/layout.jade index dfb3649..b1b22d7 100644 --- a/views/layout.jade +++ b/views/layout.jade @@ -3,6 +3,7 @@ html(lang='en') head meta(charset='utf-8') script(type="text/javascript", src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js") + script(type="text/javascript", src="/fs_edit.js") link(rel="stylesheet", type="text/css", href="http://fonts.googleapis.com/css?family=Source+Sans+Pro") link(rel="stylesheet", type="text/css", href="/bootstrap/css/bootstrap.min.css") link(rel='stylesheet', type='text/css', href='/styles.css')