如何更改meteor中的重置密码URL?

时间:2013-01-02 22:32:32

标签: javascript meteor

我正在使用meteor以及accounts-password包。我正在滚动我自己的登录名和密码更改/重置UI并想知道......

如何在Accounts.resetPassword发送的重置密码电子邮件中自定义密码重置链接?

目前它的形式如下:/#/reset-password/<id>'。由于我使用meteor router,我希望以'/reset-password/<id>'的形式发送,以便我可以使用路线'/reset-password/:id'来捕捉它。

3 个答案:

答案 0 :(得分:54)

晚会......

您可以使用以下命令更改网址,而不是更改整个文字。

Meteor.startup(function() {
 Accounts.urls.resetPassword = function(token) {
    return Meteor.absoluteUrl('reset-password/' + token);
  };
});

答案 1 :(得分:17)

它发生了一些变化:

你必须使用

Accounts.emailTemplates.resetPassword.text

对于url,您只需替换hashbang而不是从url解析令牌。作为一个例子(在coffeescript中):

Meteor.startup(() ->
  Accounts.emailTemplates.resetPassword.text = (user, url) ->
     url = url.replace('#/', '')
     return "Click this link to reset your password: " + url
)

ES6

Meteor.startup(() =>
  Accounts.emailTemplates.resetPassword.text = function(user, url) {
     url = url.replace('#/', '');
     return `Click this link to reset your password: ${url}`;
   }
);

答案 2 :(得分:7)

请参阅section on email templates in the Meteor docs

  

resetPassword:包含两个字段的对象:

     
      
  • resetPassword.subject:一个获取用户对象并返回重置密码电子邮件主题行的字符串的函数。
  •   
  • resetPassword.text:一个带有用户对象和网址的函数,并返回重置密码电子邮件的正文。
  •   

您可以自定义将哪个网址传递给重置密码电子邮件方法:

Accounts.resetPassword.text = function(user, url) {
  return "Click this link to reset your password: /reset-password/" + myId;
}
相关问题