Fix a bug checking the validity of invite codes

merge-requests/26/head
knotteye 2020-10-13 16:29:13 -05:00
parent acce235812
commit 1a410a597a
1 changed files with 12 additions and 10 deletions

View File

@ -225,18 +225,20 @@ async function initAPI() {
}); });
app.post('/api/register', (req, res) => { app.post('/api/register', (req, res) => {
if("invite" in req.body){ if("invite" in req.body){
if(api.validInvite(req.body.invite)){ api.validInvite(req.body.invite).then((v) => {
api.register(req.body.username, req.body.password, req.body.confirm, true).then((result) => { if(v){
if(result[0]) return genToken(req.body.username).then((t) => { api.register(req.body.username, req.body.password, req.body.confirm, true).then((result) => {
res.cookie('Authorization', t, {maxAge: 604800000, httpOnly: true, sameSite: 'Lax'}); if(result[0]) return genToken(req.body.username).then((t) => {
res.cookie('Authorization', t, {maxAge: 604800000, httpOnly: true, sameSite: 'Lax'});
res.json(result);
api.useInvite(req.body.invite);
return;
});
res.json(result); res.json(result);
api.useInvite(req.body.invite);
return;
}); });
res.json(result); }
}); else res.json({error: "invalid invite code"});
} });
else res.json({error: "invalid invite code"});
} }
else else
api.register(req.body.username, req.body.password, req.body.confirm).then( (result) => { api.register(req.body.username, req.body.password, req.body.confirm).then( (result) => {