Cleanup of avatar use from third party systems.

This commit is contained in:
Martin Edenhofer 2015-07-06 15:50:13 +02:00
parent 9fd61820c7
commit 060381e0db
2 changed files with 14 additions and 13 deletions

View file

@ -42,8 +42,9 @@ class Authorization < ApplicationModel
)
# update user link
if avatar
user.update_column( :image, avatar.store_hash )
if avatar && user.image != avatar.store_hash
user.image = avatar.store_hash
user.save
end
end
end
@ -51,9 +52,13 @@ class Authorization < ApplicationModel
end
def self.create_from_hash(hash, user = nil)
if user
# save/update avatar
if !user
user = User.create_from_hash!(hash)
end
# save/update avatar
if hash['info']['image']
avatar = Avatar.add(
object: 'User',
o_id: user.id,
@ -65,15 +70,10 @@ class Authorization < ApplicationModel
)
# update user link
if avatar
user.update_column( :image, avatar.store_hash )
if avatar && user.image != avatar.store_hash
user.image = avatar.store_hash
user.save
end
# fillup empty attributes
# TODO
else
user = User.create_from_hash!(hash)
end
Authorization.create(
@ -89,6 +89,7 @@ class Authorization < ApplicationModel
private
def delete_user_cache
return if !user
user.touch
end

View file

@ -102,7 +102,7 @@ add a avatar
# twitter workaround to get bigger avatar images
# see also https://dev.twitter.com/overview/general/user-profile-images-and-banners
if data[:url] =~ %r{//pbs.twimg.com/}i
data[:url].sub!(/normal\.png$/, 'bigger.png')
data[:url].sub!(/normal\.(png|jpg|gif)$/, 'bigger.\1')
end
# fetch image