formatting - routes

v1.18.x
psychobunny 12 years ago
parent aea3181d27
commit 1780b343b4

@ -1,4 +1,3 @@
var user = require('./../user.js'),
Groups = require('../groups'),
topics = require('./../topics.js'),
@ -18,7 +17,7 @@ var user = require('./../user.js'),
Admin.build_header = function(res) {
return templates['admin/header'].parse({
csrf:res.locals.csrf_token,
csrf: res.locals.csrf_token,
relative_path: nconf.get('relative_path')
});
}
@ -26,14 +25,14 @@ var user = require('./../user.js'),
Admin.create_routes = function(app) {
(function() {
var routes = [
'categories/active', 'categories/disabled', 'users', 'topics', 'settings', 'themes',
'twitter', 'facebook', 'gplus', 'redis', 'motd', 'groups',
'users/latest', 'users/sort-posts', 'users/sort-reputation',
'users/search', 'plugins'
];
for (var i=0, ii=routes.length; i<ii; i++) {
var routes = [
'categories/active', 'categories/disabled', 'users', 'topics', 'settings', 'themes',
'twitter', 'facebook', 'gplus', 'redis', 'motd', 'groups',
'users/latest', 'users/sort-posts', 'users/sort-reputation',
'users/search', 'plugins'
];
for (var i = 0, ii = routes.length; i < ii; i++) {
(function(route) {
app.get('/admin/' + route, Admin.isAdmin, function(req, res) {
res.send(Admin.build_header(res) + app.create_route('admin/' + route) + templates['admin/footer']);
@ -43,7 +42,7 @@ var user = require('./../user.js'),
var unit_tests = ['categories'];
for (var i=0, ii=unit_tests.length; i<ii; i++) {
for (var i = 0, ii = unit_tests.length; i < ii; i++) {
(function(route) {
app.get('/admin/testing/' + route, Admin.isAdmin, function(req, res) {
res.send(Admin.build_header(res) + app.create_route('admin/testing/' + route) + templates['admin/footer']);
@ -56,40 +55,65 @@ var user = require('./../user.js'),
app.get('/admin', Admin.isAdmin, function(req, res) {
res.send(Admin.build_header(res) + app.create_route('admin/index') + templates['admin/footer']);
});
app.get('/admin/index', Admin.isAdmin, function(req, res) {
res.send(Admin.build_header(res) + app.create_route('admin/index') + templates['admin/footer']);
});
app.get('/api/admin/index', function(req, res) {
res.json({version:pkg.version});
res.json({
version: pkg.version
});
});
app.get('/api/admin/users/search', function(req, res) {
res.json({search_display: 'block', loadmore_display:'none', users: []});
res.json({
search_display: 'block',
loadmore_display: 'none',
users: []
});
});
app.get('/api/admin/users/latest', function(req, res) {
user.getUsers('users:joindate', 0, 49, function(err, data) {
res.json({ search_display: 'none', loadmore_display:'block', users:data, yourid:req.user.uid });
res.json({
search_display: 'none',
loadmore_display: 'block',
users: data,
yourid: req.user.uid
});
});
});
app.get('/api/admin/users/sort-posts', function(req, res) {
user.getUsers('users:postcount', 0, 49, function(err, data) {
res.json({ search_display: 'none', loadmore_display:'block', users:data, yourid:req.user.uid });
res.json({
search_display: 'none',
loadmore_display: 'block',
users: data,
yourid: req.user.uid
});
});
});
app.get('/api/admin/users/sort-reputation', function(req, res) {
user.getUsers('users:reputation', 0, 49, function(err, data) {
res.json({ search_display: 'none', loadmore_display:'block', users:data, yourid:req.user.uid });
res.json({
search_display: 'none',
loadmore_display: 'block',
users: data,
yourid: req.user.uid
});
});
});
app.get('/api/admin/users', function(req, res) {
user.getUsers('users:joindate', 0, 49, function(err, data) {
res.json({ search_display: 'none', users:data, yourid:req.user.uid });
res.json({
search_display: 'none',
users: data,
yourid: req.user.uid
});
});
});
@ -130,24 +154,24 @@ var user = require('./../user.js'),
data = data.split("\r\n");
var finalData = {};
for(var i in data) {
if(data[i].indexOf(':') == -1 || !data[i])
for (var i in data) {
if (data[i].indexOf(':') == -1 || !data[i])
continue;
try {
data[i] = data[i].replace(/:/,"\":\"");
data[i] = data[i].replace(/:/, "\":\"");
var json = "{\"" + data[i] + "\"}";
var jsonObject = JSON.parse(json);
for(var key in jsonObject) {
for (var key in jsonObject) {
finalData[key] = jsonObject[key];
}
} catch(err){
} catch (err) {
winston.warn('can\'t parse redis status variable, ignoring', i, data[i], err);
}
}
res.json(finalData);
});
});

@ -22,7 +22,7 @@ var user = require('./../user.js'),
config['postDelay'] = meta.config['postDelay'];
config['minimumTitleLength'] = meta.config['minimumTitleLength'];
config['minimumPostLength'] = meta.config['minimumPostLength'];
config['imgurClientIDSet'] = !!meta.config['imgurClientID'];
config['imgurClientIDSet'] = !! meta.config['imgurClientID'];
config['minimumUsernameLength'] = meta.config['minimumUsernameLength'];
config['maximumUsernameLength'] = meta.config['maximumUsernameLength'];
config['minimumPasswordLength'] = meta.config['minimumPasswordLength'];
@ -41,7 +41,7 @@ var user = require('./../user.js'),
function iterator(category, callback) {
categories.getRecentReplies(category.cid, 2, function(posts) {
category["posts"] = posts;
category["post_count"] = posts.length>2 ? 2 : posts.length;
category["post_count"] = posts.length > 2 ? 2 : posts.length;
callback(null);
});
}
@ -70,7 +70,7 @@ var user = require('./../user.js'),
'login_window:spansize': 'col-md-6',
'alternate_logins:display': 'block'
}
for (var i=0, ii=num_strategies; i<ii; i++) {
for (var i = 0, ii = num_strategies; i < ii; i++) {
data[login_strategies[i] + ':display'] = 'active';
}
}
@ -95,7 +95,7 @@ var user = require('./../user.js'),
'register_window:spansize': 'col-md-6',
'alternate_logins:display': 'block'
}
for (var i=0, ii=num_strategies; i<ii; i++) {
for (var i = 0, ii = num_strategies; i < ii; i++) {
data[login_strategies[i] + ':display'] = 'active';
}
}
@ -111,7 +111,7 @@ var user = require('./../user.js'),
var uid = (req.user) ? req.user.uid : 0;
topics.getTopicWithPosts(req.params.id, uid, 0, 10, function(err, data) {
if (!err) {
if(data.deleted === '1' && data.expose_tools === 0) {
if (data.deleted === '1' && data.expose_tools === 0) {
return res.json(404, {});
}
res.json(data);
@ -184,11 +184,11 @@ var user = require('./../user.js'),
app.get('/api/search', function(req, res) {
return res.json({
show_no_topics:'hide',
show_no_posts:'hide',
search_query:'',
posts:[],
topics:[]
show_no_topics: 'hide',
show_no_posts: 'hide',
search_query: '',
posts: [],
topics: []
});
});
@ -206,11 +206,11 @@ var user = require('./../user.js'),
function searchPosts(callback) {
search(postSearch, function(err, pids) {
if(err)
if (err)
return callback(err, null);
posts.getPostSummaryByPids(pids, function(err, posts) {
if(err)
if (err)
return callback(err, null);
callback(null, posts);
});
@ -219,7 +219,7 @@ var user = require('./../user.js'),
function searchTopics(callback) {
search(topicSearch, function(err, tids) {
if(err)
if (err)
return callback(err, null);
topics.getTopicsByTids(tids, 0, function(topics) {
@ -233,11 +233,11 @@ var user = require('./../user.js'),
return next();
return res.json({
show_no_topics: results[1].length? 'hide':'',
show_no_posts: results[0].length? 'hide':'',
search_query:req.params.term,
posts:results[0],
topics:results[1]
show_no_topics: results[1].length ? 'hide' : '',
show_no_posts: results[0].length ? 'hide' : '',
search_query: req.params.term,
posts: results[0],
topics: results[1]
});
});
});
@ -247,7 +247,9 @@ var user = require('./../user.js'),
});
app.get('/api/reset/:code', function(req, res) {
res.json({ reset_code: req.params.code });
res.json({
reset_code: req.params.code
});
});
app.get('/api/404', function(req, res) {
@ -258,4 +260,4 @@ var user = require('./../user.js'),
res.json({});
});
}
}(exports));
}(exports));

@ -25,7 +25,9 @@
callbackURL: nconf.get('url') + 'auth/twitter/callback'
}, function(token, tokenSecret, profile, done) {
login_module.loginViaTwitter(profile.id, profile.username, profile.photos, function(err, user) {
if (err) { return done(err); }
if (err) {
return done(err);
}
done(null, user);
});
}));
@ -40,7 +42,9 @@
callbackURL: nconf.get('url') + 'auth/google/callback'
}, function(accessToken, refreshToken, profile, done) {
login_module.loginViaGoogle(profile.id, profile.displayName, profile.emails[0].value, function(err, user) {
if (err) { return done(err); }
if (err) {
return done(err);
}
done(null, user);
});
}));
@ -55,7 +59,9 @@
callbackURL: nconf.get('url') + 'auth/facebook/callback'
}, function(accessToken, refreshToken, profile, done) {
login_module.loginViaFacebook(profile.id, profile.displayName, profile.emails[0].value, function(err, user) {
if (err) { return done(err); }
if (err) {
return done(err);
}
done(null, user);
});
}));
@ -90,7 +96,10 @@
winston.info('[Auth] Session ' + req.sessionID + ' logout (uid: ' + req.user.uid + ')');
login_module.logout(req.sessionID, function(logout) {
req.logout();
app.build_header({ req: req, res: res }, function(err, header) {
app.build_header({
req: req,
res: res
}, function(err, header) {
res.send(header + templates['logout'] + templates['footer']);
});
});
@ -107,7 +116,9 @@
}
if (login_strategies.indexOf('google') !== -1) {
app.get('/auth/google', passport.authenticate('google', { scope: 'https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email' }));
app.get('/auth/google', passport.authenticate('google', {
scope: 'https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email'
}));
app.get('/auth/google/callback', passport.authenticate('google', {
successRedirect: '/',
@ -116,7 +127,9 @@
}
if (login_strategies.indexOf('facebook') !== -1) {
app.get('/auth/facebook', passport.authenticate('facebook', { scope: 'email' }));
app.get('/auth/facebook', passport.authenticate('facebook', {
scope: 'email'
}));
app.get('/auth/facebook/callback', passport.authenticate('facebook', {
successRedirect: '/',
@ -127,29 +140,41 @@
app.get('/reset/:code', function(req, res) {
app.build_header({ req: req, res: res }, function(err, header) {
res.send(header + app.create_route('reset/'+req.params.code) + templates['footer']);
app.build_header({
req: req,
res: res
}, function(err, header) {
res.send(header + app.create_route('reset/' + req.params.code) + templates['footer']);
});
});
app.get('/reset', function(req, res) {
app.build_header({ req: req, res: res }, function(err, header) {
app.build_header({
req: req,
res: res
}, function(err, header) {
res.send(header + app.create_route('reset') + templates['footer']);
});
});
app.post('/login', function(req, res, next) {
passport.authenticate('local', function(err, user, info) {
if(err) {
if (err) {
return next(err);
}
if (!user) {
return res.send({ success : false, message : info.message });
return res.send({
success: false,
message: info.message
});
}
req.login({
uid: user.uid
}, function() {
res.send({ success : true, message : 'authentication succeeded' });
res.send({
success: true,
message: 'authentication succeeded'
});
});
})(req, res, next);
});

@ -1,11 +1,9 @@
(function(TestBed) {
TestBed.create_routes = function(app) {
app.get('/bench/forloop', function(req, res) {
var benchData = {};
var myArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20];
function f(x) {
@ -13,62 +11,62 @@
}
var runCount = req.query.runs ? req.query.runs : 1000000;
function withCaching() {
var time = process.hrtime();
for(var n=0; n<runCount; ++n) {
for (var n = 0; n < runCount; ++n) {
for (var i = 0, len = myArray.length; i < len; ++i) {
f(myArray[i]);
}
}
var diff = process.hrtime(time);
diff = diff[0] + diff[1] / 1e9;
return diff;
}
function withoutCaching() {
var time = process.hrtime();
for(var n=0; n<runCount; ++n) {
for (var n = 0; n < runCount; ++n) {
for (var i = 0; i < myArray.length; ++i) {
f(myArray[i]);
}
}
var diff = process.hrtime(time);
diff = diff[0] + diff[1] / 1e9;
return diff;
}
function withForeach() {
var time = process.hrtime();
for(var n=0; n<runCount; ++n) {
for (var n = 0; n < runCount; ++n) {
myArray.forEach(function(index) {
});
}
var diff = process.hrtime(time);
diff = diff[0] + diff[1] / 1e9;
return diff;
}
benchData['runs'] = runCount;
benchData['withCaching'] = withCaching();
benchData['withoutCaching'] = withoutCaching();
benchData['withForeach'] = withForeach();
res.json(benchData);
});
};

@ -11,63 +11,83 @@ var user = require('./../user.js'),
app.get('/uid/:uid', function(req, res) {
if(!req.params.uid)
if (!req.params.uid)
return res.redirect('/404');
user.getUserData(req.params.uid, function(err, data) {
if(data) {
if (data) {
res.send(data);
} else {
res.json(404, {error:"User doesn't exist!"});
res.json(404, {
error: "User doesn't exist!"
});
}
});
});
app.get('/users', function(req, res) {
app.build_header({ req: req, res: res }, function(err, header) {
app.build_header({
req: req,
res: res
}, function(err, header) {
res.send(header + app.create_route("users", "users") + templates['footer']);
});
});
app.get('/users-latest', function(req, res) {
app.build_header({ req: req, res: res }, function(err, header) {
app.build_header({
req: req,
res: res
}, function(err, header) {
res.send(header + app.create_route("users-latest", "users") + templates['footer']);
});
});
app.get('/users-sort-posts', function(req, res) {
app.build_header({ req: req, res: res }, function(err, header) {
app.build_header({
req: req,
res: res
}, function(err, header) {
res.send(header + app.create_route("users-sort-posts", "users") + templates['footer']);
});
});
app.get('/users-sort-reputation', function(req, res) {
app.build_header({ req: req, res: res }, function(err, header) {
app.build_header({
req: req,
res: res
}, function(err, header) {
res.send(header + app.create_route("users-sort-reputation", "users") + templates['footer']);
});
});
app.get('/users-search', function(req, res) {
app.build_header({ req: req, res: res }, function(err, header) {
app.build_header({
req: req,
res: res
}, function(err, header) {
res.send(header + app.create_route("users-search", "users") + templates['footer']);
});
});
app.get('/users/:userslug', function(req, res, next) {
if(!req.params.userslug) {
if (!req.params.userslug) {
next();
return;
}
user.get_uid_by_userslug(req.params.userslug, function(err, uid) {
if(!uid) {
if (!uid) {
return next();
}
app.build_header({ req: req, res: res }, function(err, header) {
res.send(header + app.create_route('users/' + req.params.userslug, 'account') + templates['footer']);
app.build_header({
req: req,
res: res
}, function(err, header) {
res.send(header + app.create_route('users/' + req.params.userslug, 'account') + templates['footer']);
});
});
@ -75,13 +95,16 @@ var user = require('./../user.js'),
app.get('/users/:userslug/edit', function(req, res) {
if(!req.user)
if (!req.user)
return res.redirect('/403');
user.getUserField(req.user.uid, 'userslug', function(err, userslug) {
if(req.params.userslug && userslug === req.params.userslug) {
app.build_header({ req: req, res: res }, function(err, header) {
res.send(header + app.create_route('users/'+req.params.userslug+'/edit','accountedit') + templates['footer']);
if (req.params.userslug && userslug === req.params.userslug) {
app.build_header({
req: req,
res: res
}, function(err, header) {
res.send(header + app.create_route('users/' + req.params.userslug + '/edit', 'accountedit') + templates['footer']);
});
} else {
return res.redirect('/404');
@ -91,13 +114,16 @@ var user = require('./../user.js'),
app.get('/users/:userslug/settings', function(req, res) {
if(!req.user)
if (!req.user)
return res.redirect('/403');
user.getUserField(req.user.uid, 'userslug', function(err, userslug) {
if(req.params.userslug && userslug === req.params.userslug) {
app.build_header({ req: req, res: res }, function(err, header) {
res.send(header + app.create_route('users/'+req.params.userslug+'/settings','accountsettings') + templates['footer']);
if (req.params.userslug && userslug === req.params.userslug) {
app.build_header({
req: req,
res: res
}, function(err, header) {
res.send(header + app.create_route('users/' + req.params.userslug + '/settings', 'accountsettings') + templates['footer']);
})
} else {
return res.redirect('/404');
@ -106,10 +132,10 @@ var user = require('./../user.js'),
});
app.post('/users/uploadpicture', function(req, res) {
if(!req.user)
if (!req.user)
return res.redirect('/403');
if(req.files.userPhoto.size > 262144) {
if (req.files.userPhoto.size > 262144) {
res.send({
error: 'Images must be smaller than 256kb!'
});
@ -118,7 +144,7 @@ var user = require('./../user.js'),
var allowedTypes = ['image/png', 'image/jpeg', 'image/jpg', 'image/gif'];
if(allowedTypes.indexOf(req.files.userPhoto.type) === -1) {
if (allowedTypes.indexOf(req.files.userPhoto.type) === -1) {
res.send({
error: 'Allowed image types are png, jpg and gif!'
});
@ -126,7 +152,7 @@ var user = require('./../user.js'),
}
user.getUserField(req.user.uid, 'uploadedpicture', function(err, oldpicture) {
if(!oldpicture) {
if (!oldpicture) {
uploadUserPicture(req.user.uid, path.extname(req.files.userPhoto.name), req.files.userPhoto.path, res);
return;
}
@ -134,7 +160,7 @@ var user = require('./../user.js'),
var absolutePath = path.join(process.cwd(), global.nconf.get('upload_path'), path.basename(oldpicture));
fs.unlink(absolutePath, function(err) {
if(err) {
if (err) {
winston.err(err);
}
@ -144,7 +170,7 @@ var user = require('./../user.js'),
});
function uploadUserPicture(uid, extension, tempPath, res) {
if(!extension) {
if (!extension) {
res.send({
error: 'Error uploading file! Error : Invalid extension!'
});
@ -154,7 +180,7 @@ var user = require('./../user.js'),
var filename = uid + '-profileimg' + extension;
var uploadPath = path.join(process.cwd(), global.nconf.get('upload_path'), filename);
winston.info('Attempting upload to: '+ uploadPath);
winston.info('Attempting upload to: ' + uploadPath);
var is = fs.createReadStream(tempPath);
var os = fs.createWriteStream(uploadPath);
@ -169,15 +195,17 @@ var user = require('./../user.js'),
require('node-imagemagick').crop({
srcPath: uploadPath,
dstPath: uploadPath,
dstPath: uploadPath,
width: 128,
height: 128
}, function(err, stdout, stderr){
}, function(err, stdout, stderr) {
if (err) {
winston.err(err);
}
res.json({ path: imageUrl });
res.json({
path: imageUrl
});
});
});
@ -191,49 +219,58 @@ var user = require('./../user.js'),
app.get('/users/:userslug/following', function(req, res) {
if(!req.user)
if (!req.user)
return res.redirect('/403');
user.get_uid_by_userslug(req.params.userslug, function(err, uid) {
if(!uid) {
if (!uid) {
res.redirect('/404');
return;
}
app.build_header({ req: req, res: res }, function(err, header) {
res.send(header + app.create_route('users/'+req.params.userslug+'/following','following') + templates['footer']);
app.build_header({
req: req,
res: res
}, function(err, header) {
res.send(header + app.create_route('users/' + req.params.userslug + '/following', 'following') + templates['footer']);
});
});
});
app.get('/users/:userslug/followers', function(req, res) {
if(!req.user)
if (!req.user)
return res.redirect('/403');
user.get_uid_by_userslug(req.params.userslug, function(err, uid) {
if(!uid) {
if (!uid) {
res.redirect('/404');
return;
}
app.build_header({ req: req, res: res }, function(err, header) {
res.send(header + app.create_route('users/'+req.params.userslug+'/followers','followers') + templates['footer']);
app.build_header({
req: req,
res: res
}, function(err, header) {
res.send(header + app.create_route('users/' + req.params.userslug + '/followers', 'followers') + templates['footer']);
});
});
});
app.get('/users/:userslug/favourites', function(req, res) {
if(!req.user)
if (!req.user)
return res.redirect('/403');
user.get_uid_by_userslug(req.params.userslug, function(err, uid) {
if(!uid) {
if (!uid) {
res.redirect('/404');
return;
}
app.build_header({ req: req, res: res }, function(err, header) {
res.send(header + app.create_route('users/'+req.params.userslug+'/favourites','favourites') + templates['footer']);
app.build_header({
req: req,
res: res
}, function(err, header) {
res.send(header + app.create_route('users/' + req.params.userslug + '/favourites', 'favourites') + templates['footer']);
});
});
});
@ -242,7 +279,7 @@ var user = require('./../user.js'),
var callerUID = req.user ? req.user.uid : 0;
getUserDataByUserSlug(req.params.userslug, callerUID, function(userData) {
if(userData) {
if (userData) {
user.getFollowing(userData.uid, function(followingData) {
userData.following = followingData;
userData.followingCount = followingData.length;
@ -250,7 +287,9 @@ var user = require('./../user.js'),
});
} else {
res.json(404, { error: 'User not found!' }) ;
res.json(404, {
error: 'User not found!'
});
}
});
});
@ -259,14 +298,16 @@ var user = require('./../user.js'),
var callerUID = req.user ? req.user.uid : 0;
getUserDataByUserSlug(req.params.userslug, callerUID, function(userData) {
if(userData) {
if (userData) {
user.getFollowers(userData.uid, function(followersData) {
userData.followers = followersData;
userData.followersCount = followersData.length;
res.json(userData);
});
} else {
res.json(404, { error: 'User not found!' }) ;
res.json(404, {
error: 'User not found!'
});
}
});
});
@ -283,27 +324,33 @@ var user = require('./../user.js'),
var callerUID = req.user ? req.user.uid : 0;
user.get_uid_by_userslug(req.params.userslug, function(err, uid) {
if(!uid) {
res.json(404, { error: 'User not found!' }) ;
if (!uid) {
res.json(404, {
error: 'User not found!'
});
return;
}
if(uid !== callerUID || callerUID === "0") {
res.json(403, { error: 'Not allowed!' });
if (uid !== callerUID || callerUID === "0") {
res.json(403, {
error: 'Not allowed!'
});
return;
}
user.getUserFields(uid, ['username','userslug','showemail'], function(err, userData) {
if(err)
user.getUserFields(uid, ['username', 'userslug', 'showemail'], function(err, userData) {
if (err)
return next(err);
if(userData) {
if(userData.showemail && userData.showemail === "1")
if (userData) {
if (userData.showemail && userData.showemail === "1")
userData.showemail = "checked";
else
userData.showemail = "";
res.json(userData);
} else {
res.json(404, { error: 'User not found!' }) ;
res.json(404, {
error: 'User not found!'
});
}
});
});
@ -313,30 +360,36 @@ var user = require('./../user.js'),
var callerUID = req.user ? req.user.uid : 0;
user.get_uid_by_userslug(req.params.userslug, function(err, uid) {
if(!uid) {
res.json(404, { error: 'User not found!' }) ;
if (!uid) {
res.json(404, {
error: 'User not found!'
});
return;
}
if(uid !== callerUID || callerUID === "0") {
res.json(403, { error: 'Not allowed!' });
if (uid !== callerUID || callerUID === "0") {
res.json(403, {
error: 'Not allowed!'
});
return;
}
user.getUserFields(uid, ['username','userslug'], function(err, userData) {
if(err)
user.getUserFields(uid, ['username', 'userslug'], function(err, userData) {
if (err)
return next(err);
if(userData) {
if (userData) {
posts.getFavourites(uid, function(err, posts) {
if(err)
if (err)
return next(err);
userData.posts = posts;
userData.show_nofavourites = posts.length?'hide':'show';
userData.show_nofavourites = posts.length ? 'hide' : 'show';
res.json(userData);
});
} else {
res.json(404, { error: 'User not found!' }) ;
res.json(404, {
error: 'User not found!'
});
}
});
});
@ -346,15 +399,17 @@ var user = require('./../user.js'),
var callerUID = req.user ? req.user.uid : 0;
getUserDataByUserSlug(req.params.userslug, callerUID, function(userData) {
if(userData) {
if (userData) {
user.isFollowing(callerUID, userData.theirid, function(isFollowing) {
posts.getPostsByUid(userData.theirid, 0, 9, function(posts) {
userData.posts = posts.filter(function(p) {return p.deleted !== "1";});
userData.posts = posts.filter(function(p) {
return p.deleted !== "1";
});
userData.isFollowing = isFollowing;
if(!userData.profileviews)
if (!userData.profileviews)
userData.profileviews = 1;
if(callerUID !== userData.uid)
if (callerUID !== userData.uid)
user.incrementUserFieldBy(userData.uid, 'profileviews', 1);
postTools.toHTML(userData.signature, function(err, signature) {
@ -364,7 +419,9 @@ var user = require('./../user.js'),
});
});
} else {
res.json(404, { error: 'User not found!' }) ;
res.json(404, {
error: 'User not found!'
});
}
});
});
@ -378,39 +435,55 @@ var user = require('./../user.js'),
function getUsersSortedByJoinDate(req, res) {
user.getUsers('users:joindate', 0, 49, function(err, data) {
res.json({ search_display: 'none', loadmore_display:'block', users:data });
res.json({
search_display: 'none',
loadmore_display: 'block',
users: data
});
});
}
function getUsersSortedByPosts(req, res) {
user.getUsers('users:postcount', 0, 49, function(err, data) {
res.json({ search_display: 'none', loadmore_display:'block', users:data });
res.json({
search_display: 'none',
loadmore_display: 'block',
users: data
});
});
}
function getUsersSortedByReputation(req, res) {
user.getUsers('users:reputation', 0, 49, function(err, data) {
res.json({ search_display: 'none', loadmore_display:'block', users:data });
res.json({
search_display: 'none',
loadmore_display: 'block',
users: data
});
});
}
function getUsersForSearch(req, res) {
res.json({ search_display: 'block', loadmore_display:'none', users: [] });
res.json({
search_display: 'block',
loadmore_display: 'none',
users: []
});
}
function getUserDataByUserSlug(userslug, callerUID, callback) {
user.get_uid_by_userslug(userslug, function(err, uid) {
if(uid === null) {
if (uid === null) {
callback(null);
return;
}
user.getUserData(uid, function(err, data) {
if(data) {
if (data) {
data.joindate = utils.relativeTime(data.joindate);
if(!data.birthday) {
if (!data.birthday) {
data.age = '';
} else {
data.age = new Date().getFullYear() - new Date(data.birthday).getFullYear();
@ -420,15 +493,15 @@ var user = require('./../user.js'),
return callerUID === uid || (data.email && (data.showemail && data.showemail === "1"));
}
if(!canSeeEmail())
if (!canSeeEmail())
data.email = "";
if(callerUID === uid && (!data.showemail || data.showemail === "0"))
if (callerUID === uid && (!data.showemail || data.showemail === "0"))
data.emailClass = "";
else
data.emailClass = "hide";
data.show_banned = data.banned === '1'?'':'hide';
data.show_banned = data.banned === '1' ? '' : 'hide';
data.uid = uid;
data.yourid = callerUID;
@ -451,4 +524,4 @@ var user = require('./../user.js'),
};
}(exports));
}(exports));
Loading…
Cancel
Save