toggle registration

This commit is contained in:
Erik 2022-11-14 12:43:19 +02:00
parent 1fe34ef31d
commit 7f8ba13672
Signed by: Navy.gif
GPG Key ID: 811EC0CD80E7E5FB

View File

@ -13,16 +13,20 @@ class RegisterEndpoint extends ApiEndpoint {
[ 'post', this.register.bind(this), [ this.notLoggedIn.bind(this) ]] [ 'post', this.register.bind(this), [ this.notLoggedIn.bind(this) ]]
]; ];
this.subpaths = [ this.subpaths = [
[ '/finalise', 'post', this.finaliseRegistration.bind(this), [ this.loggedIn.bind(this) ]] [ '/finalise', 'post', this.finaliseRegistration.bind(this), [ this.loggedIn.bind(this) ]],
[ '/toggle', 'post', this.toggleRegistration.bind(this), [ server.authenticator.createAuthoriser('administrator', 5) ]]
]; ];
this.middleware = [ ]; this.middleware = [ ];
this.userdb = server.userDatabase; this.userdb = server.userDatabase;
this.registrationEnabled = server.registrationEnabled || false;
} }
async register (req, res) { async register (req, res) {
if (!this.registrationEnabled) return res.status(403).send('Registration is disabled at this time');
const { body } = req; const { body } = req;
if (!body) return res.status(400).send('Missing body'); if (!body) return res.status(400).send('Missing body');
const { username, password } = body; const { username, password } = body;
@ -37,6 +41,14 @@ class RegisterEndpoint extends ApiEndpoint {
} }
toggleRegistration (req, res) {
const { body } = req;
const { value } = body;
if (typeof value !== 'boolean') return res.status(400).end();
this.registrationEnabled = value;
res.end();
}
async finaliseRegistration (req, res) { async finaliseRegistration (req, res) {
if (!req.user.temporary) return res.status(400).send('Account already finalised'); if (!req.user.temporary) return res.status(400).send('Account already finalised');