Skip to content

Node.js based forum software built for the modern web

accidentally developed on a merge commit... *fingers crossed*

Julian Lam8be3b8c05e15
diff --cc public/css/style.less
index 44079ba5a3,19fc47425e..999af998d2
--- a/public/css/style.less
+++ b/public/css/style.less
@@@ -9,6 -9,6 +9,14 @@@
zoom: 1;
}
++.none {
++ display: none;
++}
++
++.block {
++ display: block;
++}
++
@media (min-width: 979px) {
body {
padding-top: 60px;
@@@ -165,23 -165,14 +173,33 @@@ footer.footer
padding: 0;
li {
- .inline-block;
+ vertical-align: top;
- .inline-block;
++ background: transparent;
++ .none;
.pointer;
- }
-}
-.none {
- display: none !important;
-}
-.block {
- display: block !important;
+ &.google {
+ width: 202px;
+ height: 32px;
- background: transparent;
+ background-image: url('../images/google_login.png');
+
+ &:hover {
+ background-position-x: -265px;
+ }
+
+ &:active {
+ background-position-x: -535px;
+ }
+ }
++
++ &.twitter {
++ width: 158px;
++ height: 28px;
++ background-image: url('../images/twitter_login.png');
++ }
++
++ &.active {
++ .inline-block;
++ }
+ }
}
diff --cc public/templates/login.tpl
index c8592905c0,304b8bd180..6f5bf0a752
--- a/public/templates/login.tpl
+++ b/public/templates/login.tpl
@@@ -12,11 -12,10 +12,21 @@@
<button class="btn btn-primary" id="login" type="submit">Login</button> &nbsp; <a href="/reset">Forgot Password?</a>
</form>
</div>
- <div class="well span6">
+ <div class="well span6 {alternate_logins:display}">
<h4>Alternative Logins</h4>
<ul class="alt-logins">
- <li><a href="/auth/twitter"><img src="/images/twitter_login.png" /></a></li>
- <li class="google"></li>
- <li class="none {twitter:display}"><a href="/auth/twitter"><img src="/images/twitter_login.png" /></a></li>
++ <li data-url="/auth/twitter" class="twitter {twitter:display}"></li>
++ <li data-url="/auth/google" class="google {google:display}"></li>
</ul>
</div>
--</div>
++</div>
++
++<script>
++ var altLoginEl = document.querySelector('.alt-logins');
++
++ altLoginEl.addEventListener('click', function(e) {
++ if (e.target.nodeName === 'LI') {
++ document.location.href = e.target.getAttribute('data-url');
++ }
++ });
++</script>
diff --cc src/user.js
index 1d3ae16402,1d3ae16402..1729a4c39d
--- a/src/user.js
+++ b/src/user.js
@@@ -146,7 -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 -224,6 +249,12 @@@
});
}
++ 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 --cc src/webserver.js
index 9400f36316,789810caf6..7df945e438
--- a/src/webserver.js
+++ b/src/webserver.js
@@@ -34,19 -33,6 +34,21 @@@ if (config.twitter && config.twitter.ke
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');
++ 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');
+}
+
passport.serializeUser(function(user, done) {
done(null, user.uid);
});
@@@ -139,6 -125,28 +141,27 @@@ passport.deserializeUser(function(uid,
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<ii; i++) {
- data[login_strategies[i] + ':display'] = 'block';
++ data[login_strategies[i] + ':display'] = 'active';
+ }
+ }
- console.log(data);
+ res.send(JSON.stringify(data));
+
+ break;
case 'topic' :
global.modules.posts.get(function(data) {
res.send(JSON.stringify(data));
@@@ -175,15 -183,6 +198,15 @@@
}));
}
+ if (login_strategies.indexOf('google') !== -1) {
- app.get('/auth/google', passport.authenticate('google', { scope: {} }));
++ app.get('/auth/google', passport.authenticate('google', { scope: 'https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email' }));
+
+ 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']);
});