为什么模板不能重置密码环回

时间:2022-01-19 08:27:55

i m just confuse why template not working in reset password function

我只是混淆了为什么模板不能在重置密码功能

  user.on('resetPasswordRequest', function(info) {
   var url = 'http://' + config.host + ':' + config.port + '/reset-password';
   var html = 'Click <a href="' + url + '?access_token=' +
    info.accessToken.id + '">here</a> to reset your password';
     user.app.models.Email.send({
          to: info.email,
          from: info.email,
          subject: 'Password reset',
          html: html
    }, function(err) {
       if (err) return console.log('> error sending password reset email');
      console.log('> sending password reset email to:', info.email);
   });
 });

above code is working fine but if i use template intead of html then i got empty template in email for eg like below

上面的代码工作正常,但如果我使用HTML的模板intead然后我在电子邮件中得到空模板,如下所示

    user.app.models.Email.send({
          to: info.email,
          from: info.email,
          subject: 'Password reset',
         template: path.resolve(__dirname, '../../server/views/verify.ejs'),
    }, function(err) {
       if (err) return console.log('> error sending password reset email');
      console.log('> sending password reset email to:', info.email);
   });

if i use this same template in user.verify method it work there then why it not working here
is there any other alternative to provide template in password reset

如果我在user.verify方法中使用相同的模板它在那里工作,那么为什么它不工作在那里有任何其他替代提供密码重置模板

2 个解决方案

#1


1  

hello rocky you can try something like this

你好,你可以试试这样的东西

var ejs = require("ejs");

var token = info.accessToken.id;
var pathreset= path.resolve(__dirname, '../../server/views/resetpassword1.ejs');

ejs.renderFile(pathreset, { username: info.user.username, token:token }, function (err, data) {
        if (err) {
                console.log(err);
         } else {

             var options={
                to: info.email,
                from: credentials.user,
                subject: 'Password reset',
                html:data
                }

             User.app.models.Email.send(options, function(err) {
                    if (err) return console.log('> error sending password reset email');
                     console.log('> sending password reset email to:', info.email);
             });

hope this will help you as well other

希望这对你也有帮助

#2


1  

I'm actually using html instead of template attribute, and creating a template with loopback, so your code would looks like:

我实际上使用的是html而不是template属性,并创建了一个带有loopback的模板,所以你的代码看起来像:

 var loopback = require('loopback');
 var render = loopback.template(path.join(__dirname, '../../server/views/verify.ejs'));
 var html = render(
    // only if you need to map some fields in your .ejs file
    {
            firstName: firstname,
            lastName: lastname,
            link: confirmLink
    }
);

    user.app.models.Email.send({
              to: info.email,
              from: info.email,
              subject: 'Password reset',
              text: html,
              html: html
        }, function(err) {
           if (err) return console.log('> error sending password reset email');
          console.log('> sending password reset email to:', info.email);
       });

#1


1  

hello rocky you can try something like this

你好,你可以试试这样的东西

var ejs = require("ejs");

var token = info.accessToken.id;
var pathreset= path.resolve(__dirname, '../../server/views/resetpassword1.ejs');

ejs.renderFile(pathreset, { username: info.user.username, token:token }, function (err, data) {
        if (err) {
                console.log(err);
         } else {

             var options={
                to: info.email,
                from: credentials.user,
                subject: 'Password reset',
                html:data
                }

             User.app.models.Email.send(options, function(err) {
                    if (err) return console.log('> error sending password reset email');
                     console.log('> sending password reset email to:', info.email);
             });

hope this will help you as well other

希望这对你也有帮助

#2


1  

I'm actually using html instead of template attribute, and creating a template with loopback, so your code would looks like:

我实际上使用的是html而不是template属性,并创建了一个带有loopback的模板,所以你的代码看起来像:

 var loopback = require('loopback');
 var render = loopback.template(path.join(__dirname, '../../server/views/verify.ejs'));
 var html = render(
    // only if you need to map some fields in your .ejs file
    {
            firstName: firstname,
            lastName: lastname,
            link: confirmLink
    }
);

    user.app.models.Email.send({
              to: info.email,
              from: info.email,
              subject: 'Password reset',
              text: html,
              html: html
        }, function(err) {
           if (err) return console.log('> error sending password reset email');
          console.log('> sending password reset email to:', info.email);
       });