users page

v1.18.x
Baris Soner Usakli 12 years ago
parent 781c99295c
commit 8710aa3457

@ -362,3 +362,9 @@ footer.footer {
color: white;
padding: 30px;
}
.users-box{
display:inline-block;
margin:20px;
text-align:center;
}

@ -1,5 +1,19 @@
<h1>Users</h1>
<div>
<!-- BEGIN users -->
<div class="users-box well">
<a href="/users/{users.username}">
<img src="{users.picture}"/>
</a>
<br/>
<a href="/users/{users.username}">{users.username}</a>
<br/>
<span title="reputation">{users.reputation}</span><br/>
<span title="postcount">{users.postcount}</span><br/>
</div>
<!-- END users -->
</div>

@ -178,7 +178,7 @@ var RDB = require('./redis.js'),
// User Details - move this out later
RDB.lpush('uid:' + uid + ':posts', pid);
RDB.db.hincrby(uid, 'postcount', 1);
user.incrementUserFieldBy(uid, 'postcount', 1);
if (callback)
callback(pid);
@ -196,7 +196,7 @@ var RDB = require('./redis.js'),
if (hasFavourited == false) {
RDB.sadd('pid:' + pid + ':users_favourited', uid);
RDB.db.hincrby(String(uid_of_poster), 'reputation', 1);
user.incrementUserFieldBy(uid_of_poster, 'reputation', 1);
RDB.incr('pid:' + pid + ':rep');
@ -212,8 +212,9 @@ var RDB = require('./redis.js'),
RDB.get('pid:' + pid + ':uid', function(uid_of_poster) {
Posts.hasFavourited(pid, uid, function(hasFavourited) {
if (hasFavourited == true) {
RDB.srem('pid:' + pid + ':users_favourited', uid);
RDB.db.hincrby(String(uid_of_poster), 'reputation', -1);
user.incrementUserFieldBy(uid_of_poster, 'reputation', -1);
RDB.decr('pid:' + pid + ':rep');
if (room_id) {

@ -10,7 +10,7 @@ var config = require('../config.js'),
User.getUserField = function(uid, field, callback) {
RDB.db.hget(String(uid), field, function(err, data){
RDB.db.hget('user:'+uid, field, function(err, data){
if(err === null)
callback(data);
else
@ -19,7 +19,7 @@ var config = require('../config.js'),
}
User.getUserFields = function(uid, fields, callback) {
RDB.db.hmget(String(uid), fields, function(err, data){
RDB.db.hmget('user:'+uid, fields, function(err, data){
if(err === null) {
var returnData = {};
@ -57,7 +57,7 @@ var config = require('../config.js'),
User.getUserData = function(uid, callback) {
RDB.db.hgetall(String(uid), function(err, data){
RDB.db.hgetall('user:'+uid, function(err, data){
if(err === null)
{
if(data && data['password'])
@ -70,15 +70,35 @@ var config = require('../config.js'),
}
User.setUserField = function(uid, field, value) {
RDB.db.hset(String(uid), field, value);
RDB.db.hset('user:'+uid, field, value);
}
User.incrementUserFieldBy = function(uid, field, value) {
RDB.db.hincrby('user:'+uid, field, value);
}
User.getUserList = function(callback){
RDB.db.lrange('user:users', 0, -1, function(err, data) {
var data = [];
RDB.db.keys('user:*', function(err, userkeys){
for(var i=0,ii=userkeys.length; i<ii; ++i) {
RDB.db.hgetall(userkeys[i], function(err, userdata) {
if(userdata && userdata.password)
delete userdata.password;
data.push(userdata);
if(data.length == userkeys.length)
callback(data);
});
}
});
}
User.loginViaLocal = function(username, password, next) {
if (!username || !password) {
@ -218,7 +238,7 @@ var config = require('../config.js'),
User.hashPassword(password, function(hash) {
RDB.db.hmset(String(uid), {
RDB.db.hmset('user:'+uid, {
'username' : username,
'email' : email,
'joindate' : new Date().getTime(),
@ -234,11 +254,11 @@ var config = require('../config.js'),
if(email)
User.sendConfirmationEmail(email);
RDB.incr('user:count', function(count) {
RDB.incr('usercount', function(count) {
io.sockets.emit('user.count', {count: count});
});
RDB.lpush('user:users', username);
RDB.lpush('userlist', username);
io.sockets.emit('user.latest', {username: username});
callback(null, uid);
@ -315,13 +335,13 @@ var config = require('../config.js'),
};
User.count = function(socket) {
RDB.get('user:count', function(count) {
RDB.get('usercount', function(count) {
socket.emit('user.count', {count: (count === null) ? 0 : count});
});
};
User.latest = function(socket) {
RDB.lrange('user:users', 0, 0, function(username) {
RDB.lrange('userlist', 0, 0, function(username) {
socket.emit('user.latest', {username: username});
});
}
@ -458,7 +478,7 @@ var config = require('../config.js'),
if (validated) {
RDB.get('reset:' + code + ':uid', function(uid) {
RDB.db.hset(String(uid), 'password', password);
User.setUserField(uid, 'password', password);
RDB.del('reset:' + code + ':uid');
RDB.del('reset:' + code + ':expiry');

@ -220,7 +220,13 @@ passport.deserializeUser(function(uid, done) {
});
break;
case 'users' :
if (String(req.params.section).toLowerCase() === 'edit') {
if (!req.params.section && !req.params.id) {
console.log("PURE USERS");
get_users_fn(req, res, function(userData) {
res.send(JSON.stringify(userData));
});
}
else if (String(req.params.section).toLowerCase() === 'edit') {
get_account_fn(req, res, function(userData) {
res.send(JSON.stringify(userData));
});
@ -229,6 +235,7 @@ passport.deserializeUser(function(uid, done) {
res.send(JSON.stringify(userData));
});
}
break;
case 'confirm':
global.modules.user.email.confirm(req.params.id, function(data) {
@ -372,9 +379,12 @@ passport.deserializeUser(function(uid, done) {
});
});
}
function get_users_fn(req, res, callback) {
user.getUserList(function(data){
callback({users:data});
});
}
@ -393,9 +403,9 @@ passport.deserializeUser(function(uid, done) {
});
app.get('/users', function(req, res) {
console.log("ARE U HERE");
user.getUserList(function(data){
//res.send(data);
res.send(templates['header'] + create_route("users", "users") + templates['footer']);
});
@ -403,11 +413,9 @@ passport.deserializeUser(function(uid, done) {
});
app.get('/users/:uid/edit', function(req, res){
console.log("OPPA");
if(req.user && req.params.uid)
{
//res.send("editing user");
res.send(templates['header'] + '<script>templates.ready(function(){ajaxify.go("users/' + req.params.uid+'/edit");});</script>' + templates['footer']);
}
else

Loading…
Cancel
Save