2016-04-15 03:36:44 -04:00
|
|
|
class PersonalAccessToken < ActiveRecord::Base
|
2016-04-25 05:00:59 -04:00
|
|
|
include TokenAuthenticatable
|
|
|
|
add_authentication_token_field :token
|
|
|
|
|
2016-04-15 03:36:44 -04:00
|
|
|
belongs_to :user
|
|
|
|
|
2016-04-22 04:33:11 -04:00
|
|
|
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
|
|
|
|
2016-04-15 03:36:44 -04:00
|
|
|
def self.generate(params)
|
|
|
|
personal_access_token = self.new(params)
|
2016-04-25 05:00:59 -04:00
|
|
|
personal_access_token.ensure_token
|
2016-04-15 03:36:44 -04:00
|
|
|
personal_access_token
|
|
|
|
end
|
2016-04-15 11:24:20 -04:00
|
|
|
|
|
|
|
def revoke!
|
|
|
|
self.revoked = true
|
|
|
|
self.save
|
|
|
|
end
|
2016-04-15 03:36:44 -04:00
|
|
|
end
|