module JamRuby
  class TempToken < ActiveRecord::Base

    belongs_to :user
    before_validation :generate_token, :set_expired_at, on: :create
    validates :token, :expired_at, :purpose, presence: true

  private

    def generate_token
      self.token = SecureRandom.hex(32)
    end

    def set_expired_at
      self.expired_at = Time.now + 5.minutes
    end
  end
end
