Configurable registration only by invite.

This commit is contained in:
Adrian Winterstein 2024-09-28 16:23:04 +02:00
parent c5e5e3bb71
commit 1d843af3cd
No known key found for this signature in database
GPG key ID: EDBA4B9F8D8E37AE
2 changed files with 10 additions and 1 deletions

View file

@ -28,6 +28,7 @@
"GOOGLE_CLIENT_SECRET": "aaaabbbbccccddddeeeeffff00001111",
"IAP_GOOGLE_KEYDIR": "/path/to/google/public/key/dir/",
"IGNORE_REDIRECT": "true",
"INVITE_ONLY": "true",
"ITUNES_SHARED_SECRET": "aaaabbbbccccddddeeeeffff00001111",
"LOGGLY_CLIENT_TOKEN": "token",
"LOGGLY_SUBDOMAIN": "example-subdomain",

View file

@ -18,7 +18,9 @@ import {
} from './social';
import { loginRes } from './utils';
import { verifyUsername } from '../user/validation';
import nconf from 'nconf';
const INVITE_ONLY = nconf.get('INVITE_ONLY') === 'true';
const USERNAME_LENGTH_MIN = 1;
const USERNAME_LENGTH_MAX = 20;
@ -60,7 +62,9 @@ async function _handleGroupInvitation (user, invite) {
}
} catch (err) {
logger.error(err);
return false;
}
return true;
}
function hasLocalAuth (user) {
@ -191,7 +195,11 @@ async function registerLocal (req, res, { isV3 = false }) {
// we check for partyInvite for backward compatibility
if (req.query.groupInvite || req.query.partyInvite) {
await _handleGroupInvitation(newUser, req.query.groupInvite || req.query.partyInvite);
const success = await _handleGroupInvitation(newUser, req.query.groupInvite || req.query.partyInvite);
if (INVITE_ONLY && !success)
throw new NotAuthorized(res.t('inviteOnly'));
} else if (INVITE_ONLY) {
throw new NotAuthorized(res.t('inviteOnly'));
}
const savedUser = await newUser.save();