2016-04-02 12 views
0

データベーステーブルのプロパティの値としてランダムに生成された文字列があります。私のレコードへの更新が成功すると、データベースレコードで使用されたのと同じトークンを含む電子メールを送信します。残念ながら、私のthenステートメントのトークンパラメータにはトークンが含まれておらず、値1に置き換えられています。なぜこれが起こっているのでしょうか?JavaScriptはチェーンの正しい値を渡さないと約束します

これは私のコードで表示される例コンソールログとSQLの更新です:

This is the token: 78a4543cdd4cfd9d8c7fbad89aed9f902e07c372 
Executing (default): UPDATE `user` SET `reset_password_token`='78a4543cdd4cfd9d8c7fbad89aed9f902e07c372',`reset_password_expires`='2016-04-02 14:46:13',`updatedAt`='2016-04-02 13:46:13' WHERE `email` = '[email protected]' 
Then this token: 1 

POSTメソッド:

.post(function(req, res){ 
     async.waterfall([ 
     function(done){ 
      crypto.randomBytes(20, function(err, buf){ 
       var resetToken = buf.toString('hex'); 
       done(err, resetToken); 
      }); 
     }, (function(token, done){ 


      console.log('This is the token: ' + token); 


      models.User.update({ 
       resetPasswordToken: token, 
       resetPasswordExpires: Date.now() + 3600000 
      }, { 
      where: { email: req.body.email } 

      }).then(function(token, user, done){ 


      console.log('Then this token: ' + token); 


      var transporter = nodemailer.createTransport(sgTransport(options)); 

      var mailOptions = { 
       from: '"Test Email" <[email protected]', 
       to: '[email protected]', 
       subject: 'Password Rest Confirmation', 
       text: 'You are receiving this because you (or someone else) have requested the reset of the password for your account.\n\n' + 
         'Please click on the following link, or paste this into your browser to complete the process:\n\n' + 
         'http://' + req.headers.host + '/reset/' + token + '\n\n' + 
         'If you did not request this, please ignore this email and your password will remain unchanged.\n' 
      }; 

      transporter.sendMail(mailOptions, function(error, info){ 
       if(error){ 
        return console.log(error); 
       } 
       console.log('Message sent: ' + info.response); 

      }); 
       res.redirect('/'); 
       //res.redirect('/password-reset-confirmation') Make a confirmation page with information or just send a flash message 
      }) 
     })], function(error){ 
     if(error){ 
      console.log(error); 
     } 
    }) 
    }); 

答えて

2

tokenupdate()ため、値1を受け取ります操作は影響を受けるレコードの数を返します。この場合、1つのレコードが更新されました。

+0

答えをありがとう。これはまさに私が探していたものでした – cphill

関連する問題