feat: new plugin hook to allow plugins to reject email address on new registration or email change

isekai-main
Julian Lam 3 years ago
parent 806a1e50d2
commit 6b4f35c2fa

@ -28,15 +28,22 @@ Interstitials.email = async (data) => {
callback: async (userData, formData) => { callback: async (userData, formData) => {
// Validate and send email confirmation // Validate and send email confirmation
if (userData.uid) { if (userData.uid) {
const [isAdminOrGlobalMod, canEdit, current] = await Promise.all([ const [isAdminOrGlobalMod, canEdit, current, { allowed, error }] = await Promise.all([
user.isAdminOrGlobalMod(data.req.uid), user.isAdminOrGlobalMod(data.req.uid),
privileges.users.canEdit(data.req.uid, userData.uid), privileges.users.canEdit(data.req.uid, userData.uid),
user.getUserField(userData.uid, 'email'), user.getUserField(userData.uid, 'email'),
plugins.hooks.fire('filter:user.saveEmail', {
uid: userData.uid,
email: formData.email,
registration: false,
allowed: true, // change this value to disallow
error: '[[error:invalid-email]]',
}),
]); ]);
if (formData.email && formData.email.length) { if (formData.email && formData.email.length) {
if (!utils.isEmailValid(formData.email)) { if (!allowed || !utils.isEmailValid(formData.email)) {
throw new Error('[[error:invalid-email]]'); throw new Error(error);
} }
if (formData.email === current) { if (formData.email === current) {
@ -68,8 +75,16 @@ Interstitials.email = async (data) => {
} }
} }
} else { } else {
if (meta.config.requireEmailAddress && !(formData.email && formData.email.length)) { const { allowed, error } = await plugins.hooks.fire('filter:user.saveEmail', {
throw new Error('[[error:invalid-email]]'); uid: null,
email: formData.email,
registration: true,
allowed: true, // change this value to disallow
error: '[[error:invalid-email]]',
});
if (!allowed || (meta.config.requireEmailAddress && !(formData.email && formData.email.length))) {
throw new Error(error);
} }
// New registrants have the confirm email sent from user.create() // New registrants have the confirm email sent from user.create()

Loading…
Cancel
Save