Sha256: 97318879dffa4cfdba670284676797757f03900696cf1459d649c5c5c529a92b

Contents?: true

Size: 1.47 KB

Versions: 4

Compression:

Stored size: 1.47 KB

Contents

# frozen_string_literal

# 
# Model for managing password reset tokens
#
# Automatically generated by the orthodox gem (https://github.com/katanacode/orthodox)
# (c) Copyright 2019 Katana Code Ltd. All Rights Reserved. 
#
# == Schema Information
#
# Table name: password_reset_tokens
#
#  id             :bigint           not null, primary key
#  expires_at     :datetime
#  resetable_type :string           not null
#  secret         :string
#  created_at     :datetime         not null
#  updated_at     :datetime         not null
#  resetable_id   :bigint           not null
#
# Indexes
#
#  index_password_reset_tokens_on_expires_at                       (expires_at)
#  index_password_reset_tokens_on_resetable_type_and_resetable_id  (resetable_type,resetable_id)
#  index_password_reset_tokens_on_secret                           (secret) UNIQUE
#

class PasswordResetToken < ApplicationRecord
  
  # =============
  # = Constants =
  # =============
  
  ##
  # How long should password reset links be valid for?
  EXPIRES_AFTER = 15.minutes
  
  # ================
  # = Associations =
  # ================
  
  belongs_to :resetable, polymorphic: true
  
  # ==============
  # = Attributes =
  # ==============
  
  has_secure_token :secret
  
  attr_readonly :resetable_type, :resetable_id, :expires_at, :secret
  
  before_create :set_expires_at
  
  def expired?
    expires_at <= Time.current
  end
  
  private
  
  def set_expires_at
    self.expires_at = EXPIRES_AFTER.from_now
  end
  
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
orthodox-0.3.3 lib/generators/authentication/templates/models/password_reset_token.rb
orthodox-0.3.2 lib/generators/authentication/templates/models/password_reset_token.rb
orthodox-0.3.1 lib/generators/authentication/templates/models/password_reset_token.rb
orthodox-0.3.0 lib/generators/authentication/templates/models/password_reset_token.rb