2019-01-29 13:11:45 -05:00
|
|
|
'use strict';
|
|
|
|
|
|
2019-09-15 02:14:51 -04:00
|
|
|
const user = require('../../user');
|
|
|
|
|
const events = require('../../events');
|
2019-01-29 13:11:45 -05:00
|
|
|
|
|
|
|
|
module.exports = function (SocketUser) {
|
2019-09-15 02:14:51 -04:00
|
|
|
SocketUser.acceptRegistration = async function (socket, data) {
|
|
|
|
|
const isAdminOrGlobalMod = await user.isAdminOrGlobalMod(socket.uid);
|
|
|
|
|
if (!isAdminOrGlobalMod) {
|
|
|
|
|
throw new Error('[[error:no-privileges]]');
|
|
|
|
|
}
|
|
|
|
|
const uid = await user.acceptRegistration(data.username);
|
|
|
|
|
await events.log({
|
|
|
|
|
type: 'registration-approved',
|
|
|
|
|
uid: socket.uid,
|
|
|
|
|
ip: socket.ip,
|
|
|
|
|
targetUid: uid,
|
|
|
|
|
});
|
|
|
|
|
return uid;
|
2019-01-29 13:11:45 -05:00
|
|
|
};
|
|
|
|
|
|
2019-09-15 02:14:51 -04:00
|
|
|
SocketUser.rejectRegistration = async function (socket, data) {
|
|
|
|
|
const isAdminOrGlobalMod = await user.isAdminOrGlobalMod(socket.uid);
|
|
|
|
|
if (!isAdminOrGlobalMod) {
|
|
|
|
|
throw new Error('[[error:no-privileges]]');
|
|
|
|
|
}
|
|
|
|
|
await user.rejectRegistration(data.username);
|
|
|
|
|
await events.log({
|
|
|
|
|
type: 'registration-rejected',
|
|
|
|
|
uid: socket.uid,
|
|
|
|
|
ip: socket.ip,
|
|
|
|
|
username: data.username,
|
|
|
|
|
});
|
2019-01-29 13:11:45 -05:00
|
|
|
};
|
|
|
|
|
|
2019-09-15 02:14:51 -04:00
|
|
|
SocketUser.deleteInvitation = async function (socket, data) {
|
|
|
|
|
const isAdminOrGlobalMod = await user.isAdminOrGlobalMod(socket.uid);
|
|
|
|
|
if (!isAdminOrGlobalMod) {
|
|
|
|
|
throw new Error('[[error:no-privileges]]');
|
|
|
|
|
}
|
|
|
|
|
await user.deleteInvitation(data.invitedBy, data.email);
|
2019-01-29 13:11:45 -05:00
|
|
|
};
|
|
|
|
|
};
|