mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
feat: allowed plugins to modify email verification details prior to db saving or email send/plugin fire
+ new hook `filter:user.verify` - hook `filter:user.verify.code`
This commit is contained in:
@@ -28,6 +28,12 @@ Hooks._deprecated = new Map([
|
|||||||
since: 'v1.19.6',
|
since: 'v1.19.6',
|
||||||
until: 'v2.1.0',
|
until: 'v2.1.0',
|
||||||
}],
|
}],
|
||||||
|
['filter:user.verify.code', {
|
||||||
|
new: 'filter:user.verify',
|
||||||
|
since: 'v2.2.0',
|
||||||
|
until: 'v3.0.0',
|
||||||
|
affected: new Set(),
|
||||||
|
}],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
Hooks.internals = {
|
Hooks.internals = {
|
||||||
|
|||||||
@@ -68,6 +68,7 @@ UserEmail.sendValidationEmail = async function (uid, options) {
|
|||||||
* Options:
|
* Options:
|
||||||
* - email, overrides email retrieval
|
* - email, overrides email retrieval
|
||||||
* - force, sends email even if it is too soon to send another
|
* - force, sends email even if it is too soon to send another
|
||||||
|
* - template, changes the template used for email sending
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (meta.config.sendValidationEmail !== 1) {
|
if (meta.config.sendValidationEmail !== 1) {
|
||||||
@@ -84,7 +85,7 @@ UserEmail.sendValidationEmail = async function (uid, options) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
let confirm_code = utils.generateUUID();
|
const confirm_code = utils.generateUUID();
|
||||||
const confirm_link = `${nconf.get('url')}/confirm/${confirm_code}`;
|
const confirm_link = `${nconf.get('url')}/confirm/${confirm_code}`;
|
||||||
|
|
||||||
const emailInterval = meta.config.emailConfirmInterval;
|
const emailInterval = meta.config.emailConfirmInterval;
|
||||||
@@ -104,17 +105,27 @@ UserEmail.sendValidationEmail = async function (uid, options) {
|
|||||||
throw new Error(`[[error:confirm-email-already-sent, ${emailInterval}]]`);
|
throw new Error(`[[error:confirm-email-already-sent, ${emailInterval}]]`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const username = await user.getUserField(uid, 'username');
|
||||||
|
const data = await plugins.hooks.fire('filter:user.verify', {
|
||||||
|
uid,
|
||||||
|
username,
|
||||||
|
confirm_link,
|
||||||
|
confirm_code: await plugins.hooks.fire('filter:user.verify.code', confirm_code),
|
||||||
|
email: options.email,
|
||||||
|
|
||||||
|
subject: options.subject || '[[email:email.verify-your-email.subject]]',
|
||||||
|
template: options.template || 'verify-email',
|
||||||
|
});
|
||||||
|
|
||||||
await UserEmail.expireValidation(uid);
|
await UserEmail.expireValidation(uid);
|
||||||
await db.set(`confirm:byUid:${uid}`, confirm_code);
|
await db.set(`confirm:byUid:${uid}`, confirm_code);
|
||||||
await db.pexpireAt(`confirm:byUid:${uid}`, Date.now() + (emailInterval * 60 * 1000));
|
await db.pexpireAt(`confirm:byUid:${uid}`, Date.now() + (emailInterval * 60 * 1000));
|
||||||
confirm_code = await plugins.hooks.fire('filter:user.verify.code', confirm_code);
|
|
||||||
|
|
||||||
await db.setObject(`confirm:${confirm_code}`, {
|
await db.setObject(`confirm:${confirm_code}`, {
|
||||||
email: options.email.toLowerCase(),
|
email: options.email.toLowerCase(),
|
||||||
uid: uid,
|
uid: uid,
|
||||||
});
|
});
|
||||||
await db.expireAt(`confirm:${confirm_code}`, Math.floor((Date.now() / 1000) + (60 * 60 * 24)));
|
await db.expireAt(`confirm:${confirm_code}`, Math.floor((Date.now() / 1000) + (60 * 60 * 24)));
|
||||||
const username = await user.getUserField(uid, 'username');
|
|
||||||
|
|
||||||
winston.verbose(`[user/email] Validation email for uid ${uid} sent to ${options.email}`);
|
winston.verbose(`[user/email] Validation email for uid ${uid} sent to ${options.email}`);
|
||||||
events.log({
|
events.log({
|
||||||
@@ -124,17 +135,6 @@ UserEmail.sendValidationEmail = async function (uid, options) {
|
|||||||
...options,
|
...options,
|
||||||
});
|
});
|
||||||
|
|
||||||
const data = {
|
|
||||||
uid,
|
|
||||||
username,
|
|
||||||
confirm_link,
|
|
||||||
confirm_code,
|
|
||||||
email: options.email,
|
|
||||||
|
|
||||||
subject: options.subject || '[[email:email.verify-your-email.subject]]',
|
|
||||||
template: options.template || 'verify-email',
|
|
||||||
};
|
|
||||||
|
|
||||||
if (plugins.hooks.hasListeners('action:user.verify')) {
|
if (plugins.hooks.hasListeners('action:user.verify')) {
|
||||||
plugins.hooks.fire('action:user.verify', { uid: uid, data: data });
|
plugins.hooks.fire('action:user.verify', { uid: uid, data: data });
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user