From 423de2d89105ef5c441432a3c0103b73e8b7c696 Mon Sep 17 00:00:00 2001 From: Gabriel Silva Date: Thu, 21 Jul 2016 18:28:40 +0000 Subject: [PATCH] Adds GitHubAuth and GoogleOauth2Auth image urls --- plugins/oauth_client/controllers/public/oauth_client_plugin_public_controller.rb | 5 +++-- plugins/oauth_client/db/migrate/20160720165808_add_external_profile_to_oauth_auth.rb | 6 ++++-- plugins/oauth_client/models/oauth_client_plugin/auth.rb | 11 ++++++++++- plugins/oauth_client/models/oauth_client_plugin/facebook_auth.rb | 12 ++---------- plugins/oauth_client/models/oauth_client_plugin/github_auth.rb | 10 +--------- plugins/oauth_client/models/oauth_client_plugin/google_oauth2_auth.rb | 7 +++++++ 6 files changed, 27 insertions(+), 24 deletions(-) create mode 100644 plugins/oauth_client/models/oauth_client_plugin/google_oauth2_auth.rb diff --git a/plugins/oauth_client/controllers/public/oauth_client_plugin_public_controller.rb b/plugins/oauth_client/controllers/public/oauth_client_plugin_public_controller.rb index 66c8b48..074ce16 100644 --- a/plugins/oauth_client/controllers/public/oauth_client_plugin_public_controller.rb +++ b/plugins/oauth_client/controllers/public/oauth_client_plugin_public_controller.rb @@ -41,8 +41,9 @@ class OauthClientPluginPublicController < PublicController user.external_person_id = person.id if person.oauth_auth.nil? - OauthClientPlugin::Auth.create_for_strategy(provider.strategy, external_person: person, - provider: provider, uid: auth.uid, enabled: true) + auth_data = { external_person: person, provider: provider, enabled: true, + external_person_uid: auth.uid, external_person_image_url: auth.info.image } + OauthClientPlugin::Auth.create_for_strategy(provider.strategy, auth_data) end self.current_user = user else diff --git a/plugins/oauth_client/db/migrate/20160720165808_add_external_profile_to_oauth_auth.rb b/plugins/oauth_client/db/migrate/20160720165808_add_external_profile_to_oauth_auth.rb index acdd427..855e2ce 100644 --- a/plugins/oauth_client/db/migrate/20160720165808_add_external_profile_to_oauth_auth.rb +++ b/plugins/oauth_client/db/migrate/20160720165808_add_external_profile_to_oauth_auth.rb @@ -1,13 +1,15 @@ class AddExternalProfileToOauthAuth < ActiveRecord::Migration def up add_column :oauth_client_plugin_auths, :external_person_id, :integer - add_column :oauth_client_plugin_auths, :uid, :string + add_column :oauth_client_plugin_auths, :external_person_uid, :string + add_column :oauth_client_plugin_auths, :external_person_image_url, :string add_index :oauth_client_plugin_auths, :external_person_id end def down remove_index :oauth_client_plugin_auths, :external_person_id remove_column :oauth_client_plugin_auths, :external_person_id - remove_column :oauth_client_plugin_auths, :uid + remove_column :oauth_client_plugin_auths, :external_person_uid + remove_column :oauth_client_plugin_auths, :external_person_image_url end end diff --git a/plugins/oauth_client/models/oauth_client_plugin/auth.rb b/plugins/oauth_client/models/oauth_client_plugin/auth.rb index 7e52714..11db685 100644 --- a/plugins/oauth_client/models/oauth_client_plugin/auth.rb +++ b/plugins/oauth_client/models/oauth_client_plugin/auth.rb @@ -1,7 +1,8 @@ class OauthClientPlugin::Auth < ApplicationRecord attr_accessible :profile, :external_person, :provider, - :enabled, :access_token, :expires_in, :type, :uid + :enabled, :access_token, :expires_in, :type, + :external_person_uid, :external_person_image_url belongs_to :profile, class_name: 'Profile' belongs_to :external_person, class_name: 'ExternalPerson' @@ -41,6 +42,14 @@ class OauthClientPlugin::Auth < ApplicationRecord end end + IMAGE_SIZES = { + :big => "150", + :thumb => "100", + :portrait => "64", + :minor => "50", + :icon => "18" + } + # Should be implemented by the Provider specific Auth classes def image_url(size = nil) nil diff --git a/plugins/oauth_client/models/oauth_client_plugin/facebook_auth.rb b/plugins/oauth_client/models/oauth_client_plugin/facebook_auth.rb index 69aacde..80025bd 100644 --- a/plugins/oauth_client/models/oauth_client_plugin/facebook_auth.rb +++ b/plugins/oauth_client/models/oauth_client_plugin/facebook_auth.rb @@ -1,16 +1,8 @@ class OauthClientPlugin::FacebookAuth < OauthClientPlugin::Auth - IMAGE_SIZES = { - :big => "150", - :thumb => "100", - :portrait => "64", - :minor => "50", - :icon => "20" - } - def image_url(size = nil) - size = "" - "http://graph.facebook.com/#{self.uid}/picture" + size = IMAGE_SIZES[size] || IMAGE_SIZES[:icon] + "#{self.external_person_image_url}?width=#{size}" end def perfil_url diff --git a/plugins/oauth_client/models/oauth_client_plugin/github_auth.rb b/plugins/oauth_client/models/oauth_client_plugin/github_auth.rb index 0e5ca8c..7c52aca 100644 --- a/plugins/oauth_client/models/oauth_client_plugin/github_auth.rb +++ b/plugins/oauth_client/models/oauth_client_plugin/github_auth.rb @@ -1,15 +1,7 @@ class OauthClientPlugin::GithubAuth < OauthClientPlugin::Auth - IMAGE_SIZE = { - :big => "150", - :thumb => "100", - :portrait => "64", - :minor => "50", - :icon => "18" - } - def image_url(size = nil) size = IMAGE_SIZES[size] || IMAGE_SIZES[:icon] - "https://avatars.githubusercontent.com/u/#{self.uid}?v=3&size=#{size}" + "#{self.external_person_image_url}&size=#{size}" end end diff --git a/plugins/oauth_client/models/oauth_client_plugin/google_oauth2_auth.rb b/plugins/oauth_client/models/oauth_client_plugin/google_oauth2_auth.rb new file mode 100644 index 0000000..f891db7 --- /dev/null +++ b/plugins/oauth_client/models/oauth_client_plugin/google_oauth2_auth.rb @@ -0,0 +1,7 @@ +class OauthClientPlugin::GoogleOauth2Auth < OauthClientPlugin::Auth + + def image_url(size = nil) + size = IMAGE_SIZES[size] || IMAGE_SIZES[:icon] + "#{self.external_person_image_url}?sz=#{size}" + end +end -- libgit2 0.21.2