Merge remote-tracking branch 'origin/master' into Widgets

v1.18.x
psychobunny 11 years ago
commit 52781bb539

@ -8,6 +8,7 @@
"user.edit": "Editing \"%1\"", "user.edit": "Editing \"%1\"",
"user.following": "People %1 Follows", "user.following": "People %1 Follows",
"user.followers": "People who Follow %1", "user.followers": "People who Follow %1",
"user.posts": "Posts made by %1",
"user.favourites": "%1's Favourite Posts", "user.favourites": "%1's Favourite Posts",
"user.settings": "User Settings" "user.settings": "User Settings"
} }

@ -15,6 +15,9 @@ var socket,
url: RELATIVE_PATH + '/api/config', url: RELATIVE_PATH + '/api/config',
success: function (data) { success: function (data) {
config = data; config = data;
exposeConfigToTemplates();
if(socket) { if(socket) {
socket.disconnect(); socket.disconnect();
setTimeout(function() { setTimeout(function() {
@ -591,12 +594,16 @@ var socket,
}); });
createHeaderTooltips(); createHeaderTooltips();
});
function exposeConfigToTemplates() {
$(document).ready(function() {
templates.setGlobal('relative_path', RELATIVE_PATH); templates.setGlobal('relative_path', RELATIVE_PATH);
templates.setGlobal('usePagination', config.usePagination); for(var key in config) {
templates.setGlobal('topicsPerPage', config.topicsPerPage); templates.setGlobal('config.' + key, config[key]);
templates.setGlobal('postsPerPage', config.postsPerPage); }
}); });
}
function createHeaderTooltips() { function createHeaderTooltips() {
$('#header-menu li i[title]').each(function() { $('#header-menu li i[title]').each(function() {

@ -18,23 +18,23 @@ define(function() {
url: RELATIVE_PATH + '/login', url: RELATIVE_PATH + '/login',
data: loginData, data: loginData,
success: function(data, textStatus, jqXHR) { success: function(data, textStatus, jqXHR) {
if (!data.success) {
$('#login-error-notify').show();
$('#login').removeAttr('disabled').html('Login');
} else {
$('#login').html('Redirecting...'); $('#login').html('Redirecting...');
if(!app.previousUrl) { if(!app.previousUrl) {
app.previousUrl = '/'; app.previousUrl = '/';
} }
if(app.previousUrl.indexOf('/reset/') != -1) if(app.previousUrl.indexOf('/reset/') !== -1) {
window.location.replace(RELATIVE_PATH + "/?loggedin"); window.location.replace(RELATIVE_PATH + "/?loggedin");
else } else {
var index = app.previousUrl.indexOf('#');
if(index !== -1) {
window.location.replace(app.previousUrl.slice(0, index) + '?loggedin' + app.previousUrl.slice(index));
} else {
window.location.replace(app.previousUrl + "?loggedin"); window.location.replace(app.previousUrl + "?loggedin");
}
}
app.loadConfig(); app.loadConfig();
}
}, },
error: function(data, textStatus, jqXHR) { error: function(data, textStatus, jqXHR) {
$('#login-error-notify').show(); $('#login-error-notify').show();

@ -10,12 +10,12 @@
<div class="col-lg-8"> <div class="col-lg-8">
<h2>{groups.name}</h2> <h2>{groups.name}</h2>
<p>{groups.description}</p> <p>{groups.description}</p>
<!-- IF groups.deletable -->
<div class="btn-group"> <div class="btn-group">
<button class="btn btn-default" data-action="members">Members</button> <button class="btn btn-default" data-action="members">Members</button>
<!-- IF groups.deletable -->
<button class="btn btn-danger" data-action="delete">Delete Group</button> <button class="btn btn-danger" data-action="delete">Delete Group</button>
<!-- ENDIF groups.deletable -->
</div> </div>
<!-- ENDIF groups.deletable -->
</div> </div>
<div class="col-lg-4"> <div class="col-lg-4">
<ul class="pull-right members"> <ul class="pull-right members">

@ -12,15 +12,7 @@
</div> </div>
</div> </div>
</div> </div>
<div class="col-sm-6"> <div class="col-sm-6 pull-right">
<div class="panel panel-default">
<div class="panel-heading">Active Users <small><span class="badge" id="connections"></span> socket connections</small></div>
<div class="panel-body">
<div id="active_users"></div>
</div>
</div>
</div>
<div class="col-sm-6">
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-heading">Updates</div> <div class="panel-heading">Updates</div>
<div class="panel-body"> <div class="panel-body">
@ -33,4 +25,12 @@
</div> </div>
</div> </div>
</div> </div>
<div class="col-sm-6">
<div class="panel panel-default">
<div class="panel-heading">Active Users <small><span class="badge" id="connections"></span> socket connections</small></div>
<div class="panel-body">
<div id="active_users"></div>
</div>
</div>
</div>
</div> </div>

@ -86,14 +86,14 @@
</li> </li>
<!-- END topics --> <!-- END topics -->
</ul> </ul>
<!-- IF usePagination --> <!-- IF config.usePagination -->
<div class="text-center"> <div class="text-center">
<ul class="pagination"> <ul class="pagination">
<li class="previous pull-left"><a href="#"><i class="fa fa-chevron-left"></i> [[global:previouspage]]</a></li> <li class="previous pull-left"><a href="#"><i class="fa fa-chevron-left"></i> [[global:previouspage]]</a></li>
<li class="next pull-right"><a href="#">[[global:nextpage]] <i class="fa fa-chevron-right"></i></a></li> <li class="next pull-right"><a href="#">[[global:nextpage]] <i class="fa fa-chevron-right"></i></a></li>
</ul> </ul>
</div> </div>
<!-- ENDIF usePagination --> <!-- ENDIF config.usePagination -->
</div> </div>
<!-- IF topics.length --> <!-- IF topics.length -->

@ -14,6 +14,10 @@
<!-- BEGIN pluginCSS --> <!-- BEGIN pluginCSS -->
<link rel="stylesheet" href="{pluginCSS.path}?{cache-buster}"> <link rel="stylesheet" href="{pluginCSS.path}?{cache-buster}">
<!-- END pluginCSS --> <!-- END pluginCSS -->
<!-- IF useCustomCSS -->
<style type="text/css">{customCSS}</style>
<!-- ENDIF useCustomCSS -->
<script> <script>
var RELATIVE_PATH = "{relative_path}"; var RELATIVE_PATH = "{relative_path}";
</script> </script>
@ -31,12 +35,6 @@
} }
}); });
</script> </script>
<!-- TODO : this has to be refactored, maybe configured from ACP? -baris -->
<link rel="stylesheet" type="text/css" href="//code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
<!-- IF useCustomCSS -->
<style type="text/css">{customCSS}</style>
<!-- ENDIF useCustomCSS -->
</head> </head>
<body> <body>

@ -214,14 +214,14 @@
<div style="clear:both;"></div> <div style="clear:both;"></div>
</div> </div>
<!-- IF usePagination --> <!-- IF config.usePagination -->
<div class="text-center"> <div class="text-center">
<ul class="pagination"> <ul class="pagination">
<li class="previous pull-left"><a href="#"><i class="fa fa-chevron-left"></i> [[global:previouspage]]</a></li> <li class="previous pull-left"><a href="#"><i class="fa fa-chevron-left"></i> [[global:previouspage]]</a></li>
<li class="next pull-right"><a href="#">[[global:nextpage]] <i class="fa fa-chevron-right"></i></a></li> <li class="next pull-right"><a href="#">[[global:nextpage]] <i class="fa fa-chevron-right"></i></a></li>
</ul> </ul>
</div> </div>
<!-- ENDIF usePagination --> <!-- ENDIF config.usePagination -->
<div id="move_thread_modal" class="modal" tabindex="-1" role="dialog" aria-labelledby="Move Topic" aria-hidden="true"> <div id="move_thread_modal" class="modal" tabindex="-1" role="dialog" aria-labelledby="Move Topic" aria-hidden="true">
<div class="modal-dialog"> <div class="modal-dialog">

@ -70,7 +70,7 @@
results.base.count = results.users.length; results.base.count = results.users.length;
results.base.members = results.users; results.base.members = results.users;
results.base.deletable = parseInt(results.base.gid, 10) !== 1; results.base.deletable = results.base.hidden !== '1';
callback(err, results.base); callback(err, results.base);
}); });

