toggle registration
This commit is contained in:
parent
1fe34ef31d
commit
7f8ba13672
@ -13,16 +13,20 @@ class RegisterEndpoint extends ApiEndpoint {
|
||||
[ 'post', this.register.bind(this), [ this.notLoggedIn.bind(this) ]]
|
||||
];
|
||||
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.userdb = server.userDatabase;
|
||||
this.registrationEnabled = server.registrationEnabled || false;
|
||||
|
||||
}
|
||||
|
||||
async register (req, res) {
|
||||
|
||||
if (!this.registrationEnabled) return res.status(403).send('Registration is disabled at this time');
|
||||
|
||||
const { body } = req;
|
||||
if (!body) return res.status(400).send('Missing 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) {
|
||||
|
||||
if (!req.user.temporary) return res.status(400).send('Account already finalised');
|
||||
|
Loading…
Reference in New Issue
Block a user