Module: Socialite::Models::UserConcern::ClassMethods

Defined in:
lib/socialite/models/user_concern.rb

Instance Method Summary collapse

Instance Method Details

#auth_keyObject


50
# File 'lib/socialite/models/user_concern.rb', line 50

def auth_key; :email; end

#create_from_omniauth(auth) ⇒ Object


38
39
40
41
42
43
44
45
46
47
48
# File 'lib/socialite/models/user_concern.rb', line 38

def create_from_omniauth(auth)
  create do |user|
    user.name = auth['info']['name']
    user.email = auth['info']['email']
    unless user.email.present?
      user.email = "#{auth['info']['nickname']}@#{auth['provider']}.com"
      user.placeholder_email = true if user.respond_to?(:"placeholder_email=")
    end
    user.password ||= rand(36**10).to_s(36)
  end
end

#find_from_omniauth(auth) ⇒ Object


26
27
28
29
30
31
32
# File 'lib/socialite/models/user_concern.rb', line 26

def find_from_omniauth(auth)
  if auth['info']['email']
    find_by_email(auth['info']['email'])
  else
    find_by_email("#{auth['info']['name']}@#{auth['provider']}.com")
  end
end

#find_or_create_from_omniauth(auth) ⇒ Object


34
35
36
# File 'lib/socialite/models/user_concern.rb', line 34

def find_or_create_from_omniauth(auth)
  find_from_omniauth(auth) || create_from_omniauth(auth)
end

#locate(search_hash) ⇒ Object


52
53
54
55
56
57
58
# File 'lib/socialite/models/user_concern.rb', line 52

def locate(search_hash)
  if Hash === search_hash
    where(search_hash).first
  else
    where(:email => search_hash).first
  end
end