gitlab-org--gitlab-foss/app/models/personal_access_token.rb

23 lines
544 B
Ruby
Raw Normal View History

class PersonalAccessToken < ActiveRecord::Base
include TokenAuthenticatable
add_authentication_token_field :token
serialize :scopes, Array
belongs_to :user
scope :active, -> { where(revoked: false).where("expires_at >= NOW() OR expires_at IS NULL") }
scope :inactive, -> { where("revoked = true OR expires_at < NOW()") }
2016-04-15 11:24:20 -04:00
def self.generate(params)
personal_access_token = self.new(params)
personal_access_token.ensure_token
personal_access_token
end
2016-04-15 11:24:20 -04:00
def revoke!
self.revoked = true
self.save
end
end