docbrown/app/models/identity.rb
Andy Zhao 22e76bee84 Add functionality to remove and recover identity (#3377)
* Lint some quotation marks

* Add BackupData table

* Add identity and removal functionality

* Test additional functionality

* Remove dependent destroy for backup data

* Add auth_data_dump column

* Add challenge to reserved words

* Add more shoulda matchers
2019-07-03 12:01:16 -04:00

14 lines
602 B
Ruby

class Identity < ApplicationRecord
belongs_to :user
has_many :backup_data, as: :instance, class_name: "BackupData", dependent: :destroy
validates :uid, :provider, presence: true
validates :uid, uniqueness: { scope: :provider }, if: proc { |i| i.uid_changed? || i.provider_changed? }
validates :user_id, uniqueness: { scope: :provider }, if: proc { |i| i.user_id_changed? || i.provider_changed? }
validates :provider, inclusion: { in: %w[github twitter] }
serialize :auth_data_dump
def self.find_for_oauth(auth)
find_or_create_by(uid: auth.uid, provider: auth.provider)
end
end