@ -171,8 +171,6 @@ var fs = require('fs'),
var user = require('./user'); var user = require('./user');
Meta.title.parseFragment(decodeURIComponent(urlFragment), function(err, title) { Meta.title.parseFragment(decodeURIComponent(urlFragment), function(err, title) {
var title;
if (err) { if (err) {
title = Meta.config.browserTitle || 'NodeBB'; title = Meta.config.browserTitle || 'NodeBB';
} else { } else {

@ -448,9 +448,20 @@ var nconf = require('nconf'),
}); });
app.get('/groups', function (req, res) { app.get('/groups', function (req, res) {
async.parallel([
function(next) {
groups.list({ groups.list({
expand: true expand: true
}, function (err, groups) { }, next);
},
function(next) {
groups.listSystemGroups({
expand: true
}, next);
}
], function(err, data) {
var groups = data[0].concat(data[1]);
res.json(200, { res.json(200, {
groups: groups, groups: groups,
yourid: req.user.uid yourid: req.user.uid

@ -13,16 +13,6 @@
login_strategies = []; login_strategies = [];
passport.use(new passportLocal(function(user, password, next) {
Auth.login(user, password, function(err, login) {
if (!err) {
next(null, login.user);
} else {
next(null, false, err);
}
});
}));
plugins.ready(function() { plugins.ready(function() {
plugins.fireHook('filter:auth.init', login_strategies, function(err) { plugins.fireHook('filter:auth.init', login_strategies, function(err) {
if (err) { if (err) {
@ -33,16 +23,6 @@
}); });
}); });
passport.serializeUser(function(user, done) {
done(null, user.uid);
});
passport.deserializeUser(function(uid, done) {
done(null, {
uid: uid
});
});
Auth.initialize = function(app) { Auth.initialize = function(app) {
app.use(passport.initialize()); app.use(passport.initialize());
app.use(passport.session()); app.use(passport.session());
@ -107,11 +87,9 @@
if (err) { if (err) {
return next(err); return next(err);
} }
if (!user) { if (!user) {
return res.send({ return res.json(403, info);
success: false,
message: info.message
});
} }
// Alter user cookie depending on passed-in option // Alter user cookie depending on passed-in option
@ -127,10 +105,7 @@
req.login({ req.login({
uid: user.uid uid: user.uid
}, function() { }, function() {
res.send({ res.json(info);
success: true,
message: 'authentication succeeded'
});
}); });
})(req, res, next); })(req, res, next);
}); });
@ -163,50 +138,60 @@
Auth.login = function(username, password, next) { Auth.login = function(username, password, next) {
if (!username || !password) { if (!username || !password) {
return next({ return next(new Error('invalid-user'));
status: 'error', }
message: 'invalid-user'
});
} else {
var userslug = utils.slugify(username); var userslug = utils.slugify(username);
user.getUidByUserslug(userslug, function(err, uid) { user.getUidByUserslug(userslug, function(err, uid) {
if (err) { if (err) {
return next(new Error('redis-error')); return next(err);
} else if (uid == null) { }
return next(new Error('invalid-user'));
if(!uid) {
return next(null, false, 'user doesn\'t exist');
} }
user.getUserFields(uid, ['password', 'banned'], function(err, userData) { user.getUserFields(uid, ['password', 'banned'], function(err, userData) {
if (err) return next(err); if (err) {
return next(err);
}
if (!userData || !userData.password) {
return next(new Error('invalid userdata or password'));
}
if (userData.banned && parseInt(userData.banned, 10) === 1) { if (userData.banned && parseInt(userData.banned, 10) === 1) {
return next({ return next(null, false, 'User banned');
status: "error",
message: "user-banned"
});
} }
bcrypt.compare(password, userData.password, function(err, res) { bcrypt.compare(password, userData.password, function(err, res) {
if (err) { if (err) {
winston.err(err.message); winston.err(err.message);
next(new Error('bcrypt compare error')); return next(new Error('bcrypt compare error'));
return; }
if (!res) {
next(null, false, 'invalid-password');
} }
if (res) {
next(null, { next(null, {
user: {
uid: uid uid: uid
} }, 'Authentication successful');
});
});
}); });
} else {
next(new Error('invalid-password'));
} }
passport.use(new passportLocal(Auth.login));
passport.serializeUser(function(user, done) {
done(null, user.uid);
}); });
passport.deserializeUser(function(uid, done) {
done(null, {
uid: uid
}); });
}); });
}
}
}(exports)); }(exports));

@ -45,13 +45,12 @@ var fs = require('fs'),
app.namespace('/user', function () { app.namespace('/user', function () {
function createRoute(routeName, path, templateName) { function createRoute(routeName, path, templateName, access) {
app.get(routeName, function(req, res, next) {
if (!req.params.userslug) {
return next();
}
if (!req.user && (path === '/favourites' || !!parseInt(meta.config.privateUserInfo, 10))) { function isAllowed(req, res, next) {
var callerUID = req.user ? parseInt(req.user.uid, 10) : 0;
if (!callerUID && !!parseInt(meta.config.privateUserInfo, 10)) {
return res.redirect('/403'); return res.redirect('/403');
} }
@ -64,50 +63,12 @@ var fs = require('fs'),
return res.redirect('/404'); return res.redirect('/404');
} }
app.build_header({ if (parseInt(uid, 10) === callerUID) {
req: req, return next();
res: res
}, function (err, header) {
if(err) {
return next(err);
}
res.send(header + app.create_route('user/' + req.params.userslug + path, templateName) + templates['footer']);
});
});
})
}
createRoute('/:userslug', '', 'account');
createRoute('/:userslug/following', '/following', 'following');
createRoute('/:userslug/followers', '/followers', 'followers');
createRoute('/:userslug/favourites', '/favourites', 'favourites');
createRoute('/:userslug/posts', '/posts', 'accountposts');
app.get('/:userslug/edit', function (req, res, next) {
if (!req.user) {
return res.redirect('/403');
}
user.getUserField(req.user.uid, 'userslug', function (err, userslug) {
function done() {
app.build_header({
req: req,
res: res
}, function (err, header) {
res.send(header + app.create_route('user/' + req.params.userslug + '/edit', 'accountedit') + templates['footer']);
});
}
if(err || !userslug) {
return next(err);
}
if (userslug === req.params.userslug) {
return done();
} }
user.isAdministrator(req.user.uid, function(err, isAdmin) { if (req.path.indexOf('/edit') !== -1) {
user.isAdministrator(callerUID, function(err, isAdmin) {
if(err) { if(err) {
return next(err); return next(err);
} }
@ -116,32 +77,36 @@ var fs = require('fs'),
return res.redirect('/403'); return res.redirect('/403');
} }
done(); next();
});
}); });
} else if (req.path.indexOf('/settings') !== -1 || req.path.indexOf('/favourites') !== -1) {
res.redirect('/403')
} else {
next();
}
}); });
app.get('/:userslug/settings', function (req, res) {
if (!req.user) {
return res.redirect('/403');
} }
user.getUserField(req.user.uid, 'userslug', function (err, userslug) { app.get(routeName, isAllowed, function(req, res, next) {
if (req.params.userslug && userslug === req.params.userslug) {
app.build_header({ app.build_header({
req: req, req: req,
res: res res: res
}, function (err, header) { }, function (err, header) {
res.send(header + app.create_route('user/' + req.params.userslug + '/settings', 'accountsettings') + templates['footer']); if(err) {
}) return next(err);
} else {
return res.redirect('/404');
} }
res.send(header + app.create_route('user/' + req.params.userslug + path, templateName) + templates['footer']);
}); });
}); });
}
createRoute('/:userslug', '', 'account');
createRoute('/:userslug/following', '/following', 'following');
createRoute('/:userslug/followers', '/followers', 'followers');
createRoute('/:userslug/favourites', '/favourites', 'favourites');
createRoute('/:userslug/posts', '/posts', 'accountposts');
createRoute('/:userslug/edit', '/edit', 'accountedit');
createRoute('/:userslug/settings', '/settings', 'accountsettings');
app.post('/uploadpicture', function (req, res) { app.post('/uploadpicture', function (req, res) {
if (!req.user) { if (!req.user) {
@ -257,99 +222,85 @@ var fs = require('fs'),
next(); next();
} }
app.get('/api/user/:userslug/following', isAllowed, function (req, res, next) { app.get('/api/user/:userslug/following', isAllowed, getUserFollowing);
var callerUID = req.user ? req.user.uid : '0'; app.get('/api/user/:userslug/followers', isAllowed, getUserFollowers);
app.get('/api/user/:userslug/edit', isAllowed, getUserEdit);
app.get('/api/user/:userslug/settings', isAllowed, getUserSettings);
app.get('/api/user/:userslug/favourites', isAllowed, getUserFavourites);
app.get('/api/user/:userslug/posts', isAllowed, getUserPosts);
app.get('/api/user/uid/:uid', isAllowed, getUserData);
app.get('/api/user/:userslug', isAllowed, getUserProfile);
app.get('/api/users', isAllowed, getOnlineUsers);
app.get('/api/users/sort-posts', isAllowed, getUsersSortedByPosts);
app.get('/api/users/sort-reputation', isAllowed, getUsersSortedByReputation);
app.get('/api/users/latest', isAllowed, getUsersSortedByJoinDate);
app.get('/api/users/online', isAllowed, getOnlineUsers);
app.get('/api/users/search', isAllowed, getUsersForSearch);
function getUserProfile(req, res, next) {
var callerUID = req.user ? parseInt(req.user.uid, 10) : 0;
getUserDataByUserSlug(req.params.userslug, callerUID, function (err, userData) { getUserDataByUserSlug(req.params.userslug, callerUID, function (err, userData) {
if(err) { if(err) {
return next(err); return next(err);
} }
if (userData) { if(!userData) {
user.getFollowing(userData.uid, function (err, followingData) { return res.json(404, {
if(err) {
return next(err);
}
userData.following = followingData;
userData.followingCount = followingData.length;
res.json(userData);
});
} else {
res.json(404, {
error: 'User not found!' error: 'User not found!'
}); });
} }
});
});
app.get('/api/user/:userslug/followers', isAllowed, function (req, res, next) { user.isFollowing(callerUID, userData.theirid, function (isFollowing) {
var callerUID = req.user ? req.user.uid : '0';
getUserDataByUserSlug(req.params.userslug, callerUID, function (err, userData) { posts.getPostsByUid(callerUID, userData.theirid, 0, 9, function (err, userPosts) {
if(err) {
return next(err);
}
if (userData) {
user.getFollowers(userData.uid, function (err, followersData) {
if(err) { if(err) {
return next(err); return next(err);
} }
userData.followers = followersData;
userData.followersCount = followersData.length; userData.posts = userPosts.posts.filter(function (p) {
res.json(userData); return p && parseInt(p.deleted, 10) !== 1;
});
} else {
res.json(404, {
error: 'User not found!'
});
}
});
}); });
app.get('/api/user/:userslug/edit', function (req, res, next) { userData.isFollowing = isFollowing;
var callerUID = req.user ? req.user.uid : '0';
if(!parseInt(callerUID, 10)) { if (!userData.profileviews) {
return res.json(403, { userData.profileviews = 1;
error: 'Not allowed!'
});
} }
getUserDataByUserSlug(req.params.userslug, callerUID, function (err, userData) { if (callerUID !== parseInt(userData.uid, 10) && callerUID) {
if(err) { user.incrementUserFieldBy(userData.uid, 'profileviews', 1);
return next(err);
} }
postTools.parse(userData.signature, function (err, signature) {
userData.signature = signature;
res.json(userData); res.json(userData);
}); });
}); });
});
});
}
app.get('/api/user/:userslug/settings', function(req, res, next) { function getUserData(req, res, next) {
var callerUID = req.user ? req.user.uid : '0'; var uid = req.params.uid ? req.params.uid : 0;
user.getUidByUserslug(req.params.userslug, function(err, uid) { user.getUserData(uid, function(err, userData) {
if (err) { res.json(userData);
return next(err); });
} }
function getUserPosts(req, res, next) {
var callerUID = req.user ? parseInt(req.user.uid, 10) : 0;
user.getUidByUserslug(req.params.userslug, function (err, uid) {
if (!uid) { if (!uid) {
return res.json(404, { return res.json(404, {
error: 'User not found!' error: 'User not found!'
}); });
} }
if (uid != callerUID || callerUID == '0') {
return res.json(403, {
error: 'Not allowed!'
});
}
plugins.fireHook('filter:user.settings', [], function(err, settings) {
if (err) {
return next(err);
}
user.getUserFields(uid, ['username', 'userslug'], function (err, userData) { user.getUserFields(uid, ['username', 'userslug'], function (err, userData) {
if (err) { if (err) {
return next(err); return next(err);
@ -360,18 +311,25 @@ var fs = require('fs'),
error: 'User not found!' error: 'User not found!'
}); });
} }
userData.yourid = req.user.uid;
posts.getPostsByUid(callerUID, uid, 0, 19, function (err, userPosts) {
if (err) {
return next(err);
}
userData.uid = uid;
userData.theirid = uid; userData.theirid = uid;
userData.settings = settings; userData.yourid = callerUID;
userData.posts = userPosts.posts;
userData.nextStart = userPosts.nextStart;
res.json(userData); res.json(userData);
}); });
}); });
});
}); });
}
app.get('/api/user/:userslug/favourites', isAllowed, function (req, res, next) { function getUserFavourites(req, res, next) {
var callerUID = req.user ? req.user.uid : '0'; var callerUID = req.user ? parseInt(req.user.uid, 10) : 0;
user.getUidByUserslug(req.params.userslug, function (err, uid) { user.getUidByUserslug(req.params.userslug, function (err, uid) {
if (!uid) { if (!uid) {
@ -380,7 +338,7 @@ var fs = require('fs'),
}); });
} }
if (uid != callerUID || callerUID == '0') { if (parseInt(uid, 10) !== callerUID) {
return res.json(403, { return res.json(403, {
error: 'Not allowed!' error: 'Not allowed!'
}); });
@ -411,18 +369,33 @@ var fs = require('fs'),
}); });
}); });
}); });
}); }
app.get('/api/user/:userslug/posts', isAllowed, function (req, res, next) { function getUserSettings(req, res, next) {
var callerUID = req.user ? req.user.uid : '0'; var callerUID = req.user ? parseInt(req.user.uid, 10) : 0;
user.getUidByUserslug(req.params.userslug, function(err, uid) { user.getUidByUserslug(req.params.userslug, function(err, uid) {
if (err) {
return next(err);
}
if (!uid) { if (!uid) {
return res.json(404, { return res.json(404, {
error: 'User not found!' error: 'User not found!'
}); });
} }
if (parseInt(uid, 10) !== callerUID) {
return res.json(403, {
error: 'Not allowed!'
});
}
plugins.fireHook('filter:user.settings', [], function(err, settings) {
if (err) {
return next(err);
}
user.getUserFields(uid, ['username', 'userslug'], function(err, userData) { user.getUserFields(uid, ['username', 'userslug'], function(err, userData) {
if (err) { if (err) {
return next(err); return next(err);
@ -433,85 +406,77 @@ var fs = require('fs'),
error: 'User not found!' error: 'User not found!'
}); });
} }
userData.yourid = req.user.uid;
posts.getPostsByUid(callerUID, uid, 0, 19, function (err, userPosts) {
if (err) {
return next(err);
}
userData.uid = uid;
userData.theirid = uid; userData.theirid = uid;
userData.yourid = callerUID; userData.settings = settings;
userData.posts = userPosts.posts;
userData.nextStart = userPosts.nextStart;
res.json(userData); res.json(userData);
}); });
}); });
});
});
app.get('/api/user/uid/:uid', isAllowed, function(req, res, next) {
var uid = req.params.uid ? req.params.uid : 0;
user.getUserData(uid, function(err, userData) {
res.json(userData);
});
}); });
}
app.get('/api/user/:userslug', isAllowed, function (req, res, next) { function getUserEdit(req, res, next) {
var callerUID = req.user ? req.user.uid : '0'; var callerUID = req.user ? parseInt(req.user.uid, 10) : 0;
getUserDataByUserSlug(req.params.userslug, callerUID, function (err, userData) { getUserDataByUserSlug(req.params.userslug, callerUID, function (err, userData) {
if(err) { if(err) {
return next(err); return next(err);
} }
res.json(userData);
if(!userData) {
return res.json(404, {
error: 'User not found!'
}); });
} }
user.isFollowing(callerUID, userData.theirid, function (isFollowing) { function getUserFollowers(req, res, next) {
var callerUID = req.user ? parseInt(req.user.uid, 10) : 0;
posts.getPostsByUid(callerUID, userData.theirid, 0, 9, function (err, userPosts) {
getUserDataByUserSlug(req.params.userslug, callerUID, function (err, userData) {
if(err) { if(err) {
return next(err); return next(err);
} }
userData.posts = userPosts.posts.filter(function (p) { if (userData) {
return p && parseInt(p.deleted, 10) !== 1; user.getFollowers(userData.uid, function (err, followersData) {
if(err) {
return next(err);
}
userData.followers = followersData;
userData.followersCount = followersData.length;
res.json(userData);
});
} else {
res.json(404, {
error: 'User not found!'
}); });
}
});
}
userData.isFollowing = isFollowing; function getUserFollowing(req, res, next) {
var callerUID = req.user ? parseInt(req.user.uid, 10) : 0;
if (!userData.profileviews) { getUserDataByUserSlug(req.params.userslug, callerUID, function (err, userData) {
userData.profileviews = 1; if(err) {
return next(err);
} }
if (parseInt(callerUID, 10) !== parseInt(userData.uid, 10) && parseInt(callerUID, 0)) { if (userData) {
user.incrementUserFieldBy(userData.uid, 'profileviews', 1); user.getFollowing(userData.uid, function (err, followingData) {
if(err) {
return next(err);
} }
userData.following = followingData;
postTools.parse(userData.signature, function (err, signature) { userData.followingCount = followingData.length;
userData.signature = signature;
res.json(userData); res.json(userData);
}); });
});
});
} else {
res.json(404, {
error: 'User not found!'
}); });
}
}); });
}
app.get('/api/users', isAllowed, getOnlineUsers);
app.get('/api/users/sort-posts', isAllowed, getUsersSortedByPosts);
app.get('/api/users/sort-reputation', isAllowed, getUsersSortedByReputation);
app.get('/api/users/latest', isAllowed, getUsersSortedByJoinDate);
app.get('/api/users/online', isAllowed, getOnlineUsers);
app.get('/api/users/search', isAllowed, getUsersForSearch);
function getUsersSortedByJoinDate(req, res) { function getUsersSortedByJoinDate(req, res) {
user.getUsers('users:joindate', 0, 49, function (err, data) { user.getUsers('users:joindate', 0, 49, function (err, data) {
@ -607,32 +572,34 @@ var fs = require('fs'),
} }
function getUserDataByUserSlug(userslug, callerUID, callback) { function getUserDataByUserSlug(userslug, callerUID, callback) {
var userData;
async.waterfall([ user.getUidByUserslug(userslug, function(err, uid) {
function(next) { if(err || !uid) {
user.getUidByUserslug(userslug, next); return callback(err || new Error('invalid-user'));
},
function(uid, next) {
if (!uid) {
return next(new Error('invalid-user'));
} }
async.parallel({
userData : function(next) {
user.getUserData(uid, next); user.getUserData(uid, next);
}, },
function(data, next) { userSettings : function(next) {
userData = data; user.getSettings(uid, next);
if (!userData) { },
return callback(new Error('invalid-user')); isAdmin : function(next) {
}
user.isAdministrator(callerUID, next); user.isAdministrator(callerUID, next);
},
followStats: function(next) {
user.getFollowStats(uid, next);
} }
], function(err, isAdmin) { }, function(err, results) {
if(err) { if(err || !results.userData) {
return callback(err); return callback(err || new Error('invalid-user'));
} }
var userData = results.userData;
var userSettings = results.userSettings;
var isAdmin = results.isAdmin;
userData.joindate = utils.toISOString(userData.joindate); userData.joindate = utils.toISOString(userData.joindate);
if(userData.lastonline) { if(userData.lastonline) {
userData.lastonline = utils.toISOString(userData.lastonline); userData.lastonline = utils.toISOString(userData.lastonline);
@ -647,14 +614,14 @@ var fs = require('fs'),
} }
function canSeeEmail() { function canSeeEmail() {
return isAdmin || callerUID == userData.uid || (userData.email && (userData.showemail && parseInt(userData.showemail, 10) === 1)); return isAdmin || parseInt(callerUID, 10) === parseInt(userData.uid, 10) || (userData.email && userSettings.showemail);
} }
if (!canSeeEmail()) { if (!canSeeEmail()) {
userData.email = ""; userData.email = "";
} }
if (callerUID == userData.uid && (!userData.showemail || parseInt(userData.showemail, 10) === 0)) { if (parseInt(callerUID, 10) === parseInt(userData.uid, 10) && !userSettings.showemail) {
userData.emailClass = ""; userData.emailClass = "";
} else { } else {
userData.emailClass = "hide"; userData.emailClass = "hide";
@ -668,17 +635,13 @@ var fs = require('fs'),
userData.disableSignatures = meta.config.disableSignatures !== undefined && parseInt(meta.config.disableSignatures, 10) === 1; userData.disableSignatures = meta.config.disableSignatures !== undefined && parseInt(meta.config.disableSignatures, 10) === 1;
user.getFollowStats(userData.uid, function (err, followStats) { userData.followingCount = results.followStats.followingCount;
if(err) { userData.followerCount = results.followStats.followerCount;
return callback(err);
}
userData.followingCount = followStats.followingCount;
userData.followerCount = followStats.followerCount;
callback(null, userData); callback(null, userData);
}); });
}); });
} }
}; };
}(exports)); }(exports));

