Empact-authlogic_rpx 1.1.8 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,90 +1,68 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{Empact-authlogic_rpx}
8
- s.version = "1.1.8"
8
+ s.version = "2.0.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Paul Gallagher / tardate"]
12
- s.date = %q{2010-07-03}
11
+ s.authors = [%q{Paul Gallagher / tardate}]
12
+ s.date = %q{2011-09-12}
13
13
  s.description = %q{Authlogic extension/plugin that provides RPX (rpxnow.com) authentication support}
14
14
  s.email = %q{gallagher.paul@gmail.com}
15
15
  s.extra_rdoc_files = [
16
16
  "README.rdoc"
17
17
  ]
18
18
  s.files = [
19
- ".gitignore",
20
- "CHANGELOG.rdoc",
21
- "Empact-authlogic_rpx.gemspec",
22
- "MIT-LICENSE",
23
- "README.rdoc",
24
- "Rakefile",
25
- "VERSION",
26
- "generators/add_authlogic_rpx_migration/USAGE",
27
- "generators/add_authlogic_rpx_migration/add_authlogic_rpx_migration_generator.rb",
28
- "generators/add_authlogic_rpx_migration/templates/migration_internal_mapping.rb",
29
- "generators/add_authlogic_rpx_migration/templates/migration_no_mapping.rb",
30
- "init.rb",
31
- "lib/authlogic_rpx.rb",
32
- "lib/authlogic_rpx/acts_as_authentic.rb",
33
- "lib/authlogic_rpx/helper.rb",
34
- "lib/authlogic_rpx/rpx_identifier.rb",
35
- "lib/authlogic_rpx/session.rb",
36
- "lib/authlogic_rpx/session/validation.rb",
37
- "lib/authlogic_rpx/version.rb",
38
- "rails/init.rb",
39
- "test/fixtures/rpxresponses.yml",
40
- "test/fixtures/users.yml",
41
- "test/integration/basic_authentication_and_registration_test.rb",
42
- "test/integration/internal_mapping/basic_authentication_and_registration_test.rb",
43
- "test/integration/internal_mapping/settings_test.rb",
44
- "test/integration/no_mapping/basic_authentication_and_registration_test.rb",
45
- "test/integration/no_mapping/settings_test.rb",
46
- "test/libs/ext_test_unit.rb",
47
- "test/libs/mock_rpx_now.rb",
48
- "test/libs/rails_trickery.rb",
49
- "test/libs/rpxresponse.rb",
50
- "test/libs/user.rb",
51
- "test/libs/user_session.rb",
52
- "test/test_helper.rb",
53
- "test/test_internal_mapping_helper.rb",
54
- "test/unit/acts_as_authentic_settings_test.rb",
55
- "test/unit/helpers_test.rb",
56
- "test/unit/session_settings_test.rb",
57
- "test/unit/session_validation_test.rb",
58
- "test/unit/verify_rpx_mock_test.rb"
19
+ "CHANGELOG.rdoc",
20
+ "Empact-authlogic_rpx.gemspec",
21
+ "MIT-LICENSE",
22
+ "README.rdoc",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "generators/add_authlogic_rpx_migration/USAGE",
26
+ "generators/add_authlogic_rpx_migration/add_authlogic_rpx_migration_generator.rb",
27
+ "generators/add_authlogic_rpx_migration/templates/migration_internal_mapping.rb",
28
+ "generators/add_authlogic_rpx_migration/templates/migration_no_mapping.rb",
29
+ "init.rb",
30
+ "lib/authlogic_rpx.rb",
31
+ "lib/authlogic_rpx/acts_as_authentic.rb",
32
+ "lib/authlogic_rpx/helper.rb",
33
+ "lib/authlogic_rpx/railtie.rb",
34
+ "lib/authlogic_rpx/rpx_identifier.rb",
35
+ "lib/authlogic_rpx/session.rb",
36
+ "lib/authlogic_rpx/session/validation.rb",
37
+ "lib/authlogic_rpx/version.rb",
38
+ "rails/init.rb",
39
+ "test/fixtures/rpxresponses.yml",
40
+ "test/fixtures/users.yml",
41
+ "test/integration/basic_authentication_and_registration_test.rb",
42
+ "test/integration/internal_mapping/basic_authentication_and_registration_test.rb",
43
+ "test/integration/internal_mapping/settings_test.rb",
44
+ "test/integration/no_mapping/basic_authentication_and_registration_test.rb",
45
+ "test/integration/no_mapping/settings_test.rb",
46
+ "test/libs/ext_test_unit.rb",
47
+ "test/libs/mock_rpx_now.rb",
48
+ "test/libs/rails_trickery.rb",
49
+ "test/libs/rpxresponse.rb",
50
+ "test/libs/user.rb",
51
+ "test/libs/user_session.rb",
52
+ "test/test_helper.rb",
53
+ "test/test_internal_mapping_helper.rb",
54
+ "test/unit/acts_as_authentic_settings_test.rb",
55
+ "test/unit/helpers_test.rb",
56
+ "test/unit/session_settings_test.rb",
57
+ "test/unit/session_validation_test.rb",
58
+ "test/unit/verify_rpx_mock_test.rb"
59
59
  ]
