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,13 +594,17 @@ var socket,
}); });
createHeaderTooltips(); createHeaderTooltips();
templates.setGlobal('relative_path', RELATIVE_PATH);
templates.setGlobal('usePagination', config.usePagination);
templates.setGlobal('topicsPerPage', config.topicsPerPage);
templates.setGlobal('postsPerPage', config.postsPerPage);
}); });
function exposeConfigToTemplates() {
$(document).ready(function() {
templates.setGlobal('relative_path', RELATIVE_PATH);
for(var key in config) {
templates.setGlobal('config.' + key, config[key]);
}
});
}
function createHeaderTooltips() { function createHeaderTooltips() {
$('#header-menu li i[title]').each(function() { $('#header-menu li i[title]').each(function() {
$(this).parents('a').tooltip({ $(this).parents('a').tooltip({

@ -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) {
$('#login').html('Redirecting...');
if(!app.previousUrl) {
app.previousUrl = '/';
}
if (!data.success) { if(app.previousUrl.indexOf('/reset/') !== -1) {
$('#login-error-notify').show(); window.location.replace(RELATIVE_PATH + "/?loggedin");
$('#login').removeAttr('disabled').html('Login');
} else { } else {
$('#login').html('Redirecting...'); var index = app.previousUrl.indexOf('#');
if(!app.previousUrl) { if(index !== -1) {
app.previousUrl = '/'; window.location.replace(app.previousUrl.slice(0, index) + '?loggedin' + app.previousUrl.slice(index));
} } else {
if(app.previousUrl.indexOf('/reset/') != -1)
window.location.replace(RELATIVE_PATH + "/?loggedin");
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) {
groups.list({ async.parallel([
expand: true function(next) {
}, function (err, groups) { groups.list({
expand: true
}, 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'
}); var userslug = utils.slugify(username);
} else {
user.getUidByUserslug(userslug, function(err, uid) {
if (err) {
return next(err);
}
var userslug = utils.slugify(username); if(!uid) {
return next(null, false, 'user doesn\'t exist');
}
user.getUidByUserslug(userslug, function(err, uid) { user.getUserFields(uid, ['password', 'banned'], function(err, userData) {
if (err) { if (err) {
return next(new Error('redis-error')); return next(err);
} else if (uid == null) {
return next(new Error('invalid-user'));
} }
user.getUserFields(uid, ['password', 'banned'], function(err, userData) { if (!userData || !userData.password) {
if (err) return next(err); 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) {
if (err) {
winston.err(err.message);
return next(new Error('bcrypt compare error'));
} }
bcrypt.compare(password, userData.password, function(err, res) { if (!res) {
if (err) { next(null, false, 'invalid-password');
winston.err(err.message); }
next(new Error('bcrypt compare error'));
return; next(null, {
} uid: uid
}, 'Authentication successful');
if (res) {
next(null, {
user: {
uid: uid
}
});
} 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,18 +45,17 @@ 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) { function isAllowed(req, res, next) {
return next(); var callerUID = req.user ? parseInt(req.user.uid, 10) : 0;
}
if (!req.user && (path === '/favourites' || !!parseInt(meta.config.privateUserInfo, 10))) { if (!callerUID && !!parseInt(meta.config.privateUserInfo, 10)) {
return res.redirect('/403'); return res.redirect('/403');
} }
user.getUidByUserslug(req.params.userslug, function (err, uid) { user.getUidByUserslug(req.params.userslug, function (err, uid) {
if(err) { if (err) {
return next(err); return next(err);
} }
@ -64,84 +63,50 @@ 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'); if (req.path.indexOf('/edit') !== -1) {
createRoute('/:userslug/following', '/following', 'following'); user.isAdministrator(callerUID, function(err, isAdmin) {
createRoute('/:userslug/followers', '/followers', 'followers'); if(err) {
createRoute('/:userslug/favourites', '/favourites', 'favourites'); return next(err);
createRoute('/:userslug/posts', '/posts', 'accountposts'); }
app.get('/:userslug/edit', function (req, res, next) { if(!isAdmin) {
return res.redirect('/403');
}
if (!req.user) { next();
return res.redirect('/403'); });
} else if (req.path.indexOf('/settings') !== -1 || req.path.indexOf('/favourites') !== -1) {
res.redirect('/403')
} else {
next();
}
});
} }
user.getUserField(req.user.uid, 'userslug', function (err, userslug) { app.get(routeName, isAllowed, function(req, res, next) {
function done() { 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 + '/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(err) { if(err) {
return next(err); return next(err);
} }
res.send(header + app.create_route('user/' + req.params.userslug + path, templateName) + templates['footer']);
if(!isAdmin) {
return res.redirect('/403');
}
done();
}); });
}); });
}); }
app.get('/:userslug/settings', function (req, res) {
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('user/' + req.params.userslug + '/settings', 'accountsettings') + templates['footer']);
})
} else {
return res.redirect('/404');
}
});
});
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,121 +222,114 @@ 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;
res.json(userData);
});
} else {
res.json(404, {
error: 'User not found!'
});
}
});
});
app.get('/api/user/:userslug/edit', function (req, res, next) { userData.posts = userPosts.posts.filter(function (p) {
var callerUID = req.user ? req.user.uid : '0'; return p && parseInt(p.deleted, 10) !== 1;
});
userData.isFollowing = isFollowing;
if(!parseInt(callerUID, 10)) { if (!userData.profileviews) {
return res.json(403, { userData.profileviews = 1;
error: 'Not allowed!' }
if (callerUID !== parseInt(userData.uid, 10) && callerUID) {
user.incrementUserFieldBy(userData.uid, 'profileviews', 1);
}
postTools.parse(userData.signature, function (err, signature) {
userData.signature = signature;
res.json(userData);
});
});
}); });
} });
}
getUserDataByUserSlug(req.params.userslug, callerUID, function (err, userData) { function getUserData(req, res, next) {
if(err) { var uid = req.params.uid ? req.params.uid : 0;
return next(err);
} user.getUserData(uid, function(err, userData) {
res.json(userData); res.json(userData);
}); });
}); }
app.get('/api/user/:userslug/settings', function(req, res, next) {
var callerUID = req.user ? req.user.uid : '0';
user.getUidByUserslug(req.params.userslug, function(err, uid) { function getUserPosts(req, res, next) {
if (err) { var callerUID = req.user ? parseInt(req.user.uid, 10) : 0;
return next(err);
}
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') { user.getUserFields(uid, ['username', 'userslug'], function (err, userData) {
return res.json(403, {
error: 'Not allowed!'
});
}
plugins.fireHook('filter:user.settings', [], function(err, settings) {
if (err) { if (err) {
return next(err); return next(err);
} }
user.getUserFields(uid, ['username', 'userslug'], function(err, userData) { if (!userData) {
return res.json(404, {
error: 'User not found!'
});
}
posts.getPostsByUid(callerUID, uid, 0, 19, function (err, userPosts) {
if (err) { if (err) {
return next(err); return next(err);
} }
userData.uid = uid;
if(!userData) {
return res.json(404, {
error: 'User not found!'
});
}
userData.yourid = req.user.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,107 +369,114 @@ 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) {
if (err) {
return next(err);
}
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!'
}); });
} }
user.getUserFields(uid, ['username', 'userslug'], function (err, userData) { if (parseInt(uid, 10) !== callerUID) {
return res.json(403, {
error: 'Not allowed!'
});
}
plugins.fireHook('filter:user.settings', [], function(err, settings) {
if (err) { if (err) {
return next(err); return next(err);
} }
if (!userData) { user.getUserFields(uid, ['username', 'userslug'], function(err, userData) {
return res.json(404, {
error: 'User not found!'
});
}
posts.getPostsByUid(callerUID, uid, 0, 19, function (err, userPosts) {
if (err) { if (err) {
return next(err); return next(err);
} }
userData.uid = uid;
userData.theirid = uid;
userData.yourid = callerUID;
userData.posts = userPosts.posts;
userData.nextStart = userPosts.nextStart;
if(!userData) {
return res.json(404, {
error: 'User not found!'
});
}
userData.yourid = req.user.uid;
userData.theirid = uid;
userData.settings = settings;
res.json(userData); res.json(userData);
}); });
}); });
}); });
}); }
function getUserEdit(req, res, next) {
var callerUID = req.user ? parseInt(req.user.uid, 10) : 0;
app.get('/api/user/uid/:uid', isAllowed, function(req, res, next) { getUserDataByUserSlug(req.params.userslug, callerUID, function (err, userData) {
var uid = req.params.uid ? req.params.uid : 0; if(err) {
return next(err);
user.getUserData(uid, function(err, userData) { }
res.json(userData); res.json(userData);
}); });
}); }
app.get('/api/user/:userslug', isAllowed, function (req, res, next) { function getUserFollowers(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);
} }
if(!userData) { if (userData) {
return res.json(404, { 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!' error: 'User not found!'
}); });
} }
});
}
user.isFollowing(callerUID, userData.theirid, function (isFollowing) { function getUserFollowing(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) {
return next(err);
}
if (userData) {
user.getFollowing(userData.uid, function (err, followingData) {
if(err) { if(err) {
return next(err); return next(err);
} }
userData.following = followingData;
userData.posts = userPosts.posts.filter(function (p) { userData.followingCount = followingData.length;
return p && parseInt(p.deleted, 10) !== 1; res.json(userData);
});
userData.isFollowing = isFollowing;
if (!userData.profileviews) {
userData.profileviews = 1;
}
if (parseInt(callerUID, 10) !== parseInt(userData.uid, 10) && parseInt(callerUID, 0)) {
user.incrementUserFieldBy(userData.uid, 'profileviews', 1);
}
postTools.parse(userData.signature, function (err, signature) {
userData.signature = signature;
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,78 +572,76 @@ var fs = require('fs'),
} }
function getUserDataByUserSlug(userslug, callerUID, callback) { function getUserDataByUserSlug(userslug, callerUID, callback) {
var userData;
async.waterfall([
function(next) {
user.getUidByUserslug(userslug, next);
},
function(uid, next) {
if (!uid) {
return next(new Error('invalid-user'));
}
user.getUserData(uid, next); user.getUidByUserslug(userslug, function(err, uid) {
}, if(err || !uid) {
function(data, next) { return callback(err || new Error('invalid-user'));
userData = data; }
if (!userData) {
return callback(new Error('invalid-user')); async.parallel({
userData : function(next) {
user.getUserData(uid, next);
},
userSettings : function(next) {
user.getSettings(uid, next);
},
isAdmin : function(next) {
user.isAdministrator(callerUID, next);
},
followStats: function(next) {
user.getFollowStats(uid, next);
}
}, function(err, results) {
if(err || !results.userData) {
return callback(err || new Error('invalid-user'));
} }
user.isAdministrator(callerUID, next); var userData = results.userData;
} var userSettings = results.userSettings;
], function(err, isAdmin) { var isAdmin = results.isAdmin;
if(err) {
return callback(err);
}
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);
} else { } else {
userData.lastonline = userData.joindate; userData.lastonline = userData.joindate;
} }
if (!userData.birthday) { if (!userData.birthday) {
userData.age = ''; userData.age = '';
} else { } else {
userData.age = Math.floor((new Date().getTime() - new Date(userData.birthday).getTime()) / 31536000000); userData.age = Math.floor((new Date().getTime() - new Date(userData.birthday).getTime()) / 31536000000);
} }
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";
} }
userData.websiteName = userData.website.replace('http://', '').replace('https://', ''); userData.websiteName = userData.website.replace('http://', '').replace('https://', '');
userData.banned = parseInt(userData.banned, 10) === 1; userData.banned = parseInt(userData.banned, 10) === 1;
userData.uid = userData.uid; userData.uid = userData.uid;
userData.yourid = callerUID; userData.yourid = callerUID;
userData.theirid = userData.uid; userData.theirid = userData.uid;
userData.disableSignatures = meta.config.disableSignatures !== undefined && parseInt(meta.config.disableSignatures, 10) === 1; userData.disableSignatures = meta.config.disableSignatures !== undefined && parseInt(meta.config.disableSignatures, 10) === 1;
userData.followingCount = results.followStats.followingCount;
userData.followerCount = results.followStats.followerCount;
user.getFollowStats(userData.uid, function (err, followStats) {
if(err) {
return callback(err);
}
userData.followingCount = followStats.followingCount;
userData.followerCount = followStats.followerCount;
callback(null, userData); callback(null, userData);
}); });
}); });
} }
}; };
}(exports)); }(exports));

