Sha256: 2ed2d360bdc9c006e25adab1537453bc1cdffab151f2320a3e7757c534ccb553

Contents?: true

Size: 806 Bytes

Versions: 3

Compression:

Stored size: 806 Bytes

Contents

class Devise::Oauth2Providable::Client < ActiveRecord::Base
  has_many :access_tokens
  has_many :refresh_tokens
  has_many :authorization_codes

  before_validation :init_identifier, :on => :create, :unless => :identifier?
  before_validation :init_secret, :on => :create, :unless => :secret?
  validates :website, :secret, :presence => true
  validates :name, :presence => true, :uniqueness => true
  validates :identifier, :presence => true, :uniqueness => true

  def expire_tokens_for_user(user)
    access_tokens.where(user_id: user.id).where('expires_at > ?', Time.zone.now).update_all(expires_at: Time.zone.now)
  end

  private

  def init_identifier
    self.identifier = Devise::Oauth2Providable.random_id
  end

  def init_secret
    self.secret = Devise::Oauth2Providable.random_id
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
brycesch-devise_oauth2_providable-1.2.7 app/models/devise/oauth2_providable/client.rb
brycesch-devise_oauth2_providable-1.2.6 app/models/devise/oauth2_providable/client.rb
brycesch-devise_oauth2_providable-1.2.5 app/models/devise/oauth2_providable/client.rb