Merge branch 'master' of github.com:designcreateplay/NodeBB
commit
2badb76fc2
@ -0,0 +1,100 @@
|
||||
'use strict';
|
||||
|
||||
/* globals define, app, socket */
|
||||
|
||||
define(function() {
|
||||
|
||||
var Move = {};
|
||||
|
||||
Move.init = function(tid) {
|
||||
var modal = $('#move_thread_modal'),
|
||||
targetCid,
|
||||
targetCategoryLabel;
|
||||
|
||||
$('.move_thread').on('click', function(e) {
|
||||
modal.modal('show');
|
||||
return false;
|
||||
});
|
||||
|
||||
modal.on('shown.bs.modal', onMoveModalShown);
|
||||
|
||||
function onMoveModalShown() {
|
||||
var loadingEl = $('#categories-loading');
|
||||
if (!loadingEl.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
socket.emit('categories.get', onCategoriesLoaded);
|
||||
}
|
||||
|
||||
function onCategoriesLoaded(err, data) {
|
||||
if (err) {
|
||||
return app.alertError(err.message);
|
||||
}
|
||||
|
||||
renderCategories(data.categories);
|
||||
|
||||
modal.find('.category-list').on('click', 'li[data-cid]', function(e) {
|
||||
selectCategory($(this));
|
||||
});
|
||||
|
||||
$('#move_thread_commit').on('click', onCommitClicked);
|
||||
}
|
||||
|
||||
function selectCategory(category) {
|
||||
modal.find('#confirm-category-name').html(category.html());
|
||||
$('#move-confirm').css({display: 'block'});
|
||||
|
||||
targetCid = category.attr('data-cid');
|
||||
targetCategoryLabel = category.html();
|
||||
$('#move_thread_commit').prop('disabled', false);
|
||||
}
|
||||
|
||||
function onCommitClicked() {
|
||||
var commitEl = $('#move_thread_commit'),
|
||||
cancelEl = $('#move_thread_cancel');
|
||||
|
||||
if (!commitEl.prop('disabled') && targetCid) {
|
||||
commitEl.prop('disabled', true);
|
||||
cancelEl.fadeOut(250);
|
||||
modal.find('.modal-header button').fadeOut(250);
|
||||
commitEl.html('Moving <i class="fa-spin fa-refresh"></i>');
|
||||
|
||||
moveTopic();
|
||||
}
|
||||
}
|
||||
|
||||
function moveTopic() {
|
||||
socket.emit('topics.move', {
|
||||
tid: tid,
|
||||
cid: targetCid
|
||||
}, function(err) {
|
||||
modal.modal('hide');
|
||||
if(err) {
|
||||
return app.alertError('This topic could not be moved to ' + targetCategoryLabel + '.<br />Please try again later');
|
||||
}
|
||||
|
||||
app.alertSuccess('This topic has been successfully moved to ' + targetCategoryLabel);
|
||||
});
|
||||
}
|
||||
|
||||
function renderCategories(categories) {
|
||||
var categoriesEl = modal.find('.category-list'),
|
||||
info;
|
||||
|
||||
for (var x = 0; x < categories.length; ++x) {
|
||||
info = categories[x];
|
||||
$('<li />')
|
||||
.css({background: info.bgColor, color: info.color || '#fff'})
|
||||
.addClass(info.disabled === '1' ? ' disabled' : '')
|
||||
.attr('data-cid', info.cid)
|
||||
.html('<i class="fa ' + info.icon + '"></i> ' + info.name)
|
||||
.appendTo(categoriesEl);
|
||||
}
|
||||
|
||||
$('#categories-loading').remove();
|
||||
}
|
||||
};
|
||||
|
||||
return Move;
|
||||
});
|
@ -0,0 +1,53 @@
|
||||
'use strict';
|
||||
|
||||
/* globals define, app, translator, socket, bootbox */
|
||||
|
||||
define(['forum/topic/fork', 'forum/topic/move'], function(fork, move) {
|
||||
|
||||
var ThreadTools = {};
|
||||
|
||||
ThreadTools.init = function(tid, threadState) {
|
||||
|
||||
$('.thread-tools').removeClass('hide');
|
||||
|
||||
$('.delete_thread').on('click', function(e) {
|
||||
var command = threadState.deleted !== '1' ? 'delete' : 'restore';
|
||||
|
||||
bootbox.confirm('Are you sure you want to ' + command + ' this thread?', function(confirm) {
|
||||
if (confirm) {
|
||||
socket.emit('topics.' + command, tid);
|
||||
}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
|
||||
$('.lock_thread').on('click', function(e) {
|
||||
socket.emit(threadState.locked !== '1' ? 'topics.lock' : 'topics.unlock', tid);
|
||||
return false;
|
||||
});
|
||||
|
||||
$('.pin_thread').on('click', function(e) {
|
||||
socket.emit(threadState.pinned !== '1' ? 'topics.pin' : 'topics.unpin', tid);
|
||||
return false;
|
||||
});
|
||||
|
||||
$('.markAsUnreadForAll').on('click', function() {
|
||||
var btn = $(this);
|
||||
socket.emit('topics.markAsUnreadForAll', tid, function(err) {
|
||||
if(err) {
|
||||
return app.alertError(err.message);
|
||||
}
|
||||
app.alertSuccess('[[topic:markAsUnreadForAll.success]]');
|
||||
btn.parents('.thread-tools.open').find('.dropdown-toggle').trigger('click');
|
||||
});
|
||||
return false;
|
||||
});
|
||||
|
||||
move.init(tid);
|
||||
|
||||
fork.init();
|
||||
};
|
||||
|
||||
|
||||
return ThreadTools;
|
||||
});
|
@ -0,0 +1,134 @@
|
||||
'use strict';
|
||||
|
||||
var async = require('async'),
|
||||
db = require('./../database'),
|
||||
utils = require('./../../public/src/utils'),
|
||||
validator = require('validator'),
|
||||
plugins = require('./../plugins'),
|
||||
groups = require('./../groups');
|
||||
|
||||
module.exports = function(User) {
|
||||
|
||||
User.create = function(userData, callback) {
|
||||
userData = userData || {};
|
||||
userData.userslug = utils.slugify(userData.username);
|
||||
|
||||
userData.username = userData.username.trim();
|
||||
if (userData.email !== undefined) {
|
||||
userData.email = userData.email.trim();
|
||||
userData.email = validator.escape(userData.email);
|
||||
}
|
||||
|
||||
async.parallel([
|
||||
function(next) {
|
||||
next(!utils.isEmailValid(userData.email) ? new Error('Invalid Email!') : null);
|
||||
},
|
||||
function(next) {
|
||||
next((!utils.isUserNameValid(userData.username) || !userData.userslug) ? new Error('Invalid Username!') : null);
|
||||
},
|
||||
function(next) {
|
||||
next(!utils.isPasswordValid(userData.password) ? new Error('Invalid Password!') : null);
|
||||
},
|
||||
function(next) {
|
||||
User.exists(userData.userslug, function(err, exists) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
next(exists ? new Error('Username taken!') : null);
|
||||
});
|
||||
},
|
||||
function(next) {
|
||||
if (userData.email) {
|
||||
User.email.available(userData.email, function(err, available) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
next(!available ? new Error('Email taken!') : null);
|
||||
});
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
},
|
||||
function(next) {
|
||||
plugins.fireHook('filter:user.create', userData, function(err, filteredUserData){
|
||||
next(err, utils.merge(userData, filteredUserData));
|
||||
});
|
||||
}
|
||||
], function(err, results) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
userData = results[results.length - 1];
|
||||
|
||||
db.incrObjectField('global', 'nextUid', function(err, uid) {
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
var gravatar = User.createGravatarURLFromEmail(userData.email);
|
||||
var timestamp = Date.now();
|
||||
var password = userData.password;
|
||||
|
||||
userData = {
|
||||
'uid': uid,
|
||||
'username': userData.username,
|
||||
'userslug': userData.userslug,
|
||||
'fullname': '',
|
||||
'location': '',
|
||||
'birthday': '',
|
||||
'website': '',
|
||||
'email': userData.email || '',
|
||||
'signature': '',
|
||||
'joindate': timestamp,
|
||||
'picture': gravatar,
|
||||
'gravatarpicture': gravatar,
|
||||
'uploadedpicture': '',
|
||||
'profileviews': 0,
|
||||
'reputation': 0,
|
||||
'postcount': 0,
|
||||
'lastposttime': 0,
|
||||
'banned': 0,
|
||||
'status': 'online'
|
||||
};
|
||||
|
||||
db.setObject('user:' + uid, userData, function(err) {
|
||||
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
db.setObjectField('username:uid', userData.username, uid);
|
||||
db.setObjectField('userslug:uid', userData.userslug, uid);
|
||||
|
||||
if (userData.email !== undefined) {
|
||||
db.setObjectField('email:uid', userData.email, uid);
|
||||
if (parseInt(uid, 10) !== 1) {
|
||||
User.email.verify(uid, userData.email);
|
||||
}
|
||||
}
|
||||
|
||||
plugins.fireHook('action:user.create', userData);
|
||||
db.incrObjectField('global', 'userCount');
|
||||
|
||||
db.sortedSetAdd('users:joindate', timestamp, uid);
|
||||
db.sortedSetAdd('users:postcount', 0, uid);
|
||||
db.sortedSetAdd('users:reputation', 0, uid);
|
||||
|
||||
groups.joinByGroupName('registered-users', uid);
|
||||
|
||||
if (password) {
|
||||
User.hashPassword(password, function(err, hash) {
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
User.setUserField(uid, 'password', hash);
|
||||
callback(null, uid);
|
||||
});
|
||||
} else {
|
||||
callback(null, uid);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
};
|
Loading…
Reference in New Issue