@ -104,43 +104,46 @@ 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) {
db.setObjectField('username:uid', userData.username, uid); if(err) {
db.setObjectField('userslug:uid', userData.userslug, uid); return callback(err);
}
db.setObjectField('username:uid', userData.username, uid);
db.setObjectField('userslug:uid', userData.userslug, uid);
if (userData.email !== undefined) { if (userData.email !== undefined) {
db.setObjectField('email:uid', userData.email, uid); db.setObjectField('email:uid', userData.email, uid);
if (parseInt(uid, 10) !== 1) { if (parseInt(uid, 10) !== 1) {
User.email.verify(uid, userData.email); User.email.verify(uid, userData.email);
}
} }
}
plugins.fireHook('action:user.create', userData); plugins.fireHook('action:user.create', userData);
db.incrObjectField('global', 'userCount'); db.incrObjectField('global', 'userCount');
db.sortedSetAdd('users:joindate', timestamp, uid); db.sortedSetAdd('users:joindate', timestamp, uid);
db.sortedSetAdd('users:postcount', 0, uid); db.sortedSetAdd('users:postcount', 0, uid);
db.sortedSetAdd('users:reputation', 0, uid); db.sortedSetAdd('users:reputation', 0, uid);
groups.joinByGroupName('registered-users', uid); groups.joinByGroupName('registered-users', uid);
if (password) { if (password) {
User.hashPassword(password, function(err, hash) { User.hashPassword(password, function(err, hash) {
if(err) { if(err) {
return callback(err); return callback(err);
} }
User.setUserField(uid, 'password', hash); User.setUserField(uid, 'password', hash);
callback(null, uid);
});
} else {
callback(null, uid); callback(null, uid);
}); }
} else { });
callback(null, uid);
}
}); });
}); });
}; };
@ -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