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

View file

@ -102,7 +102,7 @@ add a avatar
# twitter workaround to get bigger avatar images # twitter workaround to get bigger avatar images
# see also https://dev.twitter.com/overview/general/user-profile-images-and-banners # see also https://dev.twitter.com/overview/general/user-profile-images-and-banners
if data[:url] =~ %r{//pbs.twimg.com/}i 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 end
# fetch image # fetch image