@ -104,12 +104,14 @@ var bcrypt = require('bcryptjs'),
'postcount': 0, 'postcount': 0,
'lastposttime': 0, 'lastposttime': 0,
'banned': 0, 'banned': 0,
'status': 'online', 'status': 'online'
'showemail': 0
}; };
db.setObject('user:' + uid, userData); db.setObject('user:' + uid, userData, function(err) {
if(err) {
return callback(err);
}
db.setObjectField('username:uid', userData.username, uid); db.setObjectField('username:uid', userData.username, uid);
db.setObjectField('userslug:uid', userData.userslug, uid); db.setObjectField('userslug:uid', userData.userslug, uid);
@ -143,6 +145,7 @@ var bcrypt = require('bcryptjs'),
} }
}); });
}); });
});
}; };
User.ban = function(uid, callback) { User.ban = function(uid, callback) {
@ -209,7 +212,7 @@ var bcrypt = require('bcryptjs'),
settings = {} settings = {}
} }
settings.showemail = settings.showemail ? parseInt(settings.showemail, 10) !== 0 : parseInt(meta.config.usePagination, 10) !== 0; settings.showemail = settings.showemail ? parseInt(settings.showemail, 10) !== 0 : false;
settings.usePagination = settings.usePagination ? parseInt(settings.usePagination, 10) !== 0 : parseInt(meta.config.usePagination, 10) !== 0; settings.usePagination = settings.usePagination ? parseInt(settings.usePagination, 10) !== 0 : parseInt(meta.config.usePagination, 10) !== 0;
settings.topicsPerPage = settings.topicsPerPage ? parseInt(settings.topicsPerPage, 10) : parseInt(meta.config.topicsPerPage, 10) || 20; settings.topicsPerPage = settings.topicsPerPage ? parseInt(settings.topicsPerPage, 10) : parseInt(meta.config.topicsPerPage, 10) || 20;
settings.postsPerPage = settings.postsPerPage ? parseInt(settings.postsPerPage, 10) : parseInt(meta.config.postsPerPage, 10) || 10; settings.postsPerPage = settings.postsPerPage ? parseInt(settings.postsPerPage, 10) : parseInt(meta.config.postsPerPage, 10) || 10;

