forked from asbjornu/drywall
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented app.utility.debug and .error functions and introduced con…
…fig.logging object so logging can be turned on or off for debug and error messages globally.
- Loading branch information
Showing
11 changed files
with
214 additions
and
190 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
'use strict'; | ||
|
||
exports.port = process.env.PORT || (process.env.NODE_ENV == 'test' ? 3001 : 3000); | ||
exports.logging = { | ||
// Set this to true if you want extensive logging. | ||
debug: false, | ||
error: true | ||
}; | ||
exports.companyName = 'Acme, Inc.'; | ||
exports.projectName = 'Drywall'; | ||
exports.systemEmail = '[email protected]'; | ||
|
@@ -53,10 +58,10 @@ exports.db = { | |
database: '<database>', | ||
host: '127.0.0.1', | ||
dialect: 'postgres', | ||
// Logging to console.log. See the 'Options' section of | ||
// Logging to app.utility.debug(log. See the 'Options' section of | ||
// http://docs.sequelizejs.com/en/1.7.0/docs/usage/ for | ||
// more information. | ||
logging: console.log, | ||
logging: app.utility.debug(log, | ||
force: false | ||
}, | ||
test: { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,155 +1,159 @@ | ||
'use strict'; | ||
|
||
exports = module.exports = function(app, passport) { | ||
var LocalStrategy = require('passport-local').Strategy, | ||
TwitterStrategy = require('passport-twitter').Strategy, | ||
GitHubStrategy = require('passport-github').Strategy, | ||
FacebookStrategy = require('passport-facebook').Strategy, | ||
GoogleStrategy = require('passport-google-oauth').OAuth2Strategy, | ||
TumblrStrategy = require('passport-tumblr').Strategy; | ||
|
||
passport.use(new LocalStrategy(function(username, password, done) { | ||
console.log('Passport.LocalStrategy:', username, done); | ||
|
||
var conditions = { | ||
where : { | ||
isActive: 'yes' | ||
} | ||
}; | ||
|
||
if (username.indexOf('@') === -1) { | ||
conditions.where.username = username; | ||
} else { | ||
conditions.where.email = username.toLowerCase(); | ||
} | ||
|
||
app.db.User.findOne(conditions).then(function(user) { | ||
var dataValues = user ? user.dataValues : null; | ||
console.log('Passport.LocalStrategy:FindOne:', conditions, dataValues); | ||
|
||
if (!user) { | ||
return done(null, false, { | ||
message: 'Unknown user' | ||
}); | ||
} | ||
|
||
app.db.User.validatePassword(password, user.password, function(err, isValid) { | ||
console.log('Passport.LocalStrategy:ValidatePassword'); | ||
|
||
if (err) { | ||
return done(err); | ||
} | ||
|
||
if (!isValid) { | ||
return done(null, false, { | ||
message: 'Invalid password' | ||
}); | ||
} | ||
return done(null, user); | ||
}); | ||
}) | ||
.catch(function(err) { | ||
return done(err); | ||
}); | ||
})); | ||
|
||
if (app.config.oauth.twitter.key) { | ||
passport.use(new TwitterStrategy({ | ||
consumerKey: app.config.oauth.twitter.key, | ||
consumerSecret: app.config.oauth.twitter.secret | ||
}, | ||
function(token, tokenSecret, profile, done) { | ||
done(null, false, { | ||
token: token, | ||
tokenSecret: tokenSecret, | ||
profile: profile | ||
}); | ||
} | ||
)); | ||
var LocalStrategy = require('passport-local').Strategy, | ||
TwitterStrategy = require('passport-twitter').Strategy, | ||
GitHubStrategy = require('passport-github').Strategy, | ||
FacebookStrategy = require('passport-facebook').Strategy, | ||
GoogleStrategy = require('passport-google-oauth').OAuth2Strategy, | ||
TumblrStrategy = require('passport-tumblr').Strategy; | ||
|
||
passport.use(new LocalStrategy(function(username, password, done) { | ||
app.utility.debug('passport.localStrategy:', username, done) | ||
|
||
var conditions = { | ||
where: { | ||
isActive: 'yes' | ||
} | ||
}; | ||
|
||
if (username.indexOf('@') === -1) { | ||
conditions.where.username = username; | ||
} else { | ||
conditions.where.email = username.toLowerCase(); | ||
} | ||
|
||
if (app.config.oauth.github.key) { | ||
passport.use(new GitHubStrategy({ | ||
clientID: app.config.oauth.github.key, | ||
clientSecret: app.config.oauth.github.secret, | ||
customHeaders: { | ||
"User-Agent": app.config.projectName | ||
} | ||
}, | ||
function(accessToken, refreshToken, profile, done) { | ||
done(null, false, { | ||
accessToken: accessToken, | ||
refreshToken: refreshToken, | ||
profile: profile | ||
}); | ||
} | ||
)); | ||
} | ||
app.db.User.findOne(conditions).then(function(user) { | ||
var dataValues = user ? user.dataValues : null; | ||
app.utility.debug('passport.localStrategy.findOne:', conditions, dataValues); | ||
|
||
if (app.config.oauth.facebook.key) { | ||
passport.use(new FacebookStrategy({ | ||
clientID: app.config.oauth.facebook.key, | ||
clientSecret: app.config.oauth.facebook.secret | ||
}, | ||
function(accessToken, refreshToken, profile, done) { | ||
done(null, false, { | ||
accessToken: accessToken, | ||
refreshToken: refreshToken, | ||
profile: profile | ||
}); | ||
} | ||
)); | ||
} | ||
if (!user) { | ||
return done(null, false, { | ||
message: 'Unknown user' | ||
}); | ||
} | ||
|
||
if (app.config.oauth.google.key) { | ||
passport.use(new GoogleStrategy({ | ||
clientID: app.config.oauth.google.key, | ||
clientSecret: app.config.oauth.google.secret | ||
}, | ||
function(accessToken, refreshToken, profile, done) { | ||
done(null, false, { | ||
accessToken: accessToken, | ||
refreshToken: refreshToken, | ||
profile: profile | ||
}); | ||
} | ||
)); | ||
} | ||
app.db.User.validatePassword(password, user.password, function(err, isValid) { | ||
app.utility.debug('passport.localStrategy.ValidatePassword'); | ||
|
||
if (app.config.oauth.tumblr.key) { | ||
passport.use(new TumblrStrategy({ | ||
consumerKey: app.config.oauth.tumblr.key, | ||
consumerSecret: app.config.oauth.tumblr.secret | ||
}, | ||
function(token, tokenSecret, profile, done) { | ||
done(null, false, { | ||
token: token, | ||
tokenSecret: tokenSecret, | ||
profile: profile | ||
}); | ||
} | ||
)); | ||
} | ||
if (err) { | ||
return done(err); | ||
} | ||
|
||
passport.serializeUser(function(user, done) { | ||
var dataValues = user ? user.dataValues : null; | ||
console.log('Passport.SerializeUser:', dataValues, done); | ||
|
||
done(null, user.id); | ||
}); | ||
|
||
passport.deserializeUser(function(id, done) { | ||
console.log('Passport.DeserializeUser:', id, done); | ||
|
||
app.db.User | ||
.findOne({ where: { id: id }}) | ||
.then(function(user) { | ||
done(null, user); | ||
}) | ||
.catch(function(err) { | ||
console.log('Error de-serializing ', err); | ||
done(err); | ||
if (!isValid) { | ||
return done(null, false, { | ||
message: 'Invalid password' | ||
}); | ||
}); | ||
}; | ||
} | ||
return done(null, user); | ||
}); | ||
}) | ||
.catch(function(err) { | ||
app.utility.error('passport.localStrategy.validatePassword:', err); | ||
return done(err); | ||
}); | ||
})); | ||
|
||
if (app.config.oauth.twitter.key) { | ||
passport.use(new TwitterStrategy({ | ||
consumerKey: app.config.oauth.twitter.key, | ||
consumerSecret: app.config.oauth.twitter.secret | ||
}, | ||
function(token, tokenSecret, profile, done) { | ||
done(null, false, { | ||
token: token, | ||
tokenSecret: tokenSecret, | ||
profile: profile | ||
}); | ||
} | ||
)); | ||
} | ||
|
||
if (app.config.oauth.github.key) { | ||
passport.use(new GitHubStrategy({ | ||
clientID: app.config.oauth.github.key, | ||
clientSecret: app.config.oauth.github.secret, | ||
customHeaders: { | ||
"User-Agent": app.config.projectName | ||
} | ||
}, | ||
function(accessToken, refreshToken, profile, done) { | ||
done(null, false, { | ||
accessToken: accessToken, | ||
refreshToken: refreshToken, | ||
profile: profile | ||
}); | ||
} | ||
)); | ||
} | ||
|
||
if (app.config.oauth.facebook.key) { | ||
passport.use(new FacebookStrategy({ | ||
clientID: app.config.oauth.facebook.key, | ||
clientSecret: app.config.oauth.facebook.secret | ||
}, | ||
function(accessToken, refreshToken, profile, done) { | ||
done(null, false, { | ||
accessToken: accessToken, | ||
refreshToken: refreshToken, | ||
profile: profile | ||
}); | ||
} | ||
)); | ||
} | ||
|
||
if (app.config.oauth.google.key) { | ||
passport.use(new GoogleStrategy({ | ||
clientID: app.config.oauth.google.key, | ||
clientSecret: app.config.oauth.google.secret | ||
}, | ||
function(accessToken, refreshToken, profile, done) { | ||
done(null, false, { | ||
accessToken: accessToken, | ||
refreshToken: refreshToken, | ||
profile: profile | ||
}); | ||
} | ||
)); | ||
} | ||
|
||
if (app.config.oauth.tumblr.key) { | ||
passport.use(new TumblrStrategy({ | ||
consumerKey: app.config.oauth.tumblr.key, | ||
consumerSecret: app.config.oauth.tumblr.secret | ||
}, | ||
function(token, tokenSecret, profile, done) { | ||
done(null, false, { | ||
token: token, | ||
tokenSecret: tokenSecret, | ||
profile: profile | ||
}); | ||
} | ||
)); | ||
} | ||
|
||
passport.serializeUser(function(user, done) { | ||
var dataValues = user ? user.dataValues : null; | ||
app.utility.debug('passport.serializeUser:', dataValues, done); | ||
|
||
done(null, user.id); | ||
}); | ||
|
||
passport.deserializeUser(function(id, done) { | ||
app.utility.debug('passport.deserializeUser:', id, done); | ||
|
||
app.db.User | ||
.findOne({ | ||
where: { | ||
id: id | ||
} | ||
}) | ||
.then(function(user) { | ||
done(null, user); | ||
}) | ||
.catch(function(err) { | ||
app.utility.error('passport.deserializeUser:', err); | ||
done(err); | ||
}); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.