Sha256: 9622aabb229e319309673df144e4b5499919249e6cfe6ad1bfaaabff59d4f6ce

Contents?: true

Size: 1.23 KB

Versions: 8

Compression:

Stored size: 1.23 KB

Contents

# coding: utf-8
module DeviseRussian
  module Models
    module Base
      def self.included(base)
        base.extend ClassMethods
      end

      module ClassMethods
        def omniauthable
          has_many :authentications, :dependent => :destroy

          def omniauth_enabled
            true
          end

          unless included_modules.include? InstanceMethods
            include InstanceMethods
          end
        end
      end

      module InstanceMethods
        def apply_omniauth(omniauth, with_self=false)
          provider = omniauth['provider']
          uid = omniauth['uid']
          user_email = omniauth['extra']['raw_info']['email'] rescue nil
          user_name = omniauth['extra']['raw_info']['first_name'] rescue nil

          if with_self
            self.email = user_email if user_email && self.email.blank?
            self.name = user_name if user_name && self.name.blank?
          end

          self.authentications.new(
            :provider => provider,
            :uid => uid,
            :email => user_email,
            :name => user_name
          )
        end

        def password_required?
          (authentications.empty? || !password.blank?) && super
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
devise_russian-0.0.29 lib/devise_russian/models/base.rb
devise_russian-0.0.28 lib/devise_russian/models/base.rb
devise_russian-0.0.27 lib/devise_russian/models/base.rb
devise_russian-0.0.26 lib/devise_russian/models/base.rb
devise_russian-0.0.25 lib/devise_russian/models/base.rb
devise_russian-0.0.24 lib/devise_russian/models/base.rb
devise_russian-0.0.23 lib/devise_russian/models/base.rb
devise_russian-0.0.22 lib/devise_russian/models/base.rb