@ -88,10 +88,10 @@ module.exports.server = server;
property: 'keywords', property: 'keywords',
content: meta.config.keywords || '' content: meta.config.keywords || ''
}], }],
defaultLinkTags = [/*{ defaultLinkTags = [{
rel: 'apple-touch-icon', rel: 'apple-touch-icon',
href: meta.config['brand:logo'] || nconf.get('relative_path') + '/logo.png' href: '/apple-touch-icon'
}*/], }],
templateValues = { templateValues = {
bootswatchCSS: meta.config['theme:src'], bootswatchCSS: meta.config['theme:src'],
pluginCSS: plugins.cssFiles.map(function(file) { return { path: nconf.get('relative_path') + file.replace(/\\/g, '/') }; }), pluginCSS: plugins.cssFiles.map(function(file) { return { path: nconf.get('relative_path') + file.replace(/\\/g, '/') }; }),
@ -203,7 +203,17 @@ module.exports.server = server;
logger.init(app); logger.init(app);
// favicon & apple-touch-icon middleware
app.use(express.favicon(path.join(__dirname, '../', 'public', meta.config['brand:favicon'] ? meta.config['brand:favicon'] : 'favicon.ico'))); app.use(express.favicon(path.join(__dirname, '../', 'public', meta.config['brand:favicon'] ? meta.config['brand:favicon'] : 'favicon.ico')));
app.use('/apple-touch-icon', function(req, res) {
if (meta.config['brand:logo'] && validator.isURL(meta.config['brand:logo'])) {
return res.redirect(meta.config['brand:logo']);
} else {
return res.sendfile(path.join(__dirname, '../public', meta.config['brand:logo'] || nconf.get('relative_path') + '/logo.png'), {
maxAge: app.enabled('cache') ? 5184000000 : 0
});
}
});
app.use(require('less-middleware')({ app.use(require('less-middleware')({
src: path.join(__dirname, '../', 'public'), src: path.join(__dirname, '../', 'public'),

Loading…
Cancel
Save