mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 19:46:01 +01:00
removed global.socket, passing in socket to the functions now
This commit is contained in:
7
app.js
7
app.js
@@ -17,13 +17,6 @@ global.modules = modules;
|
|||||||
// global.uid = 1;
|
// global.uid = 1;
|
||||||
|
|
||||||
|
|
||||||
process.on('uncaughtException', function(err) {
|
|
||||||
// handle the error safely
|
|
||||||
console.log("error message "+err);
|
|
||||||
global.socket.emit('event:consolelog',{type:'uncaughtException',stack:err.stack,error:err.toString()});
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
(function(config) {
|
(function(config) {
|
||||||
config['ROOT_DIRECTORY'] = __dirname;
|
config['ROOT_DIRECTORY'] = __dirname;
|
||||||
|
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ var RDB = require('./redis.js'),
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Posts.reply = function(tid, uid, content) {
|
Posts.reply = function(socket, tid, uid, content) {
|
||||||
Posts.create(uid, content, function(pid) {
|
Posts.create(uid, content, function(pid) {
|
||||||
RDB.rpush('tid:' + tid + ':posts', pid);
|
RDB.rpush('tid:' + tid + ':posts', pid);
|
||||||
|
|
||||||
|
|||||||
@@ -93,8 +93,8 @@ var RDB = require('./redis.js'),
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Topics.post = function(socket, uid, title, content, category) {
|
||||||
|
|
||||||
Topics.post = function(uid, title, content, category) {
|
|
||||||
if (uid === 0) {
|
if (uid === 0) {
|
||||||
socket.emit('event:alert', {
|
socket.emit('event:alert', {
|
||||||
title: 'Thank you for posting',
|
title: 'Thank you for posting',
|
||||||
@@ -144,7 +144,6 @@ var RDB = require('./redis.js'),
|
|||||||
// User Details - move this out later
|
// User Details - move this out later
|
||||||
RDB.lpush('uid:' + uid + ':topics', tid);
|
RDB.lpush('uid:' + uid + ':topics', tid);
|
||||||
|
|
||||||
|
|
||||||
socket.emit('event:alert', {
|
socket.emit('event:alert', {
|
||||||
title: 'Thank you for posting',
|
title: 'Thank you for posting',
|
||||||
message: 'You have successfully posted. Click here to view your post.',
|
message: 'You have successfully posted. Click here to view your post.',
|
||||||
|
|||||||
24
src/user.js
24
src/user.js
@@ -7,7 +7,7 @@ var config = require('../config.js'),
|
|||||||
|
|
||||||
(function(User) {
|
(function(User) {
|
||||||
|
|
||||||
User.get = function(uid, fields) {
|
User.get = function(socket, uid, fields) {
|
||||||
if (uid > 0) {
|
if (uid > 0) {
|
||||||
var keys = [],
|
var keys = [],
|
||||||
returnData = {
|
returnData = {
|
||||||
@@ -48,7 +48,7 @@ var config = require('../config.js'),
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
User.login = function(user) {
|
User.login = function(socket, user) {
|
||||||
if (user.username == null || user.password == null) {
|
if (user.username == null || user.password == null) {
|
||||||
return socket.emit('user.login', {'status': 0, 'message': 'Missing fields'});
|
return socket.emit('user.login', {'status': 0, 'message': 'Missing fields'});
|
||||||
}
|
}
|
||||||
@@ -160,7 +160,7 @@ var config = require('../config.js'),
|
|||||||
}
|
}
|
||||||
|
|
||||||
User.create = function(username, password, email, callback) {
|
User.create = function(username, password, email, callback) {
|
||||||
User.exists(username, function(exists) {
|
User.exists(null, username, function(exists) {
|
||||||
if (exists) {
|
if (exists) {
|
||||||
return callback('user-exists', 0);
|
return callback('user-exists', 0);
|
||||||
}
|
}
|
||||||
@@ -187,7 +187,7 @@ var config = require('../config.js'),
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
User.exists = function(username, callback) {
|
User.exists = function(socket, username, callback) {
|
||||||
User.get_uid_by_username(username, function(exists) {
|
User.get_uid_by_username(username, function(exists) {
|
||||||
exists = !!exists;
|
exists = !!exists;
|
||||||
|
|
||||||
@@ -195,12 +195,14 @@ var config = require('../config.js'),
|
|||||||
else socket.emit('user.exists', {exists: exists});
|
else socket.emit('user.exists', {exists: exists});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
User.count = function() {
|
|
||||||
|
User.count = function(socket) {
|
||||||
RDB.get('user:count', function(count) {
|
RDB.get('user:count', function(count) {
|
||||||
socket.emit('user.count', {count: (count === null) ? 0 : count});
|
socket.emit('user.count', {count: (count === null) ? 0 : count});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
User.latest = function() {
|
|
||||||
|
User.latest = function(socket) {
|
||||||
RDB.lrange('user:users', 0, 0, function(username) {
|
RDB.lrange('user:users', 0, 0, function(username) {
|
||||||
socket.emit('user.latest', {username: username});
|
socket.emit('user.latest', {username: username});
|
||||||
});
|
});
|
||||||
@@ -233,7 +235,7 @@ var config = require('../config.js'),
|
|||||||
}
|
}
|
||||||
|
|
||||||
User.reset = {
|
User.reset = {
|
||||||
validate: function(code, callback) {
|
validate: function(socket, code, callback) {
|
||||||
if (typeof callback !== 'function') callback = undefined;
|
if (typeof callback !== 'function') callback = undefined;
|
||||||
|
|
||||||
RDB.get('reset:' + code + ':uid', function(uid) {
|
RDB.get('reset:' + code + ':uid', function(uid) {
|
||||||
@@ -256,7 +258,7 @@ var config = require('../config.js'),
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
send: function(email) {
|
send: function(socket, email) {
|
||||||
User.get_uid_by_email(email, function(uid) {
|
User.get_uid_by_email(email, function(uid) {
|
||||||
if (uid !== null) {
|
if (uid !== null) {
|
||||||
// Generate a new reset code
|
// Generate a new reset code
|
||||||
@@ -305,7 +307,7 @@ var config = require('../config.js'),
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
commit: function(code, password) {
|
commit: function(socket, code, password) {
|
||||||
this.validate(code, function(validated) {
|
this.validate(code, function(validated) {
|
||||||
if (validated) {
|
if (validated) {
|
||||||
RDB.get('reset:' + code + ':uid', function(uid) {
|
RDB.get('reset:' + code + ':uid', function(uid) {
|
||||||
@@ -321,7 +323,7 @@ var config = require('../config.js'),
|
|||||||
}
|
}
|
||||||
|
|
||||||
User.email = {
|
User.email = {
|
||||||
exists: function(email, callback) {
|
exists: function(socket, email, callback) {
|
||||||
User.get_uid_by_email(email, function(exists) {
|
User.get_uid_by_email(email, function(exists) {
|
||||||
exists = !!exists;
|
exists = !!exists;
|
||||||
if (typeof callback !== 'function') socket.emit('user.email.exists', { exists: exists });
|
if (typeof callback !== 'function') socket.emit('user.email.exists', { exists: exists });
|
||||||
@@ -331,7 +333,7 @@ var config = require('../config.js'),
|
|||||||
}
|
}
|
||||||
|
|
||||||
User.active = {
|
User.active = {
|
||||||
get_record : function() {
|
get_record : function(socket) {
|
||||||
RDB.mget(['global:active_user_record', 'global:active_user_record_date'], function(data) {
|
RDB.mget(['global:active_user_record', 'global:active_user_record_date'], function(data) {
|
||||||
socket.emit('api:user.active.get_record', {record: data[0], timestamp: data[1]});
|
socket.emit('api:user.active.get_record', {record: data[0], timestamp: data[1]});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -38,60 +38,66 @@ var SocketIO = require('socket.io').listen(global.server),
|
|||||||
});
|
});
|
||||||
|
|
||||||
io.sockets.on('connection', function(socket) {
|
io.sockets.on('connection', function(socket) {
|
||||||
global.socket = socket;
|
|
||||||
|
|
||||||
if (DEVELOPMENT === true) {
|
if (DEVELOPMENT === true) {
|
||||||
// refreshing templates
|
// refreshing templates
|
||||||
modules.templates.init();
|
modules.templates.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
process.on('uncaughtException', function(err) {
|
||||||
|
// handle the error safely
|
||||||
|
console.log("error message "+err);
|
||||||
|
socket.emit('event:consolelog',{type:'uncaughtException', stack:err.stack, error:err.toString()});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
socket.emit('event:connect', {status: 1});
|
socket.emit('event:connect', {status: 1});
|
||||||
|
|
||||||
// BEGIN: API calls (todo: organize)
|
// BEGIN: API calls (todo: organize)
|
||||||
// julian: :^)
|
// julian: :^)
|
||||||
socket.on('api:user.get', function(data) {
|
socket.on('api:user.get', function(data) {
|
||||||
modules.user.get(uid, data.fields);
|
modules.user.get(socket, uid, data.fields);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('user.exists', function(data) {
|
socket.on('user.exists', function(data) {
|
||||||
modules.user.exists(data.username);
|
modules.user.exists(socket, data.username);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('user.count', function(data) {
|
socket.on('user.count', function(data) {
|
||||||
modules.user.count(data);
|
modules.user.count(socket, data);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('user.latest', function(data) {
|
socket.on('user.latest', function(data) {
|
||||||
modules.user.latest(data);
|
modules.user.latest(socket, data);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('user.login', function(data) {
|
socket.on('user.login', function(data) {
|
||||||
data.sessionID = sessionID;
|
data.sessionID = sessionID;
|
||||||
modules.user.login(data);
|
modules.user.login(socket, data);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('user.email.exists', function(data) {
|
socket.on('user.email.exists', function(data) {
|
||||||
modules.user.email.exists(data.email);
|
modules.user.email.exists(socket, data.email);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('user:reset.send', function(data) {
|
socket.on('user:reset.send', function(data) {
|
||||||
modules.user.reset.send(data.email);
|
modules.user.reset.send(socket, data.email);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('user:reset.valid', function(data) {
|
socket.on('user:reset.valid', function(data) {
|
||||||
modules.user.reset.validate(data.code);
|
modules.user.reset.validate(socket, data.code);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('user:reset.commit', function(data) {
|
socket.on('user:reset.commit', function(data) {
|
||||||
modules.user.reset.commit(data.code, data.password);
|
modules.user.reset.commit(socket, data.code, data.password);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('api:topics.post', function(data) {
|
socket.on('api:topics.post', function(data) {
|
||||||
modules.topics.post(uid, data.title, data.content);
|
modules.topics.post(socket, uid, data.title, data.content);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('api:posts.reply', function(data) {
|
socket.on('api:posts.reply', function(data) {
|
||||||
modules.posts.reply(data.topic_id, uid, data.content);
|
modules.posts.reply(socket, data.topic_id, uid, data.content);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('api:user.active.get', function() {
|
socket.on('api:user.active.get', function() {
|
||||||
@@ -99,7 +105,7 @@ var SocketIO = require('socket.io').listen(global.server),
|
|||||||
});
|
});
|
||||||
|
|
||||||
socket.on('api:user.active.get_record', function() {
|
socket.on('api:user.active.get_record', function() {
|
||||||
modules.user.active.get_record();
|
modules.user.active.get_record(socket);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user