You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

21 lines
435 B

class VerificationCode < ApplicationRecord
VALID_FOR = 15.minutes
before_validation(on: :create) do
self.token = rand(100000..999999).to_s
end
validates_presence_of :token
belongs_to :user
scope :valid, -> { where("verification_codes.created_at > ?", VALID_FOR.ago) }
scope :expired, -> { where("verification_codes.created_at <= ?", VALID_FOR.ago) }
def expires_at
self.created_at + VALID_FOR
end
end