meteor - 困惑如何自定义流星验证邮件
问题描述
如何将验证链接从默认 Meteor 方法获取到我拥有的使用 sendgrid stmp 的自定义电子邮件方法中。
这是流星验证方法,它本身运行良好,并且有我想要的链接:
sendVerificationLink() {
let userId = Meteor.userId();
if ( userId ) {
return Accounts.sendVerificationEmail( userId );
}
},
这是我使用 sendgrid 的自定义方法,除了我无法弄清楚如何使用自定义令牌获取链接之外,一切正常:
'signupEmail' (submission) {
this.unblock();
const link = ''
const message = `welcome ${submission.firstname} `
const text = `welcome ${submission.firstname}. Please verify your
account ${link}`
Email.send({
from: "hi@test.com",
to: submission.email,
subject: message,
text: text,
html: text,
});
}
解决方案
以防万一将来有人在寻找这个,我在 Meteor 论坛上找到了答案: https ://forums.meteor.com/t/how-to-get-verification-link-for-custom-sent-verification-email /22932/2
基本上我添加了一个令牌记录并将其保存在数据库中。然后将令牌与方法一起使用:Accounts.urls.verifyEmail 创建了要插入电子邮件的链接。
这是我的最终方法:
'signupEmail' (submission) {
this.unblock();
let userId = Meteor.userId();
var tokenRecord = {
token: Random.secret(),
address: submission.email,
when: new Date()};
Meteor.users.update(
{_id: userId},
{$push: {'services.email.verificationTokens': tokenRecord}}
);
const verifyEmailUrl = Accounts.urls.verifyEmail(tokenRecord.token);
const message = `welcome ${submission.firstname} `
const text = `welcome ${submission.firstname}. Please verify your account ${verifyEmailUrl}`
Email.send({
from: "hi@test.com",
to: submission.email,
subject: message,
text: text,
html: text,
});
},
推荐阅读
- reactjs - ReactJS 和 Redux 工具包:我可以使用“createAsyncThunk()”来执行非异步副作用吗?
- docker - docker坚持使用代理
- r - 当数据集是每月时,如何计算 Quarter Over Quarter %change
- github-actions - Github 操作会忽略 bash.sh 脚本中定义的所有环境变量
- xcode - Unity Firebase + AdMob 冲突 (GoogleAppMeasurement)
- reactjs - 我收到一条错误消息“未定义没有属性”,但不明白问题出在哪里
- c# - 使用 c#.net 可以使用控制台应用程序打开 excel 工作簿,但不能使用 Windows 窗体应用程序
- java - 为什么 Throwable.getCause 在返回 `null` 之前检查“原因”是否为“this”,而不是直接返回原因?
- python - Python Selenium 有时点击,有时不点击
- python - 当行长于所选索引时,我遇到了 IndexError: list index out of range