Sha256: 7a61507632a818f8f858094051ee87a9182bccff8dd2395db8cbecb91cbafc01

Contents?: true

Size: 623 Bytes

Versions: 11

Compression:

Stored size: 623 Bytes

Contents

class Marty::Token < Marty::Base
  belongs_to :user
  validates :value, uniqueness: true

  before_create :delete_previous_tokens, :generate_new_token

  # @@validity_time = 1.day

  def generate_new_token
    self.value = Token.generate_token_value
  end

  # # Return true if token has expired
  # def expired?
  #   return Time.now > self.created_on + @@validity_time
  # end

  private

  def self.generate_token_value
    SecureRandom.hex(20)
  end

  # Removes obsolete tokens
  def delete_previous_tokens
    if user && !Marty::Util.db_in_recovery?
      Token.delete_all(['user_id = ?', user.id])
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
marty-14.3.0 app/models/marty/token.rb
marty-14.0.0 app/models/marty/token.rb
marty-13.0.2 app/models/marty/token.rb
marty-11.0.0 app/models/marty/token.rb
marty-10.0.3 app/models/marty/token.rb
marty-10.0.2 app/models/marty/token.rb
marty-10.0.0 app/models/marty/token.rb
marty-9.5.1 app/models/marty/token.rb
marty-9.5.0 app/models/marty/token.rb
marty-9.3.3 app/models/marty/token.rb
marty-9.3.2 app/models/marty/token.rb