首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Timex设置验证链接的超时

使用Timex设置验证链接的超时
EN

Stack Overflow用户
提问于 2018-03-23 10:34:25
回答 1查看 55关注 0票数 0

保存到我的数据库后,我将通过电子邮件发送一个验证链接。我希望链接有一个超时,也就是说,它将在一定的持续时间后变得无效。我如何使用Timex来做到这一点?我不想使用其他身份验证包,比如一致性。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-03-27 05:35:37

您可能根本不需要Timex,现在假设您的DB正在使用朴素时区,您可以使用

代码语言:javascript
复制
# Assuming the link will expire in an hour (3600 seconds)
valid_till = NaiveDateTime.add(NaiveDateTime.utc_now(), 3600)

# Sends the verification mail
...

# Save the valid_till somewhere in the database and when user tries to use the link to verify themselves compare the current timestamp against the stored valid_till
if NaiveDateTime.utc_now > stored_valid_till, do: false
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49447654

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档