保存到我的数据库后,我将通过电子邮件发送一个验证链接。我希望链接有一个超时,也就是说,它将在一定的持续时间后变得无效。我如何使用Timex来做到这一点?我不想使用其他身份验证包,比如一致性。
发布于 2018-03-27 05:35:37
您可能根本不需要Timex,现在假设您的DB正在使用朴素时区,您可以使用
# 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: falsehttps://stackoverflow.com/questions/49447654
复制相似问题