diff --git a/public/src/forum/admin/settings.js b/public/src/forum/admin/settings.js index 6c75e6457a..989e94a79c 100644 --- a/public/src/forum/admin/settings.js +++ b/public/src/forum/admin/settings.js @@ -32,7 +32,7 @@ define(['uploader'], function(uploader) { break; case 'checkbox': - fields[x].checked = app.config[key] === '1' ? true : false; + fields[x].checked = parseInt(app.config[key], 10) === 1; break; } } diff --git a/src/database/mongo.js b/src/database/mongo.js index 609c6f9f3f..4ba91da50e 100644 --- a/src/database/mongo.js +++ b/src/database/mongo.js @@ -369,7 +369,7 @@ }; data.setName = key; - module.setObject(key+':'+value, data, callback); + module.setObject(key + ':' + value, data, callback); } module.sortedSetRemove = function(key, value, callback) { diff --git a/src/feed.js b/src/feed.js index 798c8bdabd..d270e4b3cc 100644 --- a/src/feed.js +++ b/src/feed.js @@ -55,8 +55,8 @@ } async.each(topicData.posts, function(postData, next) { - if (postData.deleted === '0') { - dateStamp = new Date(parseInt(postData.edited === '0' ? postData.timestamp : postData.edited, 10)).toUTCString(); + if (parseInt(postData.deleted, 10) === 0) { + dateStamp = new Date(parseInt(parseInt(postData.edited, 10) === 0 ? postData.timestamp : postData.edited, 10)).toUTCString(); feed.item({ title: 'Reply to ' + topicData.topic_name + ' on ' + dateStamp, diff --git a/src/groups.js b/src/groups.js index 972cb9545f..da521a75af 100644 --- a/src/groups.js +++ b/src/groups.js @@ -15,7 +15,7 @@ }, function (err, groups) { // Remove deleted and hidden groups from this list callback(err, groups.filter(function (group) { - if (group.deleted === '1' || group.hidden === '1') { + if (parseInt(group.deleted, 10) === 1 || parseInt(group.hidden, 10) === 1) { return false; } else { return true; @@ -76,7 +76,7 @@ Groups.isDeleted = function(gid, callback) { db.getObjectField('gid:' + gid, 'deleted', function(err, deleted) { - callback(err, deleted === '1'); + callback(err, parseInt(deleted, 10) === 1); }); }; @@ -240,7 +240,7 @@ return next(err); } - if (groupObj.deleted === '1') { + if (parseInt(groupObj.deleted, 10) === 1) { db.deleteObjectField('group:gid', groupObj.name, function(err) { db.delete('gid:' + gid, function(err) { diff --git a/src/login.js b/src/login.js index adce1f8bfc..c4eb226586 100644 --- a/src/login.js +++ b/src/login.js @@ -28,7 +28,7 @@ var user = require('./user'), user.getUserFields(uid, ['password', 'banned'], function(err, userData) { if (err) return next(err); - if (userData.banned && userData.banned === '1') { + if (userData.banned && parseInt(userData.banned, 10) === 1) { return next({ status: "error", message: "user-banned" diff --git a/src/postTools.js b/src/postTools.js index 2641b8d9b2..0ec6abc81a 100644 --- a/src/postTools.js +++ b/src/postTools.js @@ -164,7 +164,7 @@ var db = require('./database'), }; posts.getPostField(pid, 'deleted', function(err, deleted) { - if(deleted === '1') { + if(parseInt(deleted, 10) === 1) { return callback(new Error('Post already deleted!')); } @@ -195,7 +195,7 @@ var db = require('./database'), // Restore topic if it is the only post topics.getTopicField(postData.tid, 'postcount', function(err, count) { - if (count === '1') { + if (parseInt(count, 10) === 1) { threadTools.restore(postData.tid, uid); } }); @@ -210,7 +210,7 @@ var db = require('./database'), }; posts.getPostField(pid, 'deleted', function(err, deleted) { - if(deleted === '0') { + if(parseInt(deleted, 10) === 0) { return callback(new Error('Post already restored')); } diff --git a/src/posts.js b/src/posts.js index 8dc8900f97..f6375d2401 100644 --- a/src/posts.js +++ b/src/posts.js @@ -78,7 +78,7 @@ var db = require('./database'), db.sortedSetAdd('categories:recent_posts:cid:' + cid, timestamp, pid); - if(topicData.pinned === '0') { + if(parseInt(topicData.pinned, 10) === 0) { db.sortedSetAdd('categories:' + cid + ':tid', timestamp, tid); } @@ -213,7 +213,7 @@ var db = require('./database'), post.userslug = userData.userslug || ''; post.user_rep = userData.reputation || 0; post.user_postcount = userData.postcount || 0; - post.user_banned = userData.banned === '1'; + post.user_banned = parseInt(userData.banned, 10) === 1; post.picture = userData.picture || require('gravatar').url('', {}, https = nconf.get('https')); post.signature = signature; @@ -250,7 +250,7 @@ var db = require('./database'), async.waterfall([ function(next) { Posts.getPostFields(pid, ['pid', 'tid', 'content', 'uid', 'timestamp', 'deleted'], function(err, postData) { - if (postData.deleted === '1') { + if (parseInt(postData.deleted, 10) === 1) { return callback(null); } else { postData.relativeTime = new Date(parseInt(postData.timestamp || 0, 10)).toISOString(); @@ -267,7 +267,7 @@ var db = require('./database'), topics.getTopicFields(postData.tid, ['title', 'cid', 'slug', 'deleted'], function(err, topicData) { if (err) { return callback(err); - } else if (topicData.deleted === '1') { + } else if (parseInt(topicData.deleted, 10) === 1) { return callback(null); } categories.getCategoryFields(topicData.cid, ['name', 'icon', 'slug'], function(err, categoryData) { diff --git a/src/routes/admin.js b/src/routes/admin.js index 666877560c..e8402442f9 100644 --- a/src/routes/admin.js +++ b/src/routes/admin.js @@ -241,7 +241,7 @@ var nconf = require('nconf'), app.get('/categories/active', function (req, res) { categories.getAllCategories(0, function (err, data) { data.categories = data.categories.filter(function (category) { - return (!category.disabled || category.disabled === "0"); + return (!category.disabled || parseInt(category.disabled, 10) === 0); }); res.json(data); }); @@ -250,7 +250,7 @@ var nconf = require('nconf'), app.get('/categories/disabled', function (req, res) { categories.getAllCategories(0, function (err, data) { data.categories = data.categories.filter(function (category) { - return category.disabled === "1"; + return parseInt(category.disabled, 10) === 1; }); res.json(data); }); diff --git a/src/routes/api.js b/src/routes/api.js index 389763bac5..3510f5bdec 100644 --- a/src/routes/api.js +++ b/src/routes/api.js @@ -42,7 +42,7 @@ var path = require('path'), var uid = (req.user) ? req.user.uid : 0; categories.getAllCategories(uid, function (err, data) { data.categories = data.categories.filter(function (category) { - return (!category.disabled || category.disabled === "0"); + return (!category.disabled || parseInt(category.disabled, 10) === 0); }); function iterator(category, callback) { @@ -54,7 +54,7 @@ var path = require('path'), } async.each(data.categories, iterator, function (err) { - data.motd_class = (meta.config.show_motd === '1' || meta.config.show_motd === undefined) ? '' : ' none'; + data.motd_class = (parseInt(meta.config.show_motd, 10) === 1 || meta.config.show_motd === undefined) ? '' : ' none'; data.motd_class += (meta.config.motd && meta.config.motd.length > 0 ? '' : ' default'); data.motd = require('marked')(meta.config.motd || "
\n\n# NodeBB v" + pkg.version + "\nWelcome to NodeBB, the discussion platform of the future."); @@ -117,7 +117,7 @@ var path = require('path'), 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 (parseInt(data.deleted, 10) === 1 && parseInt(data.expose_tools, 10) === 0) { return res.json(404, {}); } res.json(data); @@ -132,10 +132,11 @@ var path = require('path'), categoryTools.privileges(req.params.id, uid, function(err, privileges) { if (!err && privileges.read) { categories.getCategoryById(req.params.id, uid, function (err, data) { - if (!err && data && data.disabled === "0") + if (!err && data && parseInt(data.disabled, 10) === 0) { res.json(data); - else + } else { next(); + } }, req.params.id, uid); } else { res.send(403); diff --git a/src/routes/user.js b/src/routes/user.js index 58231a16c6..80f97347a1 100644 --- a/src/routes/user.js +++ b/src/routes/user.js @@ -318,10 +318,11 @@ var fs = require('fs'), return next(err); if (userData) { - if (userData.showemail && userData.showemail === "1") + if (userData.showemail && parseInt(userData.showemail, 10) === 1) { userData.showemail = "checked"; - else + } else { userData.showemail = ""; + } res.json(userData); } else { res.json(404, { @@ -501,21 +502,21 @@ var fs = require('fs'), } function canSeeEmail() { - return callerUID == uid || (data.email && (data.showemail && data.showemail === "1")); + return callerUID == uid || (data.email && (data.showemail && parseInt(data.showemail, 10) === 1)); } if (!canSeeEmail()) { data.email = ""; } - if (callerUID == uid && (!data.showemail || data.showemail === "0")) { + if (callerUID == uid && (!data.showemail || parseInt(data.showemail, 10) === 0)) { data.emailClass = ""; } else { data.emailClass = "hide"; } data.websiteName = data.website.replace('http://', '').replace('https://', ''); - data.banned = data.banned === '1'; + data.banned = parseInt(data.banned, 10) === 1; data.uid = uid; data.yourid = callerUID; data.theirid = uid; diff --git a/src/threadTools.js b/src/threadTools.js index a392241131..939603958c 100644 --- a/src/threadTools.js +++ b/src/threadTools.js @@ -292,7 +292,7 @@ var db = require('./database'), pids.reverse(); async.detectSeries(pids, function(pid, next) { posts.getPostField(pid, 'deleted', function(err, deleted) { - if (deleted === '0') { + if (parseInt(deleted, 10) === 0) { next(true); } else { next(false); diff --git a/src/topics.js b/src/topics.js index 4345545685..fc80cc965b 100644 --- a/src/topics.js +++ b/src/topics.js @@ -170,7 +170,7 @@ var async = require('async'), } postData = postData.filter(function(post) { - return parseInt(current_user, 10) !== 0 || post.deleted === "0"; + return parseInt(current_user, 10) !== 0 || parseInt(post.deleted, 10) === 0; }); function getFavouritesData(next) { @@ -454,18 +454,18 @@ var async = require('async'), getTopicInfo(topicData, function(topicInfo) { - topicData['pin-icon'] = topicData.pinned === '1' ? 'fa-thumb-tack' : 'none'; - topicData['lock-icon'] = topicData.locked === '1' ? 'fa-lock' : 'none'; - topicData['deleted-class'] = topicData.deleted === '1' ? 'deleted' : ''; + topicData['pin-icon'] = parseInt(topicData.pinned, 10) === 1 ? 'fa-thumb-tack' : 'none'; + topicData['lock-icon'] = parseInt(topicData.locked, 10) === 1 ? 'fa-lock' : 'none'; + topicData['deleted-class'] = parseInt(topicData.deleted, 10) === 1 ? 'deleted' : ''; - topicData.unreplied = topicData.postcount === '1'; + topicData.unreplied = parseInt(topicData.postcount, 10) === 1; topicData.username = topicInfo.username || 'anonymous'; topicData.userslug = topicInfo.userslug || ''; topicData.picture = topicInfo.picture || gravatar.url('', {}, https = nconf.get('https')); topicData.categoryIcon = topicInfo.categoryData.icon; topicData.categoryName = topicInfo.categoryData.name; topicData.categorySlug = topicInfo.categoryData.slug; - topicData.badgeclass = (topicInfo.hasread && current_user != 0) ? '' : 'badge-important'; + topicData.badgeclass = (topicInfo.hasread && parseInt(current_user, 10) !== 0) ? '' : 'badge-important'; topicData.teaser_text = topicInfo.teaserInfo.text || '', topicData.teaser_username = topicInfo.teaserInfo.username || ''; topicData.teaser_userslug = topicInfo.teaserInfo.userslug || ''; @@ -555,7 +555,7 @@ var async = require('async'), } function getReadStatus(next) { - if (uid && parseInt(uid) > 0) { + if (uid && parseInt(uid, 10) > 0) { Topics.hasReadTopic(tid, uid, function(read) { next(null, read); }); @@ -580,8 +580,8 @@ var async = require('async'), hasRead = results[1], teaser = results[2]; - topicData['pin-icon'] = topicData.pinned === '1' ? 'fa-thumb-tack' : 'none'; - topicData['lock-icon'] = topicData.locked === '1' ? 'fa-lock' : 'none'; + topicData['pin-icon'] = parseInt(topicData.pinned, 10) === 1 ? 'fa-thumb-tack' : 'none'; + topicData['lock-icon'] = parseInt(topicData.locked, 10) === 1 ? 'fa-lock' : 'none'; topicData.badgeclass = hasRead ? '' : 'badge-important'; topicData.teaser_text = teaser.text || ''; @@ -808,7 +808,7 @@ var async = require('async'), if(err) { return callback(err, null); } - callback(null, locked === "1"); + callback(null, parseInt(locked, 10) === 1); }); } diff --git a/src/user.js b/src/user.js index 29f574174d..8bc99bea91 100644 --- a/src/user.js +++ b/src/user.js @@ -182,12 +182,6 @@ var bcrypt = require('bcrypt'), }); }; - User.filterBannedUsers = function(users) { - return users.filter(function(user) { - return (!user.banned || user.banned === '0'); - }); - }; - User.updateProfile = function(uid, data, callback) { var fields = ['email', 'fullname', 'website', 'location', 'birthday', 'signature']; @@ -550,7 +544,7 @@ var bcrypt = require('bcrypt'), } function iterator(uid, callback) { - if(uid === "0") { + if(parseInt(uid, 10) === 0) { return callback(null); } diff --git a/src/webserver.js b/src/webserver.js index e98f3fcfe3..0c224f6569 100644 --- a/src/webserver.js +++ b/src/webserver.js @@ -465,7 +465,7 @@ var path = require('path'), function (next) { topics.getTopicWithPosts(tid, ((req.user) ? req.user.uid : 0), 0, -1, function (err, topicData) { if (topicData) { - if (topicData.deleted === '1' && topicData.expose_tools === 0) { + if (parseInt(topicData.deleted, 10) === 1 && parseInt(topicData.expose_tools, 10) === 0) { return next(new Error('Topic deleted'), null); } } @@ -587,7 +587,7 @@ var path = require('path'), categories.getCategoryById(cid, 0, function (err, categoryData) { if (categoryData) { - if (categoryData.disabled === '1') { + if (parseInt(categoryData.disabled, 10) === 1) { return next(new Error('Category disabled'), null); } } diff --git a/src/websockets.js b/src/websockets.js index 09667ca401..0eb93febbb 100644 --- a/src/websockets.js +++ b/src/websockets.js @@ -349,7 +349,7 @@ websockets.init = function(io) { }); socket.on('api:topics.post', function(data) { - if (uid < 1 && meta.config.allowGuestPosting === '0') { + if (uid < 1 && parseInt(meta.config.allowGuestPosting, 10) === 0) { socket.emit('event:alert', { title: 'Post Unsuccessful', message: 'You don't seem to be logged in, so you cannot reply.', @@ -420,7 +420,7 @@ websockets.init = function(io) { }); socket.on('api:posts.reply', function(data) { - if (uid < 1 && meta.config.allowGuestPosting === '0') { + if (uid < 1 && parseInt(meta.config.allowGuestPosting, 10) === 0) { socket.emit('event:alert', { title: 'Reply Unsuccessful', message: 'You don't seem to be logged in, so you cannot reply.', @@ -772,7 +772,7 @@ websockets.init = function(io) { }); socket.on('api:composer.push', function(data) { - if (uid > 0 || meta.config.allowGuestPosting === '1') { + if (parseInt(uid, 10) > 0 || parseInt(meta.config.allowGuestPosting, 10) === 1) { if (parseInt(data.tid) > 0) { topics.getTopicData(data.tid, function(err, topicData) { if (data.body)