Skip to content

Commit

Permalink
Fix admin for external auth.
Browse files Browse the repository at this point in the history
  • Loading branch information
richtera committed Oct 14, 2012
1 parent 7784330 commit 99f8728
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
44 changes: 25 additions & 19 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,17 @@ 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) {
var User = calipso.db.model('User');
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);
});
Expand All @@ -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,
Expand Down Expand Up @@ -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)
Expand All @@ -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'))
Expand All @@ -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();

Expand Down
3 changes: 0 additions & 3 deletions modules/core/user/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 99f8728

Please sign in to comment.