Sha256: 92d3582fd951a0561ea780927ea999679dd06e644f8f2b868c3ac300e98849e4

Contents?: true

Size: 1.14 KB

Versions: 1

Compression:

Stored size: 1.14 KB

Contents

module Identity
  module Mixins
    module User
      extend ActiveSupport::Concern

      included do
        devise *Identity.devise_modules

        if Devise.omniauth_providers.any?
          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

1 entries across 1 versions & 1 rubygems

Version Path
anadea-identity-0.5.1 lib/identity/mixins/user.rb