From 99f8728083e981a246af9bb829477e28aa2c9c88 Mon Sep 17 00:00:00 2001 From: Andreas Richter Date: Sat, 13 Oct 2012 21:18:43 -0400 Subject: [PATCH] Fix admin for external auth. --- app.js | 44 ++++++++++++++++++++++----------------- modules/core/user/user.js | 3 --- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/app.js b/app.js index 4acc04710..58050641f 100644 --- a/app.js +++ b/app.js @@ -107,10 +107,7 @@ var rootpath = process.cwd() + '/', everyauth.everymodule .findUserById( function (req, id, callback) { var User = calipso.db.model('User'); - User.findById(id, function (err, user) { - req.session.user = user; - callback(err, user); - }); + User.findById(id, callback); }); function calipsoFindOrCreateUser(user, sess, promise) { @@ -118,7 +115,9 @@ function calipsoFindOrCreateUser(user, sess, promise) { function finishUser(user) { if (sess) { if (!sess._pending) return promise.fulfill(user); - return calipso.lib.user.createUserSession(sess._pending, null, user, function(err) { + var req = sess._pending; + delete sess._pending; + return calipso.lib.user.createUserSession(req, null, user, function(err) { if(err) { calipso.error("Error saving session: " + err); return promise.fail(err); } promise.fulfill(user); }); @@ -128,7 +127,7 @@ function calipsoFindOrCreateUser(user, sess, promise) { User.findOne({username:user.username}, function (err, u) { if (err) return promise.fail(err); - if (u) return promise.fulfill(u); + if (u) return finishUser(u); u = new User({ username: user.username, fullname: user.name, @@ -212,6 +211,8 @@ function bootApplication(cluster, next) { .getSession( function (req) { if (!req.session) req.session = { _pending: req }; + else + req.session._pending = req; return req.session; }) .appId(appId) @@ -234,6 +235,8 @@ function bootApplication(cluster, next) { .getSession( function (req) { if (!req.session) req.session = { _pending: req }; + else + req.session._pending = req; return req.session; }) .myHostname(app.config.get('server:url')) @@ -253,19 +256,22 @@ function bootApplication(cluster, next) { var clientSecret = app.config.get('server:authentication:googleClientSecret'); if (clientId && clientSecret) { calipso.auth.google = true; - everyauth.google - .myHostname(app.config.get('server:url')) - .appId(clientId) - .appSecret(clientSecret) - .scope('https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email') - .getSession( function (req) { - if (!req.session) - req.session = { _pending: req }; - return req.session; - }) - .findOrCreateUser( function (sess, accessToken, extra, googleUser) { - googleUser.refreshToken = extra.refresh_token; - googleUser.expiresIn = extra.expires_in; + everyauth + .google + .myHostname(app.config.get('server:url')) + .appId(clientId) + .appSecret(clientSecret) + .scope('https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email') + .getSession( function (req) { + if (!req.session) + req.session = { _pending: req }; + else + req.session._pending = req; + return req.session; + }) + .findOrCreateUser( function (sess, accessToken, extra, googleUser) { + googleUser.refreshToken = extra.refresh_token; + googleUser.expiresIn = extra.expires_in; var promise = this.Promise(); diff --git a/modules/core/user/user.js b/modules/core/user/user.js index 226f18e7e..78a3833ba 100644 --- a/modules/core/user/user.js +++ b/modules/core/user/user.js @@ -430,7 +430,6 @@ function updateUserForm(req, res, template, block, next) { // remove the section delete userForm.sections[roleSection]; } - console.log(u); if (u.hash === 'external:auth') { delete userForm.sections[passwordSection]; } @@ -753,9 +752,7 @@ function isUserAdmin(user) { * Create session object for logged in user */ function createUserSession(req, res, user, next) { -console.log(user); var isAdmin = isUserAdmin(user); -console.log(isAdmin); // Create session req.session.user = {username:user.username, isAdmin:isAdmin, id:user._id,language:user.language,roles:user.roles}; req.session.save(function(err) {