diff --git a/public/src/client/register.js b/public/src/client/register.js index d8144d26d5..5c6dbfb0d9 100644 --- a/public/src/client/register.js +++ b/public/src/client/register.js @@ -135,7 +135,7 @@ define('forum/register', [ if (results.every(obj => obj.status === 'rejected')) { showSuccess(usernameInput, username_notify, successIcon); } else { - showError(usernameInput, username_notify, '[[error:username-taken]]'); + showError(usernameInput, `Username is taken Maybe try "${username}suffix"`); } callback(); diff --git a/src/admin/manage/registration.js b/src/admin/manage/registration.js new file mode 100644 index 0000000000..537ac97535 --- /dev/null +++ b/src/admin/manage/registration.js @@ -0,0 +1,68 @@ +'use strict'; + +// Define a global `define` if it's not already defined +/* global define */ + +define(['jquery', 'socket', 'alerts', 'bootbox'], ($, socket, alerts, bootbox) => { + const Registration = {}; + + Registration.init = () => { + $('.users-list').on('click', '[data-action]', function () { + const parent = $(this).parents('[data-username]'); + const action = $(this).attr('data-action'); + const username = parent.attr('data-username'); + const method = action === 'accept' ? 'user.acceptRegistration' : 'user.rejectRegistration'; + + socket.emit(method, { username }, (err) => { + if (err) { + alerts.error(err); + } else { + parent.remove(); + } + }); + + return false; + }); + $('.invites-list').on('click', '[data-action]', function () { + const parent = $(this).parents('[data-invitation-mail][data-invited-by]'); + const email = parent.attr('data-invitation-mail'); + const invitedBy = parent.attr('data-invited-by'); + const action = $(this).attr('data-action'); + const method = 'user.deleteInvitation'; + + if (action === 'delete') { + bootbox.confirm('[[admin/manage/registration:invitations.confirm-delete]]', (confirm) => { + helper(confirm, email, invitedBy, method, () => { + const nextRow = parent.next(); + const thisRowInvitedBy = parent.find('.invited-by'); + const nextRowInvitedBy = nextRow.find('.invited-by'); + + if (nextRowInvitedBy.html() && nextRowInvitedBy.html().length < 2) { + nextRowInvitedBy.html(thisRowInvitedBy.html()); + } + + parent.remove(); + }); + }); + } + + return false; + }); + }; + + return Registration; +}); + +function helper(confirm, email, invitedBy, method, removeRow) { + if (confirm) { + require(['socket', 'alerts'], (socket, alerts) => { + socket.emit(method, { email, invitedBy }, (err) => { + if (err) { + alerts.error(err); + } else { + removeRow(); + } + }); + }); + } +} diff --git a/src/user/data.js b/src/user/data.js index d0940ff98e..ef5bae079d 100644 --- a/src/user/data.js +++ b/src/user/data.js @@ -15,7 +15,7 @@ const intFields = [ 'uid', 'postcount', 'topiccount', 'reputation', 'profileviews', 'banned', 'banned:expire', 'email:confirmed', 'joindate', 'lastonline', 'lastqueuetime', 'lastposttime', 'followingCount', 'followerCount', - 'blocksCount', 'passwordExpiry', 'mutedUntil', + 'blocksCount', 'passwordExpiry', 'mutedUntil', ]; module.exports = function (User) { @@ -25,7 +25,7 @@ module.exports = function (User) { 'aboutme', 'signature', 'uploadedpicture', 'profileviews', 'reputation', 'postcount', 'topiccount', 'lastposttime', 'banned', 'banned:expire', 'status', 'flags', 'followerCount', 'followingCount', 'cover:url', - 'cover:position', 'groupTitle', 'mutedUntil', 'mutedReason', + 'cover:position', 'groupTitle', 'mutedUntil', 'mutedReason', 'saved' ]; User.guestData = { @@ -367,4 +367,24 @@ module.exports = function (User) { plugins.hooks.fire('action:user.set', { uid: uid, field: field, value: newValue, type: type }); return newValue; } + + User.addSaved = async function (uid, value) { + const cleanValue = validator.escape(value ? value.toString() : ''); + let currentValues = await db.getObjectField(`user:${uid}`, field); + if (!currentValues) { + currentValues = []; + } else if (typeof currentValues === 'string') { + try { + currentValues = JSON.parse(currentValues); + } catch (err) { + currentValues = [currentValues]; + } + } + if (!Array.isArray(currentValues)) { + currentValues = [currentValues]; + } + currentValues.push(cleanValue); + await db.setObjectField(`user:${uid}`, field, JSON.stringify(currentValues)); + plugins.hooks.fire('action:user.set', { uid, field, value: cleanValue, type: 'append' }); + } };