most users ever online block

v1.18.x
psychobunny 12 years ago
parent bb8d5098e4
commit a655ebb290

@ -4,7 +4,7 @@
<!-- START Forum Info -->
<div id="footer" class="container" style="padding-top: 50px;">
<div class="alert alert-info">
<span id="active_users"></span><br />
<span id="active_users"></span>; <span id="active_record"></span><br />
<span id="number_of_users"></span><br />
<span id="latest_user"></span>
</div>
@ -16,7 +16,8 @@
var num_users = document.getElementById('number_of_users'),
latest_user = document.getElementById('latest_user'),
active_users = document.getElementById('active_users'),
user_label = document.getElementById('user_label');
user_label = document.getElementById('user_label'),
active_record = document.getElementById('active_record');
socket.emit('user.count', {});
socket.on('user.count', function(data) {
@ -32,7 +33,14 @@
});
socket.emit('api:user.active.get');
socket.on('api:user.active.get', function(data) {
active_users.innerHTML = 'There ' + (parseInt(data.users) !== 1 ? 'are' : 'is') + ' <strong>' + data.users + '</strong> user' + (parseInt(data.users) !== 1 ? 's' : '') + ' and <strong>' + data.anon + '</strong> guest' + (parseInt(data.anon) !== 1 ? 's' : '') + ' online';
var plural_users = parseInt(data.users) !== 1,
plural_anon = parseInt(data.anon) !== 1;
active_users.innerHTML = 'There ' + (plural_users ? 'are' : 'is') + ' <strong>' + data.users + '</strong> user' + (plural_users ? 's' : '') + ' and <strong>' + data.anon + '</strong> guest' + (plural_anon ? 's' : '') + ' online';
});
socket.emit('api:user.active.get_record');
socket.on('api:user.active.get_record', function(data) {
active_record.innerHTML = "most users ever online was <strong>" + data + "</strong>";
});
socket.emit('api:user.get', { fields: ['username', 'picture'] });
socket.on('api:user.get', function(data) {

@ -27,7 +27,7 @@ var config = require('../config.js'),
for(var x=0,numData=data.length;x<numData;x++) {
returnData[fields[x]] = data[x];
}
console.log(returnData);
if (returnData.picture !== undefined) {
var md5sum = crypto.createHash('md5');
md5sum.update(returnData.email.toLowerCase());
@ -47,17 +47,17 @@ var config = require('../config.js'),
User.login = function(user) {
if (user.username == null || user.password == null) {
return global.socket.emit('user.login', {'status': 0, 'message': 'Missing fields'});
return socket.emit('user.login', {'status': 0, 'message': 'Missing fields'});
}
RDB.get('username:' + user.username + ':uid', function(uid) {
if (uid == null) {
return global.socket.emit('user.login', {'status': 0, 'message': 'Username does not exist.'});
return socket.emit('user.login', {'status': 0, 'message': 'Username does not exist.'});
}
RDB.get('uid:' + uid + ':password', function(password) {
if (user.password != password) {
return global.socket.emit('user.login', {'status': 0, 'message': 'Incorrect username / password combination.'});
return socket.emit('user.login', {'status': 0, 'message': 'Incorrect username / password combination.'});
} else {
// Start, replace, or extend a session
RDB.get('sess:' + user.sessionID, function(session) {
@ -88,7 +88,7 @@ var config = require('../config.js'),
User.create = function(username, password, email) {
if (username == null || password == null) {
return; global.socket.emit('user.create', {'status': 0, 'message': 'Missing fields'});
return; socket.emit('user.create', {'status': 0, 'message': 'Missing fields'});
}
@ -111,9 +111,9 @@ var config = require('../config.js'),
RDB.lpush('user:users', username);
io.sockets.emit('user.latest', {username: username});
global.socket.emit('user.create', {'status': 1});
socket.emit('user.create', {'status': 1});
global.socket.emit('event:alert', {
socket.emit('event:alert', {
title: 'Thank you for registering',
message: 'You have successfully registered - welcome to nodebb!',
type: 'notify',
@ -127,7 +127,7 @@ var config = require('../config.js'),
User.exists = function(username, callback) {
User.get_uid_by_username(username, function(exists) {
exists = !!exists;
global.socket.emit('user.exists', {exists: exists})
socket.emit('user.exists', {exists: exists})
if (callback) {
callback(exists);
@ -136,12 +136,12 @@ var config = require('../config.js'),
};
User.count = function() {
RDB.get('user:count', function(count) {
global.socket.emit('user.count', {count: (count === null) ? 0 : count});
socket.emit('user.count', {count: (count === null) ? 0 : count});
});
};
User.latest = function() {
RDB.lrange('user:users', 0, 0, function(username) {
global.socket.emit('user.latest', {username: username});
socket.emit('user.latest', {username: username});
});
}
@ -165,18 +165,18 @@ var config = require('../config.js'),
if (uid !== null) {
RDB.get('reset:' + code + ':expiry', function(expiry) {
if (expiry >= +new Date()/1000|0) {
if (!callback) global.socket.emit('user:reset.valid', { valid: true });
if (!callback) socket.emit('user:reset.valid', { valid: true });
else callback(true);
} else {
// Expired, delete from db
RDB.del('reset:' + code + ':uid');
RDB.del('reset:' + code + ':expiry');
if (!callback) global.socket.emit('user:reset.valid', { valid: false });
if (!callback) socket.emit('user:reset.valid', { valid: false });
else callback(false);
}
});
} else {
if (!callback) global.socket.emit('user:reset.valid', { valid: false });
if (!callback) socket.emit('user:reset.valid', { valid: false });
else callback(false);
}
});
@ -208,13 +208,13 @@ var config = require('../config.js'),
emailjsServer.send(message, function(err, success) {
if (err === null) {
global.socket.emit('user.send_reset', {
socket.emit('user.send_reset', {
status: "ok",
message: "code-sent",
email: email
});
} else {
global.socket.emit('user.send_reset', {
socket.emit('user.send_reset', {
status: "error",
message: "send-failed"
});
@ -222,7 +222,7 @@ var config = require('../config.js'),
}
});
} else {
global.socket.emit('user.send_reset', {
socket.emit('user.send_reset', {
status: "error",
message: "invalid-email",
email: email
@ -238,7 +238,7 @@ var config = require('../config.js'),
RDB.del('reset:' + code + ':uid');
RDB.del('reset:' + code + ':expiry');
global.socket.emit('user:reset.commit', { status: 'ok' });
socket.emit('user:reset.commit', { status: 'ok' });
});
}
});
@ -249,14 +249,28 @@ var config = require('../config.js'),
exists: function(email, callback) {
User.get_uid_by_email(email, function(exists) {
exists = !!exists;
if (typeof callback !== 'function') global.socket.emit('user.email.exists', { exists: exists });
if (typeof callback !== 'function') socket.emit('user.email.exists', { exists: exists });
else callback(exists);
});
}
}
User.active = {
get_record : function() {
RDB.get('global:active_user_record', function(record) {
socket.emit('api:user.active.get_record', record);
});
},
get: function(callback) {
function user_record(total) {
RDB.get('global:active_user_record', function(record) {
if (total > record) {
RDB.set('global:active_user_record', total);
}
});
}
RDB.keys('active:*', function(active) {
var returnObj = {
users: 0,
@ -282,6 +296,8 @@ var config = require('../config.js'),
}
}
user_record(returnObj.anon + returnObj.users);
if (callback === undefined) {
io.sockets.emit('api:user.active.get', returnObj)
} else {

@ -96,6 +96,10 @@ var SocketIO = require('socket.io').listen(global.server),
socket.on('api:user.active.get', function() {
modules.user.active.get();
});
socket.on('api:user.active.get_record', function() {
modules.user.active.get_record();
});
});
}(SocketIO));

Loading…
Cancel
Save