added join date to users, fixed post count when a new topic is created. account page shows time joined,picture and name

v1.18.x
Baris Soner Usakli 12 years ago
parent 750e087f9e
commit 73e958e627

@ -5,11 +5,25 @@
<strong></strong>
<p></p>
</div>
<!-- BEGIN user -->
<img src="{user.picture}" />
<br/>
<span>{user.username}</span>
<br/>
<label for="email">Email Address</label><input type="text" placeholder="Enter Email Address" id="email" /><br />
<button class="btn btn-primary" id="reset" type="submit">Reset Password</button>
<p>
If you see this, you are logged in.
</p>
<br/>
<span>Member for </span>
<span id="membersince">{user.joindate}</span>
<br/>
<!-- END user -->
</div>
<script type="text/javascript">
(function() {

@ -3,7 +3,7 @@
<!-- BEGIN topics -->
<a href="topic/{topics.slug}"><li class="topic-row">
<h4>{topics.title}</h4>
<p>Posted {topics.relativeTime} by <span class="username">{topics.username}</span>. {topics.post_count} posts.</p>
<p>Posted {topics.relativeTime} ago by <span class="username">{topics.username}</span>. {topics.post_count} posts.</p>
</li></a>
<!-- END topics -->
</ul>

@ -17,7 +17,7 @@
<div class="post-block">
<div id="content_{posts.pid}" class="post-content">{posts.content}</div>
<div class="profile-block">
<img class="hidden-desktop" src="{posts.gravatar}10" align="left" /> posted by <strong>{posts.username}</strong> {posts.relativeTime}
<img class="hidden-desktop" src="{posts.gravatar}10" align="left" /> posted by <strong>{posts.username}</strong> {posts.relativeTime} ago
<span class="post-buttons">
<div id="ids_{posts.pid}_{posts.uid}" class="edit {posts.display_moderator_tools} hidden-phone"><i class="icon-pencil"></i></div>
<div id="ids_{posts.pid}_{posts.uid}" class="delete {posts.display_moderator_tools} hidden-phone"><i class="icon-trash"></i></div>

@ -143,8 +143,6 @@ var RDB = require('./redis.js'),
RDB.set('tid:' + tid + ':uid', uid);
RDB.set('tid:' + tid + ':slug', slug);
RDB.set('tid:' + tid + ':timestamp', new Date().getTime());
RDB.incr('tid:' + tid + ':postcount');
RDB.set('topic:slug:' + slug + ':tid', tid);

@ -16,7 +16,9 @@ var config = require('../config.js'),
},
removeEmail = false;
if (!(fields instanceof Array)) fields = ['username', 'email'];
if (!(fields instanceof Array))
fields = ['username', 'email', 'joindate'];
if (fields.indexOf('picture') !== -1 && fields.indexOf('email') === -1) {
fields.push('email');
removeEmail = true;
@ -49,6 +51,35 @@ var config = require('../config.js'),
}
}
User.getUserData = function(uid, callback) {
var fields = ['username', 'email', 'joindate', 'picture'];
var keys = [];
for(var i = 0, numFields = fields.length; i<numFields; i++) {
keys.push('uid:' + uid + ':' + fields[i]);
}
RDB.mget(keys, function(data) {
var returnData = {
uid: uid
};
for(var i=0, numData=data.length; i<numData; i++) {
returnData[fields[i]] = data[i];
}
var md5sum = crypto.createHash('md5');
md5sum.update(returnData.email.toLowerCase());
returnData.picture = 'http://www.gravatar.com/avatar/' + md5sum.digest('hex') + '?s=24';
callback(returnData);
});
}
User.get_gravatars_by_uids = function(uids, size, callback) {
var keys = [];
@ -244,11 +275,14 @@ var config = require('../config.js'),
});
});
}
if (email) {
RDB.set('uid:' + uid + ':email', email);
RDB.set('email:' + email, uid);
}
RDB.set('uid:' + uid + ':joindate', new Date().getTime());
RDB.incr('user:count', function(count) {
io.sockets.emit('user.count', {count: count});
});

@ -5,21 +5,22 @@ var utils = {
return v.toString(16);
});
},
relativeTime: function(timestamp) {
var now = +new Date(),
difference = now - Math.floor(parseFloat(timestamp));
difference = Math.floor(difference / 1000);
if (difference < 60) return difference + ' second' + (difference !== 1 ? 's' : '') + ' ago';
if (difference < 60) return difference + ' second' + (difference !== 1 ? 's' : '');
difference = Math.floor(difference / 60);
if (difference < 60) return difference + ' minute' + (difference !== 1 ? 's' : '') + ' ago';
if (difference < 60) return difference + ' minute' + (difference !== 1 ? 's' : '');
difference = Math.floor(difference / 60);
if (difference < 24) return difference + ' hour' + (difference !== 1 ? 's' : '') + ' ago';
if (difference < 24) return difference + ' hour' + (difference !== 1 ? 's' : '');
difference = Math.floor(difference / 24);
if (difference < 3) return difference + ' day' + (difference !== 1 ? 's' : '') + ' ago';
if (difference < 3) return difference + ' day' + (difference !== 1 ? 's' : '');
// Lastly, just return a formatted date
var date = new Date(timestamp);
@ -30,6 +31,8 @@ var utils = {
// months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
return date.toDateString();
}
}
module.exports = utils;

@ -11,6 +11,8 @@ var express = require('express'),
passportTwitter = require('passport-twitter').Strategy,
passportGoogle = require('passport-google-oauth').OAuth2Strategy,
passportFacebook = require('passport-facebook').Strategy,
user = require('./user.js'),
utils = require('./utils.js'),
login_strategies = [];
passport.use(new passportLocal(function(user, password, next) {
@ -254,7 +256,17 @@ passport.deserializeUser(function(uid, done) {
if (req.user === undefined)
return res.redirect('/403');
res.send(templates['header'] + templates['account'] + templates['footer']);
user.getUserData(req.user.uid, function(data) {
data.joindate = utils.relativeTime(data.joindate);
var account = templates['account'];
var userData = {user:data};
account = account.parse(userData);
res.send(templates['header'] + account + templates['footer']);
});
});
app.get('/users', function(req, res) {

Loading…
Cancel
Save