流星:如何仅获取帐户密码重置令牌,没有电子邮件
Meteor: How to get account password reset token only, no email
我希望使用 sendgrid 模板发送帐户密码重置电子邮件。
所以基本上不用函数 Accounts.sendResetPasswordEmail
我需要函数 Accounts.getResetPasswordURL
这会给我一个密码重置 URL,我可以用它发送到将在模板中使用的 sendgrid。
那我该怎么做呢?我如何使用 Meteor 来重置密码 URL 而不是实际发送电子邮件?我将使用 API 调用 sendgrid 手动发送带有 URL 的电子邮件。
目前执行程序的方式实际上不可能做到这一点。
accounts-password
包生成一个随机令牌并在 sendResetPasswordEmail()
方法中发送电子邮件。
您可以分叉包,按照完成的方式生成您自己的令牌in the original method, or change the behavior of the email包来自行处理电子邮件。
注意:我没有用过sendgrid,所以我按API over here。
首先,您要配置 Meteor 以使用 Sendgrid's SMTP servers。这样,您可以直接通过 Meteor 发送电子邮件:
Meteor.startup(function(){
process.env.MAIL_URL = "smtp://" + sendgridUsername + ":" + sendgridPasswordOrAPIkey + "@smtp.sendgrid.net:465";
});
您可以更改重置电子邮件的默认模板。这可以通过修改 Accounts.emailTemplates
:
来完成
Accounts.emailTemplates.resetPassword.html = function(user, url){
// url contains the reset url! :)
var result;
var sendgridTemplateId = ''; // Set this to the template id you're using in sendgrid
try {
// Get sendgrid template
// API link: https://sendgrid.com/docs/API_Reference/Web_API_v3/Template_Engine/templates.html
result = HTTP.get("https://api.sendgrid.com/v3/templates/" + sendgridTemplateId);
result = result.data.templates[0].versions[0].html_content;
// then insert URL to the template
} catch (error) {
console.error('Error while fetching sendgrid template!', error);
return false;
}
return result;
};
现在,当您使用 Accounts.sendResetPasswordEmail()
时,将使用上面的模板,它实际上只是获取 sendgrid 模板和 returns 那!
我希望使用 sendgrid 模板发送帐户密码重置电子邮件。
所以基本上不用函数 Accounts.sendResetPasswordEmail
我需要函数 Accounts.getResetPasswordURL
这会给我一个密码重置 URL,我可以用它发送到将在模板中使用的 sendgrid。
那我该怎么做呢?我如何使用 Meteor 来重置密码 URL 而不是实际发送电子邮件?我将使用 API 调用 sendgrid 手动发送带有 URL 的电子邮件。
目前执行程序的方式实际上不可能做到这一点。
accounts-password
包生成一个随机令牌并在 sendResetPasswordEmail()
方法中发送电子邮件。
您可以分叉包,按照完成的方式生成您自己的令牌in the original method, or change the behavior of the email包来自行处理电子邮件。
注意:我没有用过sendgrid,所以我按API over here。
首先,您要配置 Meteor 以使用 Sendgrid's SMTP servers。这样,您可以直接通过 Meteor 发送电子邮件:
Meteor.startup(function(){
process.env.MAIL_URL = "smtp://" + sendgridUsername + ":" + sendgridPasswordOrAPIkey + "@smtp.sendgrid.net:465";
});
您可以更改重置电子邮件的默认模板。这可以通过修改 Accounts.emailTemplates
:
Accounts.emailTemplates.resetPassword.html = function(user, url){
// url contains the reset url! :)
var result;
var sendgridTemplateId = ''; // Set this to the template id you're using in sendgrid
try {
// Get sendgrid template
// API link: https://sendgrid.com/docs/API_Reference/Web_API_v3/Template_Engine/templates.html
result = HTTP.get("https://api.sendgrid.com/v3/templates/" + sendgridTemplateId);
result = result.data.templates[0].versions[0].html_content;
// then insert URL to the template
} catch (error) {
console.error('Error while fetching sendgrid template!', error);
return false;
}
return result;
};
现在,当您使用 Accounts.sendResetPasswordEmail()
时,将使用上面的模板,它实际上只是获取 sendgrid 模板和 returns 那!