mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-21 15:20:34 +00:00
fix(server): should allowed email addresses and domain be irrespective.
This commit is contained in:
@@ -277,30 +277,18 @@ export default class AuthenticationController extends BaseController {
|
|||||||
],
|
],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (error.errorType === 'SIGNUP_NOT_ALLOWED_EMAIL_DOMAIN') {
|
if (error.errorType === 'SIGNUP_RESTRICTED_NOT_ALLOWED') {
|
||||||
return res.status(400).send({
|
return res.status(400).send({
|
||||||
errors: [
|
errors: [
|
||||||
{
|
{
|
||||||
type: 'SIGNUP_NOT_ALLOWED_EMAIL_DOMAIN',
|
type: 'SIGNUP_RESTRICTED_NOT_ALLOWED',
|
||||||
message:
|
message:
|
||||||
'Sign-up is restricted the given email domain is not allowed to sign-up.',
|
'Sign-up is restricted the given email address is not allowed to sign-up.',
|
||||||
code: 710,
|
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);
|
next(error);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -87,30 +87,24 @@ export class AuthSignupService {
|
|||||||
// Can't continue if the signup is not disabled.
|
// Can't continue if the signup is not disabled.
|
||||||
if (!config.signupRestrictions.disabled) return;
|
if (!config.signupRestrictions.disabled) return;
|
||||||
|
|
||||||
// Validate the allowed domains.
|
// Validate the allowed email addresses and domains.
|
||||||
if (!isEmpty(config.signupRestrictions.allowedDomains)) {
|
if (
|
||||||
|
!isEmpty(config.signupRestrictions.allowedEmails) ||
|
||||||
|
!isEmpty(config.signupRestrictions.allowedDomains)
|
||||||
|
) {
|
||||||
const emailDomain = email.split('@').pop();
|
const emailDomain = email.split('@').pop();
|
||||||
const isAllowed = config.signupRestrictions.allowedDomains.some(
|
const isAllowedEmail =
|
||||||
(domain) => emailDomain === domain
|
|
||||||
);
|
|
||||||
if (!isAllowed) {
|
|
||||||
throw new ServiceError(ERRORS.SIGNUP_NOT_ALLOWED_EMAIL_DOMAIN);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Validate the allowed email addresses.
|
|
||||||
if (!isEmpty(config.signupRestrictions.allowedEmails)) {
|
|
||||||
const isAllowed =
|
|
||||||
config.signupRestrictions.allowedEmails.indexOf(email) !== -1;
|
config.signupRestrictions.allowedEmails.indexOf(email) !== -1;
|
||||||
|
|
||||||
if (!isAllowed) {
|
const isAllowedDomain = config.signupRestrictions.allowedDomains.some(
|
||||||
throw new ServiceError(ERRORS.SIGNUP_NOT_ALLOWED_EMAIL_ADDRESS);
|
(domain) => emailDomain === domain
|
||||||
}
|
);
|
||||||
|
|
||||||
|
if (!isAllowedEmail && !isAllowedDomain) {
|
||||||
|
throw new ServiceError(ERRORS.SIGNUP_RESTRICTED_NOT_ALLOWED);
|
||||||
}
|
}
|
||||||
// Throw error if the signup is disabled with no exceptions.
|
// Throw error if the signup is disabled with no exceptions.
|
||||||
if (
|
} else {
|
||||||
isEmpty(config.signupRestrictions.allowedDomains) &&
|
|
||||||
isEmpty(config.signupRestrictions.allowedEmails)
|
|
||||||
) {
|
|
||||||
throw new ServiceError(ERRORS.SIGNUP_RESTRICTED);
|
throw new ServiceError(ERRORS.SIGNUP_RESTRICTED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,8 +7,6 @@ export const ERRORS = {
|
|||||||
TOKEN_EXPIRED: 'TOKEN_EXPIRED',
|
TOKEN_EXPIRED: 'TOKEN_EXPIRED',
|
||||||
PHONE_NUMBER_EXISTS: 'PHONE_NUMBER_EXISTS',
|
PHONE_NUMBER_EXISTS: 'PHONE_NUMBER_EXISTS',
|
||||||
EMAIL_EXISTS: 'EMAIL_EXISTS',
|
EMAIL_EXISTS: 'EMAIL_EXISTS',
|
||||||
|
SIGNUP_RESTRICTED_NOT_ALLOWED: 'SIGNUP_RESTRICTED_NOT_ALLOWED',
|
||||||
SIGNUP_NOT_ALLOWED_EMAIL_ADDRESS: 'SIGNUP_NOT_ALLOWED_EMAIL_ADDRESS',
|
|
||||||
SIGNUP_NOT_ALLOWED_EMAIL_DOMAIN: 'SIGNUP_NOT_ALLOWED_EMAIL_DOMAIN',
|
|
||||||
SIGNUP_RESTRICTED: 'SIGNUP_RESTRICTED',
|
SIGNUP_RESTRICTED: 'SIGNUP_RESTRICTED',
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user