我发送此电子邮件邀请人们注册。这是我的路线
router.post('/invite-supervisor', (req,res) => {
const email = req.body.invite_email;
const secretToken = randomstring.generate();
// console.log('Email :',email);
//Composing email
const html = `Hi there
<br/>
To get registered please click on the following link and paste your secret token for registration.
<br/><br/>
Token : ${secretToken}
<br/><br/>
<a href="http://localhost:3000/signup/${secretToken}">http://localhost:3000/signup/${secretToken}</a>
<br/><br/>
Have a good day!`;
//<a href="http://localhost:3000/users/verify/${secretToken}">p</a>
mailer.sendEmail('admin@teamfly.com',email,'Please signup through this link',html);
req.flash('success','An invitation email sent to '+email);
res.redirect('/');
});
现在我想在几个小时后禁用我的链接。我怎么能这样做。
答案 0 :(得分:1)
如果为您创建和管理令牌数据库及其到期时间并不容易,您可以使用JWT令牌并在令牌本身内包含到期时间:https://jwt.io
特别是对于Node.js,你已经为它开发了很好的库:https://www.npmjs.com/package/jsonwebtoken
当您创建JWT令牌时,您可以设置&#34; expiresIn&#34;选项即6h,它会自动创建&#34; exp&#34;字段(所以你不必计算它)
然后,当您验证令牌时,它会自动检查它是否仍然有效
答案 1 :(得分:0)
我将遵循的设计如下: