feat(server): sign-up restrictions for self-hosted

This commit is contained in:
a.bouhuolia
2023-05-07 17:22:18 +02:00
parent 36611652da
commit ad3c9ebfe9
10 changed files with 171 additions and 4 deletions

View File

@@ -49,6 +49,7 @@ export default class AuthenticationController extends BaseController {
asyncMiddleware(this.resetPassword.bind(this)),
this.handlerErrors
);
router.get('/meta', asyncMiddleware(this.getAuthMeta.bind(this)));
return router;
}
@@ -207,6 +208,23 @@ export default class AuthenticationController extends BaseController {
}
}
/**
* Retrieves the authentication meta for SPA.
* @param {Request} req
* @param {Response} res
* @param {Function} next
* @returns {Response|void}
*/
private async getAuthMeta(req: Request, res: Response, next: Function) {
try {
const meta = await this.authApplication.getAuthMeta();
return res.status(200).send({ meta });
} catch (error) {
next(error);
}
}
/**
* Handles the service errors.
*/
@@ -247,6 +265,42 @@ export default class AuthenticationController extends BaseController {
errors: [{ type: 'EMAIL.EXISTS', code: 600 }],
});
}
if (error.errorType === 'SIGNUP_RESTRICTED') {
return res.status(400).send({
errors: [
{
type: 'SIGNUP_RESTRICTED',
message:
'Sign-up is restricted no one can sign-up to the system.',
code: 700,
},
],
});
}
if (error.errorType === 'SIGNUP_NOT_ALLOWED_EMAIL_DOMAIN') {
return res.status(400).send({
errors: [
{
type: 'SIGNUP_NOT_ALLOWED_EMAIL_DOMAIN',
message:
'Sign-up is restricted the given email domain is not allowed to sign-up.',
code: 710,
},
],
});
}
if (error.errorType === 'SIGNUP_NOT_ALLOWED_EMAIL_ADDRESS') {
return res.status(400).send({
errors: [
{
type: 'SIGNUP_NOT_ALLOWED_EMAIL_ADDRESS',
message:
'The sign-up restricted the given email address is not allowed to sign-up.',
code: 720,
},
],
});
}
}
next(error);
}