mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 03:55:55 +01:00
restricting posting by anons, redirects to login page and saves post to localstorage
This commit is contained in:
@@ -143,6 +143,40 @@ var socket,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If there was a saved draft, populate the post content with it now
|
||||||
|
if (localStorage) {
|
||||||
|
var draft = localStorage.getItem(post_mode + '_' + id + '_draft');
|
||||||
|
if (draft && draft.length > 0) {
|
||||||
|
post_content.value = draft;
|
||||||
|
localStorage.removeItem(post_mode + '_' + id + '_draft');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Override post window behaviour if user is not logged in
|
||||||
|
if (document.getElementById('user_label') === null) {
|
||||||
|
submit_post_btn.innerHTML = '<i class="icon-save"></i> Save & Login</i>';
|
||||||
|
submit_post_btn.onclick = function() {
|
||||||
|
// Save the post content in localStorage and send the user to registration page
|
||||||
|
if (localStorage && post_content.value.length > 0) {
|
||||||
|
localStorage.setItem(post_mode + '_' + id + '_draft', post_content.value);
|
||||||
|
|
||||||
|
jQuery(post_window).slideUp(250);
|
||||||
|
$(document.body).removeClass('composing');
|
||||||
|
post_title.value = '';
|
||||||
|
reply_title.value = '';
|
||||||
|
post_content.value = '';
|
||||||
|
|
||||||
|
app.alert({
|
||||||
|
title: 'Post Saved',
|
||||||
|
message: 'We've saved your post as a draft. It will be available again when you log in and post again.',
|
||||||
|
type: 'notify',
|
||||||
|
timeout: 5000
|
||||||
|
});
|
||||||
|
|
||||||
|
ajaxify.go('login');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -65,7 +65,7 @@
|
|||||||
<span class="btn btn-link" tabindex="-1"><i class="icon-list"></i></span>
|
<span class="btn btn-link" tabindex="-1"><i class="icon-list"></i></span>
|
||||||
</div>
|
</div>
|
||||||
<div class="btn-group" style="float: right; margin-right: -12px">
|
<div class="btn-group" style="float: right; margin-right: -12px">
|
||||||
<button id="submit_post_btn" class="btn" onclick="app.post_topic()" tabIndex="3"><i class="icon-ok"></i> Submit</button>
|
<button id="submit_post_btn" class="btn" tabIndex="3"><i class="icon-ok"></i> Submit</button>
|
||||||
<button class="btn" id="discard-post" tabIndex="4"><i class="icon-remove"></i> Discard</button>
|
<button class="btn" id="discard-post" tabIndex="4"><i class="icon-remove"></i> Discard</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
10
src/posts.js
10
src/posts.js
@@ -146,6 +146,16 @@ marked.setOptions({
|
|||||||
|
|
||||||
|
|
||||||
Posts.reply = function(socket, tid, uid, content) {
|
Posts.reply = function(socket, tid, uid, content) {
|
||||||
|
if (uid < 1) {
|
||||||
|
socket.emit('event:alert', {
|
||||||
|
title: 'Reply Unsuccessful',
|
||||||
|
message: 'You don't seem to be logged in, so you cannot reply.',
|
||||||
|
type: 'error',
|
||||||
|
timeout: 2000
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Posts.create(uid, tid, content, function(pid) {
|
Posts.create(uid, tid, content, function(pid) {
|
||||||
if (pid > 0) {
|
if (pid > 0) {
|
||||||
RDB.rpush('tid:' + tid + ':posts', pid);
|
RDB.rpush('tid:' + tid + ':posts', pid);
|
||||||
|
|||||||
Reference in New Issue
Block a user