How do you change the reset password URL in meteor?

断了今生、忘了曾经 提交于 2019-12-18 12:09:34

问题


I am using meteor along with the accounts-password package. I'm rolling my own login and password changing/resetting UI and want to know...

How can I customize the password reset link in the reset password email sent as a result of Accounts.resetPassword?

Currently it in the form like so: /#/reset-password/<id>'. Since I am using meteor router, I would like to send in the form '/reset-password/<id>'so I can catch it with the route '/reset-password/:id'.


回答1:


See the section on email templates in the Meteor docs:

resetPassword: An Object with two fields:

  • resetPassword.subject: A Function that takes a user object and returns a String for the subject line of a reset password email.
  • resetPassword.text: A Function that takes a user object and a url, and returns the body text for a reset password email.

You can customise which url is passed to the reset password email method:

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



回答2:


Late to the party ...

Instead of changing the whole text, you can just change the url with:

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



回答3:


It has changed a little bit:

You have to use

Accounts.emailTemplates.resetPassword.text

For the url you can simply replace the hashbang instead of parsing the token from the url. As an example (in 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}`;
   }
);


来源:https://stackoverflow.com/questions/14130310/how-do-you-change-the-reset-password-url-in-meteor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!