Sha256: b52acf76a8d3296138a6a6010c826458286242eecce69cceb81340ea99406fa5

Contents?: true

Size: 1.16 KB

Versions: 2

Compression:

Stored size: 1.16 KB

Contents

module Identity
  module Mixins
    module User
      def self.included(base)
        base.devise *Identity.devise_modules
        base.extend ClassMethods

        if Devise.omniauth_providers.any?
          base.devise :omniauthable, omniauth_providers: Devise.omniauth_providers
        end
      end

      def build_from_auth(auth)
        self.email = "#{auth.uid}@#{auth.provider}.com"
        self.password = Devise.friendly_token[0,20]
        self.oauth_hash = auth

        send("build_from_#{auth.provider}", auth) if respond_to?("build_from_#{auth.provider}")
      end

      module ClassMethods
        def from_omniauth!(auth)
          where(provider: auth.provider, uid: auth.uid).first_or_create! do |user|
            user.build_from_auth auth
          end
        end

        def find_first_by_auth_conditions(tainted_conditions, opts = {})
          super(tainted_conditions, send(Identity.active_scope).where_values_hash.merge(opts))
        end

        def active
          result = where(active: true)
          result = result.where.not(confirmed_at: nil) if devise_modules.include?(:confirmable)
          result
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
anadea-identity-0.5.3 lib/identity/mixins/user.rb
anadea-identity-0.5.2 lib/identity/mixins/user.rb