mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 15:48:04 +01:00
add blocker to block emails from registration
This commit is contained in:
@@ -9,9 +9,31 @@ import { schema as SubscriptionPlanSchema } from '../subscriptionPlan';
|
||||
import { schema as TagSchema } from '../tag';
|
||||
import { schema as UserNotificationSchema } from '../userNotification';
|
||||
import { schema as WebhookSchema } from '../webhook';
|
||||
import { model as Blocker } from '../blocker';
|
||||
|
||||
const RESTRICTED_EMAIL_DOMAINS = Object.freeze(['habitica.com', 'habitrpg.com']);
|
||||
|
||||
const BLOCKED_EMAILS = [];
|
||||
|
||||
Blocker.watchBlockers({
|
||||
type: 'email',
|
||||
area: 'full',
|
||||
}, {
|
||||
initial: true,
|
||||
}).on('change', async change => {
|
||||
const { operation, blocker: { value } } = change;
|
||||
if (operation === 'add') {
|
||||
if (value && !BLOCKED_EMAILS.includes(value)) {
|
||||
BLOCKED_EMAILS.push(value);
|
||||
}
|
||||
} else if (operation === 'delete') {
|
||||
const index = BLOCKED_EMAILS.indexOf(value);
|
||||
if (index !== -1) {
|
||||
BLOCKED_EMAILS.splice(index, 1);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// User schema definition
|
||||
export const UserSchema = new Schema({
|
||||
apiToken: {
|
||||
@@ -43,6 +65,12 @@ export const UserSchema = new Schema({
|
||||
return RESTRICTED_EMAIL_DOMAINS.every(domain => !lowercaseEmail.endsWith(`@${domain}`));
|
||||
},
|
||||
message: shared.i18n.t('invalidEmailDomain', { domains: RESTRICTED_EMAIL_DOMAINS.join(', ') }),
|
||||
}, {
|
||||
validator (email) {
|
||||
const lowercaseEmail = email.toLowerCase();
|
||||
return BLOCKED_EMAILS.every(block => lowercaseEmail.indexOf(block) === -1);
|
||||
},
|
||||
message: shared.i18n.t('emailBlockedRegistration'),
|
||||
}],
|
||||
},
|
||||
username: {
|
||||
|
||||
Reference in New Issue
Block a user