diff --git a/config.default.js b/config.default.js index 8c5a546c50..0e20f9672b 100644 --- a/config.default.js +++ b/config.default.js @@ -17,6 +17,10 @@ var config = { "twitter": { "key": '', "secret": '' + }, + "google": { + "id": '', + "secret": '' } } diff --git a/package.json b/package.json index cb853c9be6..072503960a 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "passport": "0.1.16", "passport-local": "0.1.6", "passport-twitter": "0.1.4", + "passport-google-oauth": "0.1.5", "less-middleware": "0.1.11" }, "devDependencies": {}, diff --git a/public/css/style.less b/public/css/style.less index 06d0cda1e8..44079ba5a3 100644 --- a/public/css/style.less +++ b/public/css/style.less @@ -165,7 +165,23 @@ footer.footer { padding: 0; li { + vertical-align: top; .inline-block; .pointer; + + &.google { + width: 202px; + height: 32px; + background: transparent; + background-image: url('../images/google_login.png'); + + &:hover { + background-position-x: -265px; + } + + &:active { + background-position-x: -535px; + } + } } } \ No newline at end of file diff --git a/public/images/google_login.png b/public/images/google_login.png new file mode 100644 index 0000000000..55abc2bc78 Binary files /dev/null and b/public/images/google_login.png differ diff --git a/public/templates/login.tpl b/public/templates/login.tpl index d2f06bef2b..c8592905c0 100644 --- a/public/templates/login.tpl +++ b/public/templates/login.tpl @@ -16,6 +16,7 @@

Alternative Logins

\ No newline at end of file diff --git a/src/webserver.js b/src/webserver.js index 95d55d9d29..9400f36316 100644 --- a/src/webserver.js +++ b/src/webserver.js @@ -9,6 +9,7 @@ var express = require('express'), passport = require('passport'), passportLocal = require('passport-local').Strategy, passportTwitter = require('passport-twitter').Strategy, + passportGoogle = require('passport-google-oauth').OAuth2Strategy, login_strategies = []; passport.use(new passportLocal(function(user, password, next) { @@ -22,7 +23,7 @@ if (config.twitter.key.length > 0 && config.twitter.secret.length > 0) { passport.use(new passportTwitter({ consumerKey: config.twitter.key, consumerSecret: config.twitter.secret, - callbackURL: config.url + "auth/twitter/callback" + callbackURL: config.url + 'auth/twitter/callback' }, function(token, tokenSecret, profile, done) { global.modules.user.loginViaTwitter(profile.id, profile.username, function(err, user) { if (err) { return done(err); } @@ -33,6 +34,19 @@ if (config.twitter.key.length > 0 && config.twitter.secret.length > 0) { login_strategies.push('twitter'); } +if (config.google.id.length > 0 && config.google.secret.length > 0) { + passport.use(new passportGoogle({ + clientID: config.google.id, + clientSecret: config.google.secret, + callbackURL: config.url + 'auth/google/callback' + }, function(accessToken, refreshToken, profile, done) { + console.log(accessToken, refreshToken, profile); + done('hardcode fail'); + })) + + login_strategies.push('google'); +} + passport.serializeUser(function(user, done) { done(null, user.uid); }); @@ -161,6 +175,15 @@ passport.deserializeUser(function(uid, done) { })); } + if (login_strategies.indexOf('google') !== -1) { + app.get('/auth/google', passport.authenticate('google', { scope: {} })); + + app.get('/auth/google/callback', passport.authenticate('google', { + successRedirect: '/', + failureRedirect: '/login' + })); + } + app.get('/reset/:code', function(req, res) { res.send(templates['header'] + templates['reset_code'].parse({ reset_code: req.params.code }) + templates['footer']); });