14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'app/models/login/user.rb', line 14
def self.provider auth, provider_id
raise "Not enough information provided" unless auth.info.nickname.present? || auth.info.email.present?
find_hash = { email:auth.info.email }
find_hash = { github:auth.info.nickname } if provider_id == :github
find_hash = { twitter:auth.info.nickname } if provider_id == :twitter
user = where(find_hash).first
, github = "", ""
= auth.info.nickname if provider_id == :twitter
github = auth.info.nickname if provider_id == :github
first_name = auth.info.first_name.presence || auth.info.name.split.first || ""
last_name = auth.info.last_name.presence || auth.info.name.split.last || ""
transaction do
if user
user.update_attribute :twitter, unless user..present?
user.update_attribute :first_name, first_name unless user.first_name.present?
user.update_attribute :last_name, last_name unless user.last_name.present?
else
create_hash = { github: github, twitter: , first_name: first_name, last_name: last_name, password: Devise.friendly_token[0,20] }
create_hash[:email] = auth.info.email.presence
user = create! create_hash
end
user.providers.find_or_create auth
end
end
|