Sha256: 25c326fdd9c0abea1918a1333bfe88f9cca2cdc5812909b44bd776e234e172b4

Contents?: true

Size: 1.05 KB

Versions: 4

Compression:

Stored size: 1.05 KB

Contents

module OpenConferenceWare

  # == Schema Information
  #
  # Table name: authentications
  #
  #  id         :integer          not null, primary key
  #  user_id    :integer
  #  provider   :string(255)
  #  uid        :string(255)
  #  name       :string(255)
  #  email      :string(255)
  #  info       :text
  #  created_at :datetime         not null
  #  updated_at :datetime         not null
  #

  class Authentication < OpenConferenceWare::Base
    belongs_to :user
    serialize :info, JSON

    after_initialize do |auth|
      auth.info ||= {}
    end

    def self.find_and_update_or_create_from_auth_hash(auth_hash)
      auth = find_or_initialize_by(
        provider: auth_hash.provider,
        uid: auth_hash.uid
      )

      auth.name  = auth_hash.info.name
      auth.email = auth_hash.info.email
      auth.info  = auth_hash.info

      auth.save && auth
    end

    def has_first_and_last_name?
      !!(info['first_name'] && info['last_name'])
    end

    def first_url
      info['urls'].values.first if info['urls'].is_a?(Hash)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
open_conference_ware-1.0.0.pre4 app/models/open_conference_ware/authentication.rb
open_conference_ware-1.0.0.pre3 app/models/open_conference_ware/authentication.rb
open_conference_ware-1.0.0.pre2 app/models/open_conference_ware/authentication.rb
open_conference_ware-1.0.0.pre1 app/models/open_conference_ware/authentication.rb