personal_access_token.rb 626 字节
Newer Older
1
class PersonalAccessToken < ActiveRecord::Base
2
  include Expirable
3 4 5
  include TokenAuthenticatable
  add_authentication_token_field :token

6 7
  serialize :scopes, Array

8 9
  belongs_to :user

10 11
  before_save :ensure_token

12
  scope :active, -> { where("revoked = false AND (expires_at >= NOW() OR expires_at IS NULL)") }
13
  scope :inactive, -> { where("revoked = true OR expires_at < NOW()") }
14 15
  scope :with_impersonation, -> { where(impersonation: true) }
  scope :without_impersonation, -> { where(impersonation: false) }
16 17 18 19 20

  def revoke!
    self.revoked = true
    self.save
  end
21 22 23 24

  def active?
    !revoked? && !expired?
  end
25
end