Sha256: 76bd2debf672b1fa6e795a9ae118e8f28d89b039a216413efcc46098f2bce558
Contents?: true
Size: 644 Bytes
Versions: 17
Compression:
Stored size: 644 Bytes
Contents
# frozen_string_literal: true class PasswordResetToken < ApplicationRecord belongs_to :user before_create :ensure_token before_create :ensure_expiration scope :active, -> { where("expires_at >= ?", Time.now.utc) } scope :expired, -> { where("expires_at < ?", Time.now.utc) } class << self def default_expiration 24.hours end def expire! expired.delete_all end end def expired? expires_at < Time.now.utc end private def ensure_expiration self.expires_at ||= Time.now.utc + self.class.default_expiration end def ensure_token self.token ||= SecureRandom.hex(32) end end
Version data entries
17 entries across 17 versions & 1 rubygems