gpt4 book ai didi

javascript - 解析服务器 server.js 邮件适配器中的用户字段为空

转载 作者:搜寻专家 更新时间:2023-10-31 23:40:09 25 4
gpt4 key购买 nike

我使用 parse-server-amazon-ses-email-adapter并想知道如何本地化验证电子邮件和重置密码电子邮件。

我的线索是检查用户的字段,然后在 server.jsAmazonSESAdapter.js 上分配正确的模板。问题是用户属性为空,除了电子邮件、用户名。

例如,在下面的示例中,firstName 是未定义的。

谢谢。

emailAdapter: {
module: 'parse-server-amazon-ses-email-adapter',
options: {
// The address that your emails come from
fromAddress: 'Iron rr',
accessKeyId: 'gg',
secretAccessKey: 'gg',
region: 'eu-west-1',
// The template section
templates: {
passwordResetEmail: {
subject: 'Redefinir sua senha Iron Trainers',
pathPlainText: '/opt/bitnami/apps/parse/htdocs/node_modules/parse-server/node_modules/parse-server-amazon-ses-email-adapter/test/email-templates/password_reset_email.txt',
pathHtml: '/opt/bitnami/apps/parse/htdocs/node_modules/parse-server/node_modules/parse-server-amazon-ses-email-adapter/test/email-templates/password_reset_email.html',
callback: (user) => {
return {
firstName: user.get('firstName')
}
}
// Now you can use {{firstName}} in your templates
},
verificationEmail: {
subject: 'Confirmar email no Iron Trainers',
pathPlainText: '/opt/bitnami/apps/parse/htdocs/node_modules/parse-server/node_modules/parse-server-amazon-ses-email-adapter/test/email-templates/verification_email.txt',
pathHtml: '/opt/bitnami/apps/parse/htdocs/node_modules/parse-server/node_modules/parse-server-amazon-ses-email-adapter/test/email-templates/resendEmailVerification.html',
callback: (user) => {
return {
firstName: user.get('firstName')
}
}
// Now you can use {{firstName}} in your templates
},
customEmailAlert: {
subject: 'Urgent notification!',
pathPlainText: '/opt/bitnami/apps/parse/htdocs/node_modules/parse-server/node_modules/parse-server-amazon-ses-email-adapter/test/email-templates/custom_alert.txt',
pathHtml: '/opt/bitnami/apps/parse/htdocs/node_modules/parse-server/node_modules/parse-server-amazon-ses-email-adapter/test/email-templates/custom_alert.html',
}
}

最佳答案

据我所知,这可以通过插件中的代码更改来完成。

在代码的下面一行有一个if-else条件

https://github.com/ecohealthalliance/parse-server-amazon-ses-email-adapter/blob/0bce9b6c81681c3829a17b208d839d23c846ab05/src/AmazonSESAdapter.js#L90

因为你没有提供任何反馈,我也没有办法设置它,我假设 else 部分是被执行的部分

  const {
link,
appName,
user,
templateConfig
} = options;
const {
callback
} = templateConfig;
let userVars;

if (callback && typeof callback === 'function') {
userVars = callback(user);
// If custom user variables are not packaged in an object, ignore it
const validUserVars = userVars && userVars.constructor && userVars.constructor.name === 'Object';
userVars = validUserVars ? userVars : {};
}

pathPlainText = templateConfig.pathPlainText;
pathHtml = templateConfig.pathHtml;

templateVars = Object.assign({
link,
appName,
username: user.get('username'),
email: user.get('email')
}, userVars);

message = {
from: this.fromAddress,
to: user.get('email'),
subject: templateConfig.subject
};
}

现在在这部分,2行决定要使用的模板

pathPlainText = templateConfig.pathPlainText;
pathHtml = templateConfig.pathHtml;

此时,您提供的回调已经被调用。现在在回调中你可以设置一个变量,假设它是名称 locale。所以你可以像下面这样更新代码

pathPlainText = templateConfig.pathPlainText + (userVars["locale"] || "en");
pathHtml = templateConfig.pathHtml + (userVars["locale"] || "en");

然后您将创建文件路径中包含 locale 的模板,并使用更新的代码选择正确的模板。

您也可以查看@bgran 答案,乍一看我确实认为它也应该有效

关于javascript - 解析服务器 server.js 邮件适配器中的用户字段为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50010212/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com