Improved self.create_from_hash!.
This commit is contained in:
parent
060381e0db
commit
47400286b3
|
@ -32,8 +32,8 @@ class User < ApplicationModel
|
||||||
|
|
||||||
before_create :check_name, :check_email, :check_login, :check_password
|
before_create :check_name, :check_email, :check_login, :check_password
|
||||||
before_update :check_password, :check_email, :check_login
|
before_update :check_password, :check_email, :check_login
|
||||||
after_create :avatar_check
|
after_create :avatar_for_email_check
|
||||||
after_update :avatar_check
|
after_update :avatar_for_email_check
|
||||||
after_destroy :avatar_destroy
|
after_destroy :avatar_destroy
|
||||||
notify_clients_support
|
notify_clients_support
|
||||||
|
|
||||||
|
@ -249,17 +249,23 @@ returns
|
||||||
=end
|
=end
|
||||||
|
|
||||||
def self.create_from_hash!(hash)
|
def self.create_from_hash!(hash)
|
||||||
|
|
||||||
|
roles = Role.where( name: 'Customer' )
|
||||||
url = ''
|
url = ''
|
||||||
if hash['info']['urls']
|
if hash['info']['urls']
|
||||||
url = hash['info']['urls']['Website'] || hash['info']['urls']['Twitter'] || ''
|
hash['info']['urls'].each {|_name, local_url|
|
||||||
|
next if !local_url
|
||||||
|
next if local_url.empty?
|
||||||
|
url = local_url
|
||||||
|
}
|
||||||
end
|
end
|
||||||
roles = Role.where( name: 'Customer' )
|
|
||||||
create(
|
create(
|
||||||
login: hash['info']['nickname'] || hash['uid'],
|
login: hash['info']['nickname'] || hash['uid'],
|
||||||
firstname: hash['info']['name'],
|
firstname: hash['info']['name'],
|
||||||
email: hash['info']['email'],
|
email: hash['info']['email'],
|
||||||
image: hash['info']['image'],
|
image_source: hash['info']['image'],
|
||||||
# :url => url.to_s,
|
web: url,
|
||||||
|
address: hash['info']['location'],
|
||||||
note: hash['info']['description'],
|
note: hash['info']['description'],
|
||||||
source: hash['provider'],
|
source: hash['provider'],
|
||||||
roles: roles,
|
roles: roles,
|
||||||
|
@ -503,7 +509,7 @@ returns
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def avatar_check
|
def avatar_for_email_check
|
||||||
|
|
||||||
return if !email
|
return if !email
|
||||||
return if email.empty?
|
return if email.empty?
|
||||||
|
|
Loading…
Reference in a new issue