60
60
  s.homepage = %q{http://github.com/tardate/authlogic_rpx}
61
- s.rdoc_options = ["--charset=UTF-8"]
62
- s.require_paths = ["lib"]
63
- s.rubygems_version = %q{1.3.7}
61
+ s.require_paths = [%q{lib}]
62
+ s.rubygems_version = %q{1.8.8}
64
63
  s.summary = %q{Authlogic plug-in for RPX support}
65
- s.test_files = [
66
- "test/integration/basic_authentication_and_registration_test.rb",
67
- "test/integration/internal_mapping/basic_authentication_and_registration_test.rb",
68
- "test/integration/internal_mapping/settings_test.rb",
69
- "test/integration/no_mapping/basic_authentication_and_registration_test.rb",
70
- "test/integration/no_mapping/settings_test.rb",
71
- "test/libs/ext_test_unit.rb",
72
- "test/libs/mock_rpx_now.rb",
73
- "test/libs/rails_trickery.rb",
74
- "test/libs/rpxresponse.rb",
75
- "test/libs/user.rb",
76
- "test/libs/user_session.rb",
77
- "test/test_helper.rb",
78
- "test/test_internal_mapping_helper.rb",
79
- "test/unit/acts_as_authentic_settings_test.rb",
80
- "test/unit/helpers_test.rb",
81
- "test/unit/session_settings_test.rb",
82
- "test/unit/session_validation_test.rb",
83
- "test/unit/verify_rpx_mock_test.rb"
84
- ]
85
64
 
86
65
  if s.respond_to? :specification_version then
87
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
88
66
  s.specification_version = 3
89
67
 
90
68
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.8
1
+ 2.0.0
@@ -6,9 +6,10 @@ require "authlogic_rpx/session/validation"
6
6
  require "authlogic_rpx/helper"
7
7
  require "authlogic_rpx/rpx_identifier"
8
8
 
9
- ActiveRecord::Base.send(:include, AuthlogicRpx::ActsAsAuthentic)
10
9
  Authlogic::Session::Base.class_eval do
11
10
  include AuthlogicRpx::Session::Validation
12
11
  include AuthlogicRpx::Session
13
12
  end
14
- ActionController::Base.helper AuthlogicRpx::Helper
13
+ ActionController::Base.helper AuthlogicRpx::Helper
14
+
15
+ require 'authlogic_rpx/railtie' if defined?(Rails)
@@ -1,276 +1,272 @@
1
1
  # This module is responsible for adding RPX functionality to Authlogic. Checkout the README for more info and please
2
2
  # see the sub modules for detailed documentation.
3
3
  module AuthlogicRpx
4
- # This module is responsible for adding in the RPX functionality to your models. It hooks itself into the
5
- # acts_as_authentic method provided by Authlogic.
6
- module ActsAsAuthentic
7
- # Adds in the neccesary modules for acts_as_authentic to include and also disabled password validation if
8
- # RPX is being used.
9
- def self.included(klass)
10
- klass.class_eval do
11
- extend Config
12
- add_acts_as_authentic_module(Methods, :prepend)
13
- end
14
- end
15
-
16
- class GeneralError < StandardError
17
- end
18
- class ConfigurationError < StandardError
19
- end
20
-
21
- module Config
22
-
23
- # account_merge_enabled is used to enable merging of accounts.
24
- #
25
- # * <tt>Default:</tt> false
26
- # * <tt>Accepts:</tt> boolean
27
- def account_merge_enabled(value=false)
28
- account_merge_enabled_value(value)
29
- end
30
- def account_merge_enabled_value(value=nil)
31
- rw_config(:account_merge_enabled,value,false)
32
- end
33
- alias_method :account_merge_enabled=,:account_merge_enabled
34
-
35
-
36
- # account_mapping_mode is used to explicitly set/override the mapping behaviour.
37
- #
38
- # * <tt>Default:</tt> :auto
39
- # * <tt>Accepts:</tt> :auto, :none, :internal, :rpxnow
40
- def account_mapping_mode(value=:auto)
41
- account_mapping_mode_value(value)
42
- end
43
- def account_mapping_mode_value(value=nil)
44
- raise AuthlogicRpx::ActsAsAuthentic::ConfigurationError.new unless value.nil? || [:auto,:none,:internal].include?( value )
45
- rw_config(:account_mapping_mode,value,:auto)
46
- end
47
- alias_method :account_mapping_mode=,:account_mapping_mode
48
-
49
- # returns the actual account mapping mode in use - resolves :auto to actual mechanism
50
- #
51
- attr_writer :account_mapping_mode_used
52
- def account_mapping_mode_used
53
- @account_mapping_mode_used ||= (
54
- account_mapping_mode_value == :auto ?
55
- ( RPXIdentifier.table_exists? ?
56
- :internal :
57
- ( self.column_names.include?("rpx_identifier") ? :none : AuthlogicRpx::ActsAsAuthentic::ConfigurationError.new )
58
- ) :
59
- account_mapping_mode_value
60
- )
61
- end
62
-
63
-
64
- # determines if no account mapping is supported (the only behaviour in authlogic_rpx v1.0.4)
65
- def using_no_mapping?
66
- account_mapping_mode_used == :none
67
- end
68
- # determines if internal account mapping is enabled (behaviour added in authlogic_rpx v1.1.0)
69
- def using_internal_mapping?
70
- account_mapping_mode_used == :internal
71
- end
72
- # determines if rpxnow account mapping is enabled (currently not implemented)
73
- def using_rpx_mapping?
74
- account_mapping_mode_used == :rpxnow
75
- end
76
-
77
- end
78
-
79
- module Methods
80
-
81
- # Set up some simple validations
82
- def self.included(klass)
83
- klass.class_eval do
84
-
85
- case
86
- when using_no_mapping?
87
- alias_method :using_rpx?, :using_rpx__nomap?
88
- alias_method :add_rpx_identifier, :add_rpx_identifier__nomap
89
- alias_method :identified_by?, :identified_by__nomap?
90
- alias_method :merge_user_id, :merge_user_id__nomap
91
-
92
- # Uses default find_by_rpx_identifier class method
93
-
94
- # Add an rpx_identifier collection method
95
- def rpx_identifiers
96
- [{ :identifier => rpx_identifier, :provider_name => "Unknown" }]
97
- end
98
-
99
- when using_internal_mapping?
100
- alias_method :using_rpx?, :using_rpx__internal?
101
- alias_method :add_rpx_identifier, :add_rpx_identifier__internal
102
- alias_method :identified_by?, :identified_by__internal?
103
- alias_method :merge_user_id, :merge_user_id__internal
4
+ # This module is responsible for adding in the RPX functionality to your models. It hooks itself into the
5
+ # acts_as_authentic method provided by Authlogic.
6
+ module ActsAsAuthentic
7
+ # Adds in the neccesary modules for acts_as_authentic to include and also disabled password validation if
8
+ # RPX is being used.
9
+ def self.included(klass)
10
+ klass.class_eval do
11
+ extend Config
12
+ add_acts_as_authentic_module(Methods, :prepend)
13
+ end
14
+ end
15
+
16
+ class GeneralError < StandardError
17
+ end
18
+ class ConfigurationError < StandardError
19
+ end
20
+
21
+ module Config
22
+
23
+ # account_merge_enabled is used to enable merging of accounts.
24
+ #
25
+ # * <tt>Default:</tt> false
26
+ # * <tt>Accepts:</tt> boolean
27
+ def account_merge_enabled(value=false)
28
+ account_merge_enabled_value(value)
29
+ end
30
+ def account_merge_enabled_value(value=nil)
31
+ rw_config(:account_merge_enabled,value,false)
32
+ end
33
+ alias_method :account_merge_enabled=,:account_merge_enabled
34
+
35
+
36
+ # account_mapping_mode is used to explicitly set/override the mapping behaviour.
37
+ #
38
+ # * <tt>Default:</tt> :auto
39
+ # * <tt>Accepts:</tt> :auto, :none, :internal, :rpxnow
40
+ def account_mapping_mode(value=:auto)
41
+ account_mapping_mode_value(value)
42
+ end
43
+ def account_mapping_mode_value(value=nil)
44
+ raise AuthlogicRpx::ActsAsAuthentic::ConfigurationError.new unless value.nil? || [:auto,:none,:internal].include?( value )
45
+ rw_config(:account_mapping_mode,value,:auto)
46
+ end
47
+ alias_method :account_mapping_mode=,:account_mapping_mode
48
+
49
+ # returns the actual account mapping mode in use - resolves :auto to actual mechanism
50
+ #
51
+ attr_writer :account_mapping_mode_used
52
+ def account_mapping_mode_used
53
+ @account_mapping_mode_used ||=
54
+ if account_mapping_mode_value != :auto
55
+ account_mapping_mode_value
56
+ elsif RPXIdentifier.table_exists?
57
+ :internal
58
+ elsif self.column_names.include?("rpx_identifier")
59
+ :none
60
+ else
61
+ AuthlogicRpx::ActsAsAuthentic::ConfigurationError.new
62
+ end
63
+ end
64
+
65
+
66
+ # determines if no account mapping is supported (the only behaviour in authlogic_rpx v1.0.4)
67
+ def using_no_mapping?
68
+ account_mapping_mode_used == :none
69
+ end
70
+ # determines if internal account mapping is enabled (behaviour added in authlogic_rpx v1.1.0)
71
+ def using_internal_mapping?
72
+ account_mapping_mode_used == :internal
73
+ end
74
+ # determines if rpxnow account mapping is enabled (currently not implemented)
75
+ def using_rpx_mapping?
76
+ account_mapping_mode_used == :rpxnow
77
+ end
78
+
79
+ end
80
+
81
+ module Methods
82
+
83
+ # Set up some simple validations
84
+ def self.included(klass)
85
+ klass.class_eval do
86
+
87
+ case
88
+ when using_no_mapping?
89
+ alias_method :using_rpx?, :using_rpx__nomap?
90
+ alias_method :add_rpx_identifier, :add_rpx_identifier__nomap
91
+ alias_method :identified_by?, :identified_by__nomap?
92
+ alias_method :merge_user_id, :merge_user_id__nomap
93
+
94
+ # Uses default find_by_rpx_identifier class method
95
+
96
+ # Add an rpx_identifier collection method
97
+ def rpx_identifiers
98
+ [{ :identifier => rpx_identifier, :provider_name => "Unknown" }]
99
+ end
100
+
101
+ when using_internal_mapping?
102
+ alias_method :using_rpx?, :using_rpx__internal?
103
+ alias_method :add_rpx_identifier, :add_rpx_identifier__internal
104
+ alias_method :identified_by?, :identified_by__internal?
105
+ alias_method :merge_user_id, :merge_user_id__internal
104
106
  has_many :rpx_identifiers, :class_name => 'RPXIdentifier', :validate => false, :dependent => :destroy
105
-
106
- # Add custom find_by_rpx_identifier class method
107
- #
108
- def self.find_by_rpx_identifier(id)
109
- identifier = RPXIdentifier.find_by_identifier(id)
110
- if identifier.nil?
111
- if self.column_names.include? 'rpx_identifier'
112
- # check for authentication using <=1.0.4, migrate identifier to rpx_identifiers table
113
- user = self.find( :first, :conditions => [ "rpx_identifier = ?", id ] )
114
- unless user.nil?
115
- user.add_rpx_identifier( id, 'Unknown' )
116
- end
117
- return user
118
- else
119
- return nil
120
- end
121
- else
122
- identifier.send( self.class_name.downcase )
123
- end
124
- end
125
-
107
+
108
+ # Add custom find_by_rpx_identifier class method
109
+ #
110
+ def self.find_by_rpx_identifier(id)
111
+ if identifier = RPXIdentifier.find_by_identifier(id)
112
+ identifier.send(self.model_name.downcase )
113
+ elsif self.column_names.include? 'rpx_identifier'
114
+ # check for authentication using <=1.0.4, migrate identifier to rpx_identifiers table
115
+ if user = self.find( :first, :conditions => [ "rpx_identifier = ?", id ] )
116
+ user.add_rpx_identifier( id, 'Unknown' )
117
+ end
118
+ user
119
+ end
120
+ end
121
+
126
122
  else
127
123
  raise AuthlogicRpx::ActsAsAuthentic::ConfigurationError.new( "invalid or unsupported account_mapping_mode" )
128
124
  end
129
125
 
130
- validates_length_of_password_field_options validates_length_of_password_field_options.merge(:if => :validate_password_with_rpx?)
131
- validates_confirmation_of_password_field_options validates_confirmation_of_password_field_options.merge(:if => :validate_password_with_rpx?)
132
- validates_length_of_password_confirmation_field_options validates_length_of_password_confirmation_field_options.merge(:if => :validate_password_with_rpx?)
133
-
134
- before_validation :adding_rpx_identifier
135
- end
126
+ validates_length_of_password_field_options validates_length_of_password_field_options.merge(:if => :validate_password_with_rpx?)
127
+ validates_confirmation_of_password_field_options validates_confirmation_of_password_field_options.merge(:if => :validate_password_with_rpx?)
128
+ validates_length_of_password_confirmation_field_options validates_length_of_password_confirmation_field_options.merge(:if => :validate_password_with_rpx?)
129
+
130
+ before_validation :adding_rpx_identifier
131
+ end
136
132
 
137
133
  # add relations and validation to RPXIdentifier based on the actual user model class name used
138
134
  #
139
- RPXIdentifier.class_eval do
140
- belongs_to klass.name.downcase.to_sym
141
- validates_presence_of "#{klass.name.downcase}_id".to_sym
142
- end
143
- end
144
-
145
- # test if account it using RPX authentication
146
- # aliased to using_rpx based on authlogic_rpx configuration mode
147
- def using_rpx__nomap?
148
- !rpx_identifier.blank?
149
- end
150
- def using_rpx__internal?
151
- !rpx_identifiers.empty?
152
- end
153
-
154
- # test if account it using normal password authentication
155
- def using_password?
156
- !send(crypted_password_field).blank?
157
- end
135
+ RPXIdentifier.class_eval do
136
+ belongs_to klass.name.downcase.to_sym
137
+ validates_presence_of "#{klass.name.downcase}_id".to_sym
138
+ end
139
+ end
140
+
141
+ # test if account it using RPX authentication
142
+ # aliased to using_rpx based on authlogic_rpx configuration mode
143
+ def using_rpx__nomap?
144
+ !rpx_identifier.blank?
145
+ end
146
+ def using_rpx__internal?
147
+ !rpx_identifiers.empty?
148
+ end
149
+
150
+ # test if account it using normal password authentication
151
+ def using_password?
152
+ !send(crypted_password_field).blank?
153
+ end
158
154
 
159
155
  # adds RPX identification to the instance.
160
156
  # Abstracts how the RPX identifier is added to allow for multiplicity of underlying implementations
161
- # aliased to add_rpx_identifier based on authlogic_rpx configuration mode
157
+ # aliased to add_rpx_identifier based on authlogic_rpx configuration mode
162
158
  def add_rpx_identifier__nomap( rpx_id, rpx_provider_name )
163
- self.rpx_identifier = rpx_id
164
- #TODO: make rpx_provider_name a std param?
159
+ self.rpx_identifier = rpx_id
160
+ #TODO: make rpx_provider_name a std param?
165
161
  end
166
162
  def add_rpx_identifier__internal( rpx_id, rpx_provider_name )
167
- self.rpx_identifiers.build(:identifier => rpx_id, :provider_name => rpx_provider_name )
163
+ self.rpx_identifiers.build(:identifier => rpx_id, :provider_name => rpx_provider_name )
168
164
  end
169
-
165
+
170
166
  # Checks if given identifier is an identity for this account
171
167
  # aliased to identified_by based on authlogic_rpx configuration mode
172
- def identified_by__nomap?( id )
173
- self.rpx_identifier == id
174
- end
175
- def identified_by__internal?( id )
176
- self.rpx_identifiers.find_by_identifier( id )
177
- end
178
-
179
- private
180
-
181
- # tests if password authentication should be checked: if rpx is enabled (but not used by this user)
182
- def validate_password_with_rpx?
183
- !using_rpx? && require_password?
184
- end
185
-
186
- # determines if account merging is enabled; delegates to class method
187
- def account_merge_enabled?
188
- self.class.account_merge_enabled_value
189
- end
190
-
191
- # hook for adding RPX identifier to an existing account. This is invoked prior to model validation.
192
- # RPX information is plucked from the controller session object (where it was placed by the session model as a result
193
- # of the RPX callback)
194
- # The minimal action taken is to add an RPXIdentifier object to the user.
195
- #
196
- # This procedure chains to the map_added_rpx_data, which may be over-ridden in your project to perform
197
- # additional mapping of RPX information to the user model as may be desired.
198
- #
199
- def adding_rpx_identifier
200
- return true unless session_class && session_class.controller
201
-
202
- added_rpx_data = session_class.controller.session['added_rpx_data']
203
- unless added_rpx_data.blank?
204
- session_class.controller.session['added_rpx_data'] = nil
205
- rpx_id = added_rpx_data['profile']['identifier']
206
- rpx_provider_name = added_rpx_data['profile']['providerName']
207
-
208
- unless self.identified_by?( rpx_id )
209
- # identifier not already set for this user..
210
-
211
- another_user = self.class.find_by_rpx_identifier( rpx_id )
212
- if another_user
213
- return false unless account_merge_enabled?
214
- # another user already has this id registered..
215
-
216
- # merge all IDs from another_user to self, with application callbacks before/after
217
- before_merge_rpx_data( another_user, self )
218
- merge_user_id another_user
219
- after_merge_rpx_data( another_user, self )
220
-
221
- else
222
- self.add_rpx_identifier( rpx_id, rpx_provider_name )
223
- end
224
- end
225
-
226
- map_added_rpx_data( added_rpx_data )
227
- end
228
- end
229
-
230
- # merge_user_id is an internal method used to merge the actual RPX identifiers
231
- # aliased to merge_user_id based on authlogic_rpx configuration mode
232
- def merge_user_id__nomap( from_user )
233
- self.rpx_identifier = from_user.rpx_identifier
234
- from_user.rpx_identifier = nil
235
- from_user.save
236
- from_user.reload
237
- end
238
- def merge_user_id__internal( from_user )
239
- self.rpx_identifiers << from_user.rpx_identifiers
240
- from_user.reload
241
- end
242
-
243
-
244
- # map_added_rpx_data maps additional fields from the RPX response into the user object during the "add RPX to existing account" process.
245
- # Override this in your user model to perform field mapping as may be desired
246
- # See https://rpxnow.com/docs#profile_data for the definition of available attributes
247
- #
248
- # "self" at this point is the user model. Map details as appropriate from the rpx_data structure provided.
249
- #
250
- def map_added_rpx_data( rpx_data )
251
-
252
- end
253
-
254
- # before_merge_rpx_data provides a hook for application developers to perform data migration prior to the merging of user accounts.
255
- # This method is called just before authlogic_rpx merges the user registration for 'from_user' into 'to_user'
256
- # Authlogic_RPX is responsible for merging registration data.
257
- #
258
- # By default, it does not merge any other details (e.g. application data ownership)
259
- #
260
- def before_merge_rpx_data( from_user, to_user )
261
-
262
- end
263
-
264
- # after_merge_rpx_data provides a hook for application developers to perform account clean-up after authlogic_rpx has
265
- # migrated registration details.
266
- #
267
- # By default, does nothing. It could, for example, be used to delete or disable the 'from_user' account
268
- #
269
- def after_merge_rpx_data( from_user, to_user )
270
-
271
- end
272
-
273
-
274
- end
275
- end
168
+ def identified_by__nomap?( id )
169
+ self.rpx_identifier == id
170
+ end
171
+ def identified_by__internal?( id )
172
+ self.rpx_identifiers.find_by_identifier( id )
173
+ end
174
+
175
+ private
176
+
177
+ # tests if password authentication should be checked: if rpx is enabled (but not used by this user)
178
+ def validate_password_with_rpx?
179
+ !using_rpx? && require_password?
180
+ end
181
+
182
+ # determines if account merging is enabled; delegates to class method
183
+ def account_merge_enabled?
184
+ self.class.account_merge_enabled_value
185
+ end
186
+
187
+ # hook for adding RPX identifier to an existing account. This is invoked prior to model validation.
188
+ # RPX information is plucked from the controller session object (where it was placed by the session model as a result
189
+ # of the RPX callback)
190
+ # The minimal action taken is to add an RPXIdentifier object to the user.
191
+ #
192
+ # This procedure chains to the map_added_rpx_data, which may be over-ridden in your project to perform
193
+ # additional mapping of RPX information to the user model as may be desired.
194
+ #
195
+ def adding_rpx_identifier
196
+ return true unless session_class && session_class.controller
197
+
198
+ added_rpx_data = session_class.controller.session['added_rpx_data']
199
+ unless added_rpx_data.blank?
200
+ session_class.controller.session['added_rpx_data'] = nil
201
+ rpx_id = added_rpx_data['profile']['identifier']
202
+ rpx_provider_name = added_rpx_data['profile']['providerName']
203
+
204
+ unless self.identified_by?( rpx_id )
205
+ # identifier not already set for this user..
206
+
207
+ another_user = self.class.find_by_rpx_identifier( rpx_id )
208
+ if another_user
209
+ return false unless account_merge_enabled?
210
+ # another user already has this id registered..
211
+
212
+ # merge all IDs from another_user to self, with application callbacks before/after
213
+ before_merge_rpx_data( another_user, self )
214
+ merge_user_id another_user
215
+ after_merge_rpx_data( another_user, self )
216
+
217
+ else
218
+ self.add_rpx_identifier( rpx_id, rpx_provider_name )
219
+ end
220
+ end
221
+
222
+ map_added_rpx_data( added_rpx_data )
223
+ end
224
+ end
225
+
226
+ # merge_user_id is an internal method used to merge the actual RPX identifiers
227
+ # aliased to merge_user_id based on authlogic_rpx configuration mode
228
+ def merge_user_id__nomap( from_user )
229
+ self.rpx_identifier = from_user.rpx_identifier
230
+ from_user.rpx_identifier = nil
231
+ from_user.save
232
+ from_user.reload
233
+ end
234
+ def merge_user_id__internal( from_user )
235
+ self.rpx_identifiers << from_user.rpx_identifiers
236
+ from_user.reload
237
+ end
238
+
239
+
240
+ # map_added_rpx_data maps additional fields from the RPX response into the user object during the "add RPX to existing account" process.
241
+ # Override this in your user model to perform field mapping as may be desired
242
+ # See https://rpxnow.com/docs#profile_data for the definition of available attributes
243
+ #
244
+ # "self" at this point is the user model. Map details as appropriate from the rpx_data structure provided.
245
+ #
246
+ def map_added_rpx_data( rpx_data )
247
+
248
+ end
249
+
250
+ # before_merge_rpx_data provides a hook for application developers to perform data migration prior to the merging of user accounts.
251
+ # This method is called just before authlogic_rpx merges the user registration for 'from_user' into 'to_user'
252
+ # Authlogic_RPX is responsible for merging registration data.
253
+ #
254
+ # By default, it does not merge any other details (e.g. application data ownership)
255
+ #
256
+ def before_merge_rpx_data( from_user, to_user )
257
+
258
+ end
259
+
260
+ # after_merge_rpx_data provides a hook for application developers to perform account clean-up after authlogic_rpx has
261
+ # migrated registration details.
262
+ #
263
+ # By default, does nothing. It could, for example, be used to delete or disable the 'from_user' account
264
+ #
265
+ def after_merge_rpx_data( from_user, to_user )
266
+
267
+ end
268
+
269
+
270
+ end
271
+ end
276
272
  end