10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/empower/omniauth.rb', line 10
def from_omniauth(auth)
user = User.find_by_email(auth.info.email)
if user.nil?
user = User.create!(
:email => auth.info.email,
:password => Devise.friendly_token[0,20],
)
attrs = {}
if ActiveRecord::Base.connection.column_exists?(:users, :name, :string)
attrs[:name] = auth.info.name
end
if ActiveRecord::Base.connection.column_exists?(:users, :image, :string)
attrs[:image] = auth.info.image
end
if attrs.keys.size > 0
user.update_columns(attrs)
end
else
attrs = {}
if ActiveRecord::Base.connection.column_exists?(:users, :name, :string)
attrs[:name] = auth.info.name
end
if ActiveRecord::Base.connection.column_exists?(:users, :image, :string)
attrs[:image] = auth.info.image
end
if attrs.keys.size > 0
user.update_columns(attrs)
end
end
user
end
|