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

Merge branch 'master' of github.com:psychobunny/node-forum

Conflicts:
	public/templates/login.tpl
v1.18.x
Julian Lam 12 years ago
commit 8be3b8c05e

@ -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();

@ -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;
}
}
}

@ -1,6 +1,6 @@
<h1>Login</h1>
<div class="row-fluid">
<div class="well span6">
<div class="well {login_window:spansize}">
<h4>Login via Username &amp; Password</h4>
<div class="alert alert-error" id="error" style="display:none">
<button type="button" class="close" data-dismiss="alert">&times;</button>
@ -12,11 +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 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>

@ -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;

@ -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) {

@ -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<ii; i++) {
data[login_strategies[i] + ':display'] = 'active';
}
}
res.send(JSON.stringify(data));
break;
case 'topic' :
global.modules.posts.get(function(data) {
res.send(JSON.stringify(data));
@ -176,7 +199,7 @@ passport.deserializeUser(function(uid, done) {
}
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: '/',

Loading…
Cancel
Save