Commit 571c237b404690e423f9dc1fcb822b74e981ba14
1 parent
f9cf8cb6
Exists in
master
and in
15 other branches
oauth_client: properly save the oauth provider when signup
Showing
2 changed files
with
21 additions
and
3 deletions
Show diff stats
plugins/oauth_client/lib/ext/user.rb
... | ... | @@ -6,19 +6,32 @@ class User |
6 | 6 | has_many :oauth_providers, through: :oauth_auths, source: :provider |
7 | 7 | |
8 | 8 | after_create :activate_oauth_user |
9 | + after_create :store_oauth_providers | |
10 | + | |
11 | + def initialize_with_oauth_client(attributes = {}, options = {}) | |
12 | + @oauth_providers = attributes.delete(:oauth_providers) || [] | |
13 | + initialize_without_oauth_client(attributes, options) | |
14 | + end | |
15 | + alias_method_chain :initialize, :oauth_client | |
16 | + | |
17 | + def store_oauth_providers | |
18 | + @oauth_providers.each do |provider| | |
19 | + self.person.oauth_auths.create!(profile: self.person, provider: provider, enabled: true) | |
20 | + end | |
21 | + end | |
9 | 22 | |
10 | 23 | def activate_oauth_user |
11 | - self.activate if oauth_providers.present? | |
24 | + self.activate if oauth_providers.present? || @oauth_providers.present? | |
12 | 25 | end |
13 | 26 | |
14 | 27 | def password_required_with_oauth? |
15 | - password_required_without_oauth? && oauth_providers.empty? | |
28 | + password_required_without_oauth? && oauth_providers.empty? && @oauth_providers.blank? | |
16 | 29 | end |
17 | 30 | |
18 | 31 | alias_method_chain :password_required?, :oauth |
19 | 32 | |
20 | 33 | def make_activation_code_with_oauth |
21 | - oauth_providers.blank? ? make_activation_code_without_oauth : nil | |
34 | + @oauth_providers.blank? && oauth_providers.blank? ? make_activation_code_without_oauth : nil | |
22 | 35 | end |
23 | 36 | |
24 | 37 | alias_method_chain :make_activation_code, :oauth | ... | ... |
plugins/oauth_client/test/unit/user_test.rb
... | ... | @@ -11,6 +11,11 @@ class UserTest < ActiveSupport::TestCase |
11 | 11 | User.create!(:email => 'testoauth@example.com', :login => 'testoauth', :oauth_providers => [provider]) |
12 | 12 | end |
13 | 13 | |
14 | + should 'associate the oauth provider with the created user' do | |
15 | + user = User.create!(:email => 'testoauth@example.com', :login => 'testoauth', :oauth_providers => [provider]) | |
16 | + assert_equal user.oauth_providers.reload, [provider] | |
17 | + end | |
18 | + | |
14 | 19 | should 'password is required if there is a oauth provider' do |
15 | 20 | user = User.new(:email => 'testoauth@example.com', :login => 'testoauth') |
16 | 21 | user.save | ... | ... |