mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-09 15:35:47 +01:00
fixed logout in admin site, cleaned up topics.post, anon users can post topics now if allowed
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
define(function() {
|
define(function() {
|
||||||
var Admin = {};
|
var Admin = {};
|
||||||
|
|
||||||
Admin.init = function() {
|
Admin.init = function() {
|
||||||
ajaxify.register_events(['api:get_all_rooms']);
|
ajaxify.register_events(['api:get_all_rooms']);
|
||||||
socket.on('api:get_all_rooms', function(data) {
|
socket.on('api:get_all_rooms', function(data) {
|
||||||
|
|
||||||
@@ -22,6 +22,14 @@ define(function() {
|
|||||||
|
|
||||||
app.enterRoom('admin');
|
app.enterRoom('admin');
|
||||||
socket.emit('api:get_all_rooms');
|
socket.emit('api:get_all_rooms');
|
||||||
|
|
||||||
|
$('#logout-link').on('click', function() {
|
||||||
|
$.post(RELATIVE_PATH + '/logout', {
|
||||||
|
_csrf: $('#csrf_token').val()
|
||||||
|
}, function() {
|
||||||
|
window.location.href = RELATIVE_PATH + '/';
|
||||||
|
});
|
||||||
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
return Admin;
|
return Admin;
|
||||||
|
|||||||
177
src/topics.js
177
src/topics.js
@@ -20,105 +20,104 @@ var RDB = require('./redis'),
|
|||||||
|
|
||||||
(function(Topics) {
|
(function(Topics) {
|
||||||
|
|
||||||
Topics.post = function(uid, title, content, category_id, callback) {
|
Topics.post = function(uid, title, content, cid, callback) {
|
||||||
CategoryTools.privileges(category_id, uid, function(err, privileges) {
|
|
||||||
if (privileges.write) {
|
|
||||||
if (!category_id)
|
|
||||||
throw new Error('Attempted to post without a category_id');
|
|
||||||
|
|
||||||
if (content)
|
CategoryTools.privileges(cid, uid, function(err, privileges) {
|
||||||
content = content.trim();
|
|
||||||
if (title)
|
|
||||||
title = title.trim();
|
|
||||||
|
|
||||||
if (!uid) {
|
if(err) {
|
||||||
callback(new Error('not-logged-in'), null);
|
return callback(err);
|
||||||
return;
|
} else if(!privileges.write) {
|
||||||
} else if (!title || title.length < meta.config.minimumTitleLength) {
|
return callback(new Error('no-privileges'));
|
||||||
callback(new Error('title-too-short'), null);
|
} else if (!cid) {
|
||||||
return;
|
return callback(new Error('invalid-cid'));
|
||||||
} else if (!content || content.length < meta.config.miminumPostLength) {
|
} else if (!title || title.length < meta.config.minimumTitleLength) {
|
||||||
callback(new Error('content-too-short'), null);
|
return callback(new Error('title-too-short'), null);
|
||||||
return;
|
} else if (!content || content.length < meta.config.miminumPostLength) {
|
||||||
|
return callback(new Error('content-too-short'), null);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (content) {
|
||||||
|
content = content.trim();
|
||||||
|
}
|
||||||
|
if (title) {
|
||||||
|
title = title.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
user.getUserField(uid, 'lastposttime', function(err, lastposttime) {
|
||||||
|
if (err) {
|
||||||
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
user.getUserField(uid, 'lastposttime', function(err, lastposttime) {
|
if(!lastposttime) {
|
||||||
if (err) lastposttime = 0;
|
lastposttime = 0;
|
||||||
if (Date.now() - lastposttime < meta.config.postDelay * 1000) {
|
}
|
||||||
callback(new Error('too-many-posts'), null);
|
|
||||||
return;
|
if (Date.now() - lastposttime < meta.config.postDelay * 1000) {
|
||||||
|
return callback(new Error('too-many-posts'), null);
|
||||||
|
}
|
||||||
|
|
||||||
|
RDB.incr('next_topic_id', function(err, tid) {
|
||||||
|
if(err) {
|
||||||
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
RDB.incr('next_topic_id', function(err, tid) {
|
RDB.sadd('topics:tid', tid);
|
||||||
RDB.handle(err);
|
|
||||||
|
|
||||||
// Global Topics
|
var slug = tid + '/' + utils.slugify(title);
|
||||||
if (uid == null) uid = 0;
|
var timestamp = Date.now();
|
||||||
if (uid !== null) {
|
RDB.hmset('topic:' + tid, {
|
||||||
RDB.sadd('topics:tid', tid);
|
'tid': tid,
|
||||||
} else {
|
'uid': uid,
|
||||||
// need to add some unique key sent by client so we can update this with the real uid later
|
'cid': cid,
|
||||||
RDB.lpush('topics:queued:tid', tid);
|
'title': title,
|
||||||
|
'slug': slug,
|
||||||
|
'timestamp': timestamp,
|
||||||
|
'lastposttime': 0,
|
||||||
|
'postcount': 0,
|
||||||
|
'viewcount': 0,
|
||||||
|
'locked': 0,
|
||||||
|
'deleted': 0,
|
||||||
|
'pinned': 0
|
||||||
|
});
|
||||||
|
|
||||||
|
topicSearch.index(title, tid);
|
||||||
|
|
||||||
|
user.addTopicIdToUser(uid, tid);
|
||||||
|
|
||||||
|
// let everyone know that there is an unread topic in this category
|
||||||
|
RDB.del('cid:' + cid + ':read_by_uid', function(err, data) {
|
||||||
|
Topics.markAsRead(tid, uid);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
// in future it may be possible to add topics to several categories, so leaving the door open here.
|
||||||
|
RDB.zadd('categories:' + cid + ':tid', timestamp, tid);
|
||||||
|
RDB.hincrby('category:' + cid, 'topic_count', 1);
|
||||||
|
RDB.incr('totaltopiccount');
|
||||||
|
|
||||||
|
feed.updateCategory(cid);
|
||||||
|
|
||||||
|
posts.create(uid, tid, content, function(err, postData) {
|
||||||
|
if(err) {
|
||||||
|
return callback(err, null);
|
||||||
|
} else if(!postData) {
|
||||||
|
return callback(new Error('invalid-post'), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
var slug = tid + '/' + utils.slugify(title);
|
// Auto-subscribe the post creator to the newly created topic
|
||||||
var timestamp = Date.now();
|
threadTools.toggleFollow(tid, uid);
|
||||||
RDB.hmset('topic:' + tid, {
|
|
||||||
'tid': tid,
|
|
||||||
'uid': uid,
|
|
||||||
'cid': category_id,
|
|
||||||
'title': title,
|
|
||||||
'slug': slug,
|
|
||||||
'timestamp': timestamp,
|
|
||||||
'lastposttime': 0,
|
|
||||||
'postcount': 0,
|
|
||||||
'viewcount': 0,
|
|
||||||
'locked': 0,
|
|
||||||
'deleted': 0,
|
|
||||||
'pinned': 0
|
|
||||||
});
|
|
||||||
|
|
||||||
topicSearch.index(title, tid);
|
Topics.getTopicForCategoryView(tid, uid, function(topicData) {
|
||||||
|
topicData.unreplied = 1;
|
||||||
|
|
||||||
user.addTopicIdToUser(uid, tid);
|
callback(null, {
|
||||||
|
topicData: topicData,
|
||||||
// let everyone know that there is an unread topic in this category
|
postData: postData
|
||||||
RDB.del('cid:' + category_id + ':read_by_uid', function(err, data) {
|
|
||||||
Topics.markAsRead(tid, uid);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
// in future it may be possible to add topics to several categories, so leaving the door open here.
|
|
||||||
RDB.zadd('categories:' + category_id + ':tid', timestamp, tid);
|
|
||||||
RDB.hincrby('category:' + category_id, 'topic_count', 1);
|
|
||||||
RDB.incr('totaltopiccount');
|
|
||||||
|
|
||||||
feed.updateCategory(category_id);
|
|
||||||
|
|
||||||
posts.create(uid, tid, content, function(err, postData) {
|
|
||||||
if(err) {
|
|
||||||
return callback(err, null);
|
|
||||||
} else if(!postData) {
|
|
||||||
return callback(new Error('invalid-post'), null);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Auto-subscribe the post creator to the newly created topic
|
|
||||||
threadTools.toggleFollow(tid, uid);
|
|
||||||
|
|
||||||
Topics.getTopicForCategoryView(tid, uid, function(topicData) {
|
|
||||||
topicData.unreplied = 1;
|
|
||||||
|
|
||||||
callback(null, {
|
|
||||||
topicData: topicData,
|
|
||||||
postData: postData
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
} else {
|
});
|
||||||
callback(new Error('no-privileges'));
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -459,9 +458,9 @@ var RDB = require('./redis'),
|
|||||||
topicData['deleted-class'] = topicData.deleted === '1' ? 'deleted' : '';
|
topicData['deleted-class'] = topicData.deleted === '1' ? 'deleted' : '';
|
||||||
|
|
||||||
topicData.unreplied = topicData.postcount === '1';
|
topicData.unreplied = topicData.postcount === '1';
|
||||||
topicData.username = topicInfo.username;
|
topicData.username = topicInfo.username || 'anonymous';
|
||||||
topicData.userslug = topicInfo.userslug;
|
topicData.userslug = topicInfo.userslug || '';
|
||||||
topicData.picture = topicInfo.picture;
|
topicData.picture = topicInfo.picture || require('gravatar').url('', {}, https = nconf.get('https'));;
|
||||||
topicData.categoryIcon = topicInfo.categoryData.icon;
|
topicData.categoryIcon = topicInfo.categoryData.icon;
|
||||||
topicData.categoryName = topicInfo.categoryData.name;
|
topicData.categoryName = topicInfo.categoryData.name;
|
||||||
topicData.categorySlug = topicInfo.categoryData.slug;
|
topicData.categorySlug = topicInfo.categoryData.slug;
|
||||||
@@ -644,9 +643,7 @@ var RDB = require('./redis'),
|
|||||||
Topics.markAllRead = function(uid, callback) {
|
Topics.markAllRead = function(uid, callback) {
|
||||||
RDB.smembers('topics:tid', function(err, tids) {
|
RDB.smembers('topics:tid', function(err, tids) {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log(err);
|
return callback(err, null);
|
||||||
callback(err, null);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tids && tids.length) {
|
if (tids && tids.length) {
|
||||||
|
|||||||
@@ -346,20 +346,19 @@ module.exports.init = function(io) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
socket.on('api:topics.post', function(data) {
|
socket.on('api:topics.post', function(data) {
|
||||||
|
if (uid < 1 && meta.config.allowGuestPosting === '0') {
|
||||||
|
socket.emit('event:alert', {
|
||||||
|
title: 'Post Unsuccessful',
|
||||||
|
message: 'You don't seem to be logged in, so you cannot reply.',
|
||||||
|
type: 'danger',
|
||||||
|
timeout: 2000
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
topics.post(uid, data.title, data.content, data.category_id, function(err, result) {
|
topics.post(uid, data.title, data.content, data.category_id, function(err, result) {
|
||||||
if(err) {
|
if(err) {
|
||||||
if (err.message === 'not-logged-in') {
|
if (err.message === 'title-too-short') {
|
||||||
socket.emit('event:alert', {
|
|
||||||
title: 'Thank you for posting',
|
|
||||||
message: 'Since you are unregistered, your post is awaiting approval. Click here to register now.',
|
|
||||||
type: 'warning',
|
|
||||||
timeout: 7500,
|
|
||||||
clickfn: function() {
|
|
||||||
ajaxify.go('register');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else if (err.message === 'title-too-short') {
|
|
||||||
topics.emitTitleTooShortAlert(socket);
|
topics.emitTitleTooShortAlert(socket);
|
||||||
} else if (err.message === 'content-too-short') {
|
} else if (err.message === 'content-too-short') {
|
||||||
posts.emitContentTooShortAlert(socket);
|
posts.emitContentTooShortAlert(socket);
|
||||||
|
|||||||
Reference in New Issue
Block a user