简体   繁体   中英

Set timeout for verification link using Timex

I am sending a verification link via email after saving it to my database. I want the link to have a timeout, ie, it would be rendered invalid after a certain duration. How do I do so using Timex? I don't want to use other authentication packages like Coherence.

You may not need Timex at all, now assuming your DB is using naive time zone, you can use

# 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM