diff --git a/public/src/app.js b/public/src/app.js
index 12b7f07712..21d0f4bf3d 100644
--- a/public/src/app.js
+++ b/public/src/app.js
@@ -12,7 +12,7 @@ var socket,
socket = io.connect('http://' + config.socket.address + config.socket.port? ':' + config.socket.port : '');
socket.on('event:connect', function(data) {
- console.log('connected to socket.io: ', data);
+ console.log('connected to nodebb socket: ', data);
});
socket.on('event:alert', function(data) {
diff --git a/public/templates/account_settings.tpl b/public/templates/account_settings.tpl
new file mode 100644
index 0000000000..d29898b8e4
--- /dev/null
+++ b/public/templates/account_settings.tpl
@@ -0,0 +1,18 @@
+
Account Settings
+
+
+
+
+ If you see this, you are logged in.
+
+
+
\ No newline at end of file
diff --git a/src/user.js b/src/user.js
index 76c09adccb..95ee11cf59 100644
--- a/src/user.js
+++ b/src/user.js
@@ -21,11 +21,11 @@ var config = require('../config.js'),
return global.socket.emit('user.login', {'status': 0, 'message': 'Incorrect username / password combination.'});
} else {
// Start, replace, or extend a session
- RDB.get('uid:' + uid + ':session', function(session) {
+ RDB.get('session:' + user.sessionID, function(session) {
if (session !== user.sessionID) {
- RDB.set('uid:' + uid + ':session', user.sessionID, 60*60*24*14); // Login valid for two weeks
+ RDB.set('session:' + user.sessionID, uid, 60*60*24*14); // Login valid for two weeks
} else {
- RDB.expire('uid:' + uid + ':session', 60*60*24*14); // Defer expiration to two weeks from now
+ RDB.expire('session:' + user.sessionID, 60*60*24*14); // Defer expiration to two weeks from now
}
});
@@ -103,6 +103,10 @@ var config = require('../config.js'),
RDB.get('email:' + email, callback)
};
+ User.get_uid_by_session = function(session, callback) {
+ RDB.get('session:' + session, callback);
+ };
+
User.reset = {
validate: function(code, callback) {
if (typeof callback !== 'function') callback = undefined;
diff --git a/src/webserver.js b/src/webserver.js
index c401993229..e88c514b93 100644
--- a/src/webserver.js
+++ b/src/webserver.js
@@ -16,7 +16,7 @@ var express = require('express'),
}
function checkAuth(req, res, next) {
- if (!req.session || !req.session.uid) {
+ if (!global.uid) {
res.send(403, 'You are not authorized to view this page');
} else {
next();
@@ -27,13 +27,23 @@ var express = require('express'),
app.use(express.favicon()); // 2 args: string path and object options (i.e. expire time etc)
app.use(express.bodyParser()); // Puts POST vars in request.body
app.use(express.cookieParser()); // If you want to parse cookies (res.cookies)
- app.use(express.session({secret: 'nodebb-julian', key: 'express.sid'}));
+ app.use(express.session({secret: 'nodebb', key: 'express.sid'}));
+ app.use(function(req, res, next) {
+ global.modules.user.get_uid_by_session(req.sessionID, function(uid) {
+ if (uid) global.uid = uid;
+ next();
+ });
+ });
// Dunno wtf this does
// app.use(express.logger({ format: '\x1b[1m:method\x1b[0m \x1b[33m:url\x1b[0m :response-time ms' }));
// Useful if you want to use app.put and app.delete (instead of app.post all the time)
// app.use(express.methodOverride());
app.get('/', function(req, res) {
+ //global.modules.topics.get(function() {
+ // res.send(templates['header'] + templates['home'] + templates['footer']);
+ //})
+
res.send(templates['header'] + templates['home'] + templates['footer']);
});
diff --git a/src/websockets.js b/src/websockets.js
index 0af4f8e26f..ae1c90c36c 100644
--- a/src/websockets.js
+++ b/src/websockets.js
@@ -15,7 +15,7 @@ var SocketIO = require('socket.io').listen(global.server),
io.set('authorization', function(handshakeData, accept) {
if (handshakeData.headers.cookie) {
handshakeData.cookie = cookie.parse(handshakeData.headers.cookie);
- handshakeData.sessionID = connect.utils.parseSignedCookie(handshakeData.cookie['express.sid'], 'nodebb-julian');
+ handshakeData.sessionID = connect.utils.parseSignedCookie(handshakeData.cookie['express.sid'], 'nodebb');
if (handshakeData.cookie['express.sid'] == handshakeData.sessionID) {
return accept('Cookie is invalid.', false);