Added admin-only invites

v1.18.x
Peter Jaszkowiak 9 years ago
parent af8e649246
commit 67905667a9

@ -108,7 +108,7 @@ Controllers.register = function(req, res, next) {
async.waterfall([
function(next) {
if (registrationType === 'invite-only') {
if (registrationType === 'invite-only' || registrationType === 'admin-invite-only') {
user.verifyInvitation(req.query, next);
} else {
next();

@ -155,9 +155,11 @@ function render(req, res, data, next) {
return next(err);
}
if (!req.uid) {
return next(new Error('[[error:no-privileges]]'));
}
var registrationType = meta.config.registrationType;
data.templateData.maximumInvites = meta.config.maximumInvites;
data.templateData.inviteOnly = registrationType === 'invite-only' || registrationType === 'admin-invite-only';
data.templateData['reputation:disabled'] = parseInt(meta.config['reputation:disabled'], 10) === 1;
user.getInvitesNumber(req.uid, function(err, num) {
if (err) {
@ -165,11 +167,9 @@ function render(req, res, data, next) {
}
data.templateData.invites = num;
data.templateData.maximumInvites = meta.config.maximumInvites;
data.templateData.inviteOnly = meta.config.registrationType === 'invite-only';
data.templateData['reputation:disabled'] = parseInt(meta.config['reputation:disabled'], 10) === 1;
res.render('users', data.templateData);
});
});
}

@ -270,36 +270,41 @@ SocketUser.invite = function(socket, email, callback) {
return callback(new Error('[[error:invalid-data]]'));
}
if (meta.config.registrationType !== 'invite-only') {
var registrationType = meta.config.registrationType
if (registrationType !== 'invite-only' && registrationType !== 'admin-invite-only') {
return callback(new Error('[[error:forum-not-invite-only]]'));
}
var max = meta.config.maximumInvites;
if (max) {
async.waterfall([
function(next) {
user.getInvitesNumber(socket.uid, next);
},
function(invites, next) {
user.isAdministrator(socket.uid, function(err, admin) {
next(err, invites, admin);
});
},
function(invites, admin, next) {
console.log(admin, invites, max);
if (!admin && invites > max) {
return next(new Error('[[error:invite-maximum-met, ' + invites + ', ' + max + ']]'));
user.isAdministrator(socket.uid, function(err, admin) {
if (err) {
return callback(err);
}
if (registrationType === 'admin-invite-only' && !admin) {
return callback(new Error('[[error:no-privileges]]'));
}
if (max) {
async.waterfall([
function(next) {
user.getInvitesNumber(socket.uid, next);
},
function(invites, next) {
if (!admin && invites > max) {
return next(new Error('[[error:invite-maximum-met, ' + invites + ', ' + max + ']]'));
}
next();
},
function(next) {
user.sendInvitationEmail(socket.uid, email, next);
}
next();
},
function(next) {
user.sendInvitationEmail(socket.uid, email, next);
}
], callback);
} else {
user.sendInvitationEmail(socket.uid, email, callback);
}
], callback);
} else {
user.sendInvitationEmail(socket.uid, email, callback);
}
});
};

@ -33,6 +33,7 @@
<option value="normal">Normal</option>
<option value="admin-approval">Admin Approval</option>
<option value="invite-only">Invite Only</option>
<option value="admin-invite-only">Admin Invite Only</option>
<option value="disabled">No registration</option>
</select>
</div>

Loading…
Cancel
Save