|
|
|
@ -7,7 +7,8 @@ var express = require('express'),
|
|
|
|
|
redis = require('redis'),
|
|
|
|
|
redisServer = redis.createClient(config.redis.port, config.redis.host, config.redis.options),
|
|
|
|
|
passport = require('passport'),
|
|
|
|
|
passportLocal = require('passport-local').Strategy;
|
|
|
|
|
passportLocal = require('passport-local').Strategy,
|
|
|
|
|
passportTwitter = require('passport-twitter').Strategy;
|
|
|
|
|
|
|
|
|
|
passport.use(new passportLocal(function(user, password, next) {
|
|
|
|
|
global.modules.user.loginViaLocal(user, password, function(login) {
|
|
|
|
@ -16,6 +17,17 @@ passport.use(new passportLocal(function(user, password, next) {
|
|
|
|
|
});
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
passport.use(new passportTwitter({
|
|
|
|
|
consumerKey: config.twitter.key,
|
|
|
|
|
consumerSecret: config.twitter.secret,
|
|
|
|
|
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); }
|
|
|
|
|
done(null, user);
|
|
|
|
|
});
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
passport.serializeUser(function(user, done) {
|
|
|
|
|
done(null, user.uid);
|
|
|
|
|
});
|
|
|
|
@ -62,23 +74,6 @@ passport.deserializeUser(function(uid, done) {
|
|
|
|
|
global.modules.user.session_ping(req.sessionID, req.user.uid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if (req.session.uid === undefined) {
|
|
|
|
|
// console.log('info: [Auth] First load, retrieving uid...');
|
|
|
|
|
|
|
|
|
|
// global.modules.user.get_uid_by_session(req.sessionID, function(uid) {
|
|
|
|
|
// if (uid !== null) {
|
|
|
|
|
// req.session.uid = uid;
|
|
|
|
|
// console.log('info: [Auth] uid ' + req.session.uid + ' found. Welcome back.');
|
|
|
|
|
// } else {
|
|
|
|
|
// req.session.uid = 0;
|
|
|
|
|
// console.log('info: [Auth] No login session found.');
|
|
|
|
|
// }
|
|
|
|
|
// });
|
|
|
|
|
// } else {
|
|
|
|
|
// // console.log('SESSION: ' + req.sessionID);
|
|
|
|
|
// // console.log('info: [Auth] Ping from uid ' + req.session.uid);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// (Re-)register the session as active
|
|
|
|
|
global.modules.user.active.register(req.sessionID);
|
|
|
|
|
|
|
|
|
@ -152,6 +147,13 @@ passport.deserializeUser(function(uid, done) {
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
app.get('/auth/twitter', passport.authenticate('twitter'));
|
|
|
|
|
|
|
|
|
|
app.get('/auth/twitter/callback', passport.authenticate('twitter', {
|
|
|
|
|
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']);
|
|
|
|
|
});
|
|
|
|
|