0

将验证链接保存到我的数据库后,我正在通过电子邮件发送验证链接。我希望链接有一个超时,即,它会在一定时间后变为无效。我该如何使用 Timex?我不想使用其他身份验证包,如 Coherence。

4

1 回答 1

1

您可能根本不需要 Timex,现在假设您的数据库使用的是幼稚时区,您可以使用

# 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
于 2018-03-27T05:35:37.990 回答