Commit 423de2d89105ef5c441432a3c0103b73e8b7c696
1 parent
ad5a4b60
Adds GitHubAuth and GoogleOauth2Auth image urls
Signed-off-by: Gabriel Silva <gabriel93.silva@gmail.com> Signed-off-by: Sabryna Sousa <sabryna.sousa1323@gmail.com>
Showing
6 changed files
with
27 additions
and
24 deletions
Show diff stats
plugins/oauth_client/controllers/public/oauth_client_plugin_public_controller.rb
... | ... | @@ -41,8 +41,9 @@ class OauthClientPluginPublicController < PublicController |
41 | 41 | user.external_person_id = person.id |
42 | 42 | |
43 | 43 | if person.oauth_auth.nil? |
44 | - OauthClientPlugin::Auth.create_for_strategy(provider.strategy, external_person: person, | |
45 | - provider: provider, uid: auth.uid, enabled: true) | |
44 | + auth_data = { external_person: person, provider: provider, enabled: true, | |
45 | + external_person_uid: auth.uid, external_person_image_url: auth.info.image } | |
46 | + OauthClientPlugin::Auth.create_for_strategy(provider.strategy, auth_data) | |
46 | 47 | end |
47 | 48 | self.current_user = user |
48 | 49 | else | ... | ... |
plugins/oauth_client/db/migrate/20160720165808_add_external_profile_to_oauth_auth.rb
1 | 1 | class AddExternalProfileToOauthAuth < ActiveRecord::Migration |
2 | 2 | def up |
3 | 3 | add_column :oauth_client_plugin_auths, :external_person_id, :integer |
4 | - add_column :oauth_client_plugin_auths, :uid, :string | |
4 | + add_column :oauth_client_plugin_auths, :external_person_uid, :string | |
5 | + add_column :oauth_client_plugin_auths, :external_person_image_url, :string | |
5 | 6 | add_index :oauth_client_plugin_auths, :external_person_id |
6 | 7 | end |
7 | 8 | |
8 | 9 | def down |
9 | 10 | remove_index :oauth_client_plugin_auths, :external_person_id |
10 | 11 | remove_column :oauth_client_plugin_auths, :external_person_id |
11 | - remove_column :oauth_client_plugin_auths, :uid | |
12 | + remove_column :oauth_client_plugin_auths, :external_person_uid | |
13 | + remove_column :oauth_client_plugin_auths, :external_person_image_url | |
12 | 14 | end |
13 | 15 | end | ... | ... |
plugins/oauth_client/models/oauth_client_plugin/auth.rb
1 | 1 | class OauthClientPlugin::Auth < ApplicationRecord |
2 | 2 | |
3 | 3 | attr_accessible :profile, :external_person, :provider, |
4 | - :enabled, :access_token, :expires_in, :type, :uid | |
4 | + :enabled, :access_token, :expires_in, :type, | |
5 | + :external_person_uid, :external_person_image_url | |
5 | 6 | |
6 | 7 | belongs_to :profile, class_name: 'Profile' |
7 | 8 | belongs_to :external_person, class_name: 'ExternalPerson' |
... | ... | @@ -41,6 +42,14 @@ class OauthClientPlugin::Auth < ApplicationRecord |
41 | 42 | end |
42 | 43 | end |
43 | 44 | |
45 | + IMAGE_SIZES = { | |
46 | + :big => "150", | |
47 | + :thumb => "100", | |
48 | + :portrait => "64", | |
49 | + :minor => "50", | |
50 | + :icon => "18" | |
51 | + } | |
52 | + | |
44 | 53 | # Should be implemented by the Provider specific Auth classes |
45 | 54 | def image_url(size = nil) |
46 | 55 | nil | ... | ... |
plugins/oauth_client/models/oauth_client_plugin/facebook_auth.rb
1 | 1 | class OauthClientPlugin::FacebookAuth < OauthClientPlugin::Auth |
2 | 2 | |
3 | - IMAGE_SIZES = { | |
4 | - :big => "150", | |
5 | - :thumb => "100", | |
6 | - :portrait => "64", | |
7 | - :minor => "50", | |
8 | - :icon => "20" | |
9 | - } | |
10 | - | |
11 | 3 | def image_url(size = nil) |
12 | - size = "" | |
13 | - "http://graph.facebook.com/#{self.uid}/picture" | |
4 | + size = IMAGE_SIZES[size] || IMAGE_SIZES[:icon] | |
5 | + "#{self.external_person_image_url}?width=#{size}" | |
14 | 6 | end |
15 | 7 | |
16 | 8 | def perfil_url | ... | ... |
plugins/oauth_client/models/oauth_client_plugin/github_auth.rb
1 | 1 | class OauthClientPlugin::GithubAuth < OauthClientPlugin::Auth |
2 | 2 | |
3 | - IMAGE_SIZE = { | |
4 | - :big => "150", | |
5 | - :thumb => "100", | |
6 | - :portrait => "64", | |
7 | - :minor => "50", | |
8 | - :icon => "18" | |
9 | - } | |
10 | - | |
11 | 3 | def image_url(size = nil) |
12 | 4 | size = IMAGE_SIZES[size] || IMAGE_SIZES[:icon] |
13 | - "https://avatars.githubusercontent.com/u/#{self.uid}?v=3&size=#{size}" | |
5 | + "#{self.external_person_image_url}&size=#{size}" | |
14 | 6 | end |
15 | 7 | end | ... | ... |
plugins/oauth_client/models/oauth_client_plugin/google_oauth2_auth.rb
0 → 100644