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([ async.waterfall([
function(next) { function(next) {
if (registrationType === 'invite-only') { if (registrationType === 'invite-only' || registrationType === 'admin-invite-only') {
user.verifyInvitation(req.query, next); user.verifyInvitation(req.query, next);
} else { } else {
next(); next();

@ -155,9 +155,11 @@ function render(req, res, data, next) {
return next(err); return next(err);
} }
if (!req.uid) { var registrationType = meta.config.registrationType;
return next(new Error('[[error:no-privileges]]'));
} 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) { user.getInvitesNumber(req.uid, function(err, num) {
if (err) { if (err) {
@ -165,11 +167,9 @@ function render(req, res, data, next) {
} }
data.templateData.invites = num; 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); res.render('users', data.templateData);
}); });
}); });
} }

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

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

Loading…
Cancel
Save