BigW Consortium Gitlab

personal_access_token.rb 516 Bytes
Newer Older
1
class PersonalAccessToken < ActiveRecord::Base
2 3 4
  include TokenAuthenticatable
  add_authentication_token_field :token

5 6
  belongs_to :user

7 8
  scope :active, -> { where(revoked: false).where("expires_at >= NOW() OR expires_at IS NULL") }
  scope :inactive, -> { where("revoked = true OR expires_at < NOW()") }
9

10 11
  def self.generate(params)
    personal_access_token = self.new(params)
12
    personal_access_token.ensure_token
13 14
    personal_access_token
  end
15 16 17 18 19

  def revoke!
    self.revoked = true
    self.save
  end
20
end