Moving to github

This commit is contained in:
2026-03-28 19:24:29 -04:00
commit 036fa7ab33
302 changed files with 17838 additions and 0 deletions

27
app/models/api_token.rb Normal file
View File

@@ -0,0 +1,27 @@
class ApiToken < ApplicationRecord
belongs_to :user
# Validations
validates :token, presence: true, uniqueness: true
# Callbacks
before_validation :generate_token, on: :create
# Scopes
scope :active, -> { where("expires_at IS NULL OR expires_at > ?", Time.current) }
# Instance methods
def expired?
expires_at.present? && expires_at < Time.current
end
def touch_last_used!
update_column(:last_used_at, Time.current)
end
private
def generate_token
self.token ||= SecureRandom.urlsafe_base64(32)
end
end