diff --git a/server/social.coffee b/server/social.coffee index 22976d6..3fc67ca 100644 --- a/server/social.coffee +++ b/server/social.coffee @@ -385,24 +385,31 @@ module.exports = exports = (log, loga, argv) -> # see http://ward.asia.wiki.org/login-to-view.html if argv.restricted? - allowedToView = (req) -> - allowed = [] if argv.allowed_domains? - if Array.isArray(argv.allowed_domains) - allowed = argv.allowed_domains - else - # accommodate copy bug to be fixed soon - # https://github.com/fedwiki/wiki/blob/4c6eee69e78c1ba3f3fc8d61f4450f70afb78f10/farm.coffee#L98-L103 - for k, v of argv.allowed_domains - allowed.push v - # emails = [ { value: 'ward.cunningham@gmail.com', type: 'account' } ] - emails = req.session?.passport?.user?.google?.emails - return false unless emails - for entry in emails - have = entry.value.split('@')[1] - for want in allowed - return true if want == have + try + allowed_domains = argv.allowed_domains + emails = req.session.passport.user.google.emails + for entry in emails + have = entry.value.split('@')[1] + for want in allowed_domains + return true if want == have + catch error + if emails? + console.log "argv.allowed_domains exists, but there was an error. Make sure it's value is an array in your config." + if argv.allowed_ids? + try + allowed_ids = argv.allowed_ids + idProvider = _.head(_.keys(req.session.passport.user)) + switch idProvider + when 'github', 'twitter', 'oauth2' + id = req.session.passport.user[idProvider].id + return true if (allowed_ids.length == 1 and allowed_ids[0] == "*") + for want in allowed_ids + return true if want == id + catch error + if idProvider? + console.log "argv.allowed_ids exists, but there was an error. Make sure it's value is an array in your config." false app.all '*', (req, res, next) ->