Last active
July 28, 2016 03:57
-
-
Save giancarlosisasi/674a5af4300ae481dbc112df89425d56 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Token < ApplicationRecord | |
| belongs_to :user | |
| before_create :generate_token | |
| def valid? | |
| self.expires_at > DateTime.now | |
| end | |
| private | |
| def generate_token | |
| loop do | |
| self.token = SecureRandom.hex | |
| break unless Token.where(token: self.token).exists? | |
| end | |
| self.expires_at = 3.month.from_now | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment