more cleanup in user routes

v1.18.x
Baris Soner Usakli 12 years ago
parent 6a4dcc75c2
commit a0b4ea70b3

@ -55,13 +55,7 @@ var user = require('./../user.js'),
return;
}
user.getUserData(uid, function(userdata) {
if(userdata) {
res.send(app.build_header(res) + app.create_route('users/'+userdata.userslug, 'account') + templates['footer']);
} else {
res.redirect('/404');
}
});
res.send(app.build_header(res) + app.create_route('users/'+req.params.userslug, 'account') + templates['footer']);
});
});
@ -249,8 +243,11 @@ var user = require('./../user.js'),
function api_method(req, res) {
var callerUID = req.user ? req.user.uid : 0;
var userslug = req.params.userslug;
var section = req.params.section ? String(req.params.section).toLowerCase() : null;
if (!section && !userslug) {
if (!req.params.section && !req.params.userslug) {
user.getUserList(function(data) {
data = data.sort(function(a, b) {
return b.joindate - a.joindate;
@ -258,18 +255,19 @@ var user = require('./../user.js'),
res.json({ search_display: 'none', users: data });
});
}
else if(String(req.params.section).toLowerCase() === 'following') {
else if(section === 'following') {
getFollowing(req, res, callerUID);
}
else if(String(req.params.section).toLowerCase() === 'followers') {
else if(section === 'followers') {
getFollowers(req, res, callerUID);
}
else if (String(req.params.section).toLowerCase() === 'edit') {
getUserDataByUserSlug(req.params.userslug, callerUID, function(userData) {
else if (section === 'edit') {
getUserDataByUserSlug(userslug, callerUID, function(userData) {
res.json(userData);
});
} else {
getUserDataByUserSlug(req.params.userslug, callerUID, function(userData) {
getUserDataByUserSlug(userslug, callerUID, function(userData) {
if(userData) {
user.isFollowing(callerUID, userData.theirid, function(isFollowing) {
posts.getPostsByUid(userData.theirid, 0, 9, function(posts) {
userData.posts = posts;
@ -278,13 +276,15 @@ var user = require('./../user.js'),
res.json(userData);
});
});
} else {
res.json(null);
}
});
}
}
function getFollowing(req, res, callerUid) {
getUserDataByUserSlug(req.params.userslug, callerUID, function(userData) {
getUserDataByUserSlug(req.params.userslug, callerUid, function(userData) {
if(userData) {
user.getFollowing(userData.uid, function(followingData) {
userData.following = followingData;

Loading…
Cancel
Save