diff --git a/app.js b/app.js index b9759de5bc..96b367830c 100644 --- a/app.js +++ b/app.js @@ -4,7 +4,8 @@ var modules = { posts: require('./src/posts.js'), templates: require('./src/templates.js'), webserver: require('./src/webserver.js'), - websockets: require('./src/websockets.js') + websockets: require('./src/websockets.js'), + fs: require('fs') } DEVELOPMENT = true; @@ -13,9 +14,6 @@ var modules = { global.configuration = {}; global.modules = modules; -// change this to = null when auth module is complete -// global.uid = 1; - process.on('uncaughtException', function(err) { // handle the error safely @@ -28,7 +26,6 @@ process.on('uncaughtException', function(err) { config['ROOT_DIRECTORY'] = __dirname; modules.templates.init(); - // modules.webserver.init(); modules.websockets.init(); diff --git a/public/css/style.less b/public/css/style.less index 44079ba5a3..999af998d2 100644 --- a/public/css/style.less +++ b/public/css/style.less @@ -9,6 +9,14 @@ zoom: 1; } +.none { + display: none; +} + +.block { + display: block; +} + @media (min-width: 979px) { body { padding-top: 60px; @@ -166,13 +174,13 @@ footer.footer { li { vertical-align: top; - .inline-block; + background: transparent; + .none; .pointer; &.google { width: 202px; height: 32px; - background: transparent; background-image: url('../images/google_login.png'); &:hover { @@ -183,5 +191,15 @@ footer.footer { background-position-x: -535px; } } + + &.twitter { + width: 158px; + height: 28px; + background-image: url('../images/twitter_login.png'); + } + + &.active { + .inline-block; + } } } \ No newline at end of file diff --git a/public/templates/login.tpl b/public/templates/login.tpl index c8592905c0..6f5bf0a752 100644 --- a/public/templates/login.tpl +++ b/public/templates/login.tpl @@ -1,6 +1,6 @@

Login

-
+

Login via Username & Password

-
+

Alternative Logins

    -
  • -
  • + +
-
\ No newline at end of file +
+ + \ No newline at end of file diff --git a/src/templates.js b/src/templates.js index 98e0ed6f99..e56f09f39d 100644 --- a/src/templates.js +++ b/src/templates.js @@ -1,4 +1,4 @@ -var fs = require('fs'); + (function(Templates) { @@ -7,7 +7,7 @@ var fs = require('fs'); function loadTemplates(templatesToLoad) { for (var t in templatesToLoad) { (function(file) { - fs.readFile(global.configuration.ROOT_DIRECTORY + '/public/templates/' + file + '.tpl', function(err, html) { + modules.fs.readFile(global.configuration.ROOT_DIRECTORY + '/public/templates/' + file + '.tpl', function(err, html) { var template = function() { this.toString = function() { return this.html; diff --git a/src/user.js b/src/user.js index 1d3ae16402..1729a4c39d 100644 --- a/src/user.js +++ b/src/user.js @@ -146,7 +146,32 @@ var config = require('../config.js'), } }); } - }) + }); + } + + User.loginViaGoogle = function(gplusid, handle, email, callback) { + User.get_uid_by_google_id(gplusid, function(uid) { + if (uid !== null) { + // Existing User + callback(null, { + uid: uid + }); + } else { + // New User + User.create(handle, null, email, function(err, uid) { + if (err !== null) { + callback(err); + } else { + // Save twitter-specific information to the user + RDB.set('uid:' + uid + ':gplusid', gplusid); + RDB.set('gplusid:' + gplusid + ':uid', uid); + callback(null, { + uid: uid + }); + } + }); + } + }); } User.logout = function(sessionID, callback) { @@ -224,6 +249,12 @@ var config = require('../config.js'), }); } + User.get_uid_by_google_id = function(gplusid, callback) { + RDB.get('gplusid:' + gplusid + ':uid', function(uid) { + callback(uid); + }); + } + User.session_ping = function(sessionID, uid) { // Start, replace, or extend a session RDB.get('sess:' + sessionID, function(session) { diff --git a/src/webserver.js b/src/webserver.js index 9400f36316..7df945e438 100644 --- a/src/webserver.js +++ b/src/webserver.js @@ -19,7 +19,7 @@ passport.use(new passportLocal(function(user, password, next) { }); })); -if (config.twitter.key.length > 0 && config.twitter.secret.length > 0) { +if (config.twitter && config.twitter.key && config.twitter.key.length > 0 && config.twitter.secret.length > 0) { passport.use(new passportTwitter({ consumerKey: config.twitter.key, consumerSecret: config.twitter.secret, @@ -40,8 +40,10 @@ if (config.google.id.length > 0 && config.google.secret.length > 0) { clientSecret: config.google.secret, callbackURL: config.url + 'auth/google/callback' }, function(accessToken, refreshToken, profile, done) { - console.log(accessToken, refreshToken, profile); - done('hardcode fail'); + global.modules.user.loginViaGoogle(profile.id, profile.displayName, profile.emails[0].value, function(err, user) { + if (err) { return done(err); } + done(null, user); + }); })) login_strategies.push('google'); @@ -139,6 +141,27 @@ passport.deserializeUser(function(uid, done) { res.send(JSON.stringify(data)); }); break; + case 'login' : + var data = {}, + num_strategies = login_strategies.length; + + if (num_strategies == 0) { + data = { + 'login_window:spansize': 'span12', + 'alternate_logins:display': 'none' + }; + } else { + data = { + 'login_window:spansize': 'span6', + 'alternate_logins:display': 'block' + } + for (var i=0, ii=num_strategies; i