Skip to content

Commit 03f6201

Browse files
committed
on_validation is the decider of which persistence logic to use
1 parent 4b8cc2d commit 03f6201

File tree

1 file changed

+6
-19
lines changed

1 file changed

+6
-19
lines changed

lib/omniauth/strategies/identity.rb

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,19 @@ def registration_phase
7676
if model.respond_to?(:column_names) && model.column_names.include?('provider')
7777
attributes.reverse_merge!(provider: 'identity')
7878
end
79-
@identity = model.new(attributes)
80-
if saving_instead_of_creating?
79+
if validating?
80+
@identity = model.new(attributes)
8181
env['omniauth.identity'] = @identity
82-
if !validating? || valid?
82+
if valid?
8383
@identity.save
8484
registration_result
8585
else
8686
registration_failure(options[:validation_failure_message])
8787
end
8888
else
89-
deprecated_registration(attributes)
89+
@identity = model.create(attributes)
90+
env['omniauth.identity'] = @identity
91+
registration_result
9092
end
9193
end
9294

@@ -141,10 +143,6 @@ def build_omniauth_registration_form(validation_message)
141143
end
142144
end
143145

144-
def saving_instead_of_creating?
145-
@identity.respond_to?(:save) && @identity.respond_to?(:persisted?)
146-
end
147-
148146
# Validates the model before it is persisted
149147
#
150148
# @return [truthy or falsey] :on_validation option is truthy or falsey
@@ -177,17 +175,6 @@ def registration_result
177175
registration_failure(options[:registration_failure_message])
178176
end
179177
end
180-
181-
def deprecated_registration(attributes)
182-
warn <<~CREATEDEP
183-
[DEPRECATION] Please define '#{model.class}#save'.
184-
Behavior based on '#{model.class}.create' will be removed in omniauth-identity v4.0.
185-
See lib/omniauth/identity/model.rb
186-
CREATEDEP
187-
@identity = model.create(attributes)
188-
env['omniauth.identity'] = @identity
189-
registration_result
190-
end
191178
end
192179
end
193180
end

0 commit comments

Comments
 (0)