Skip to content

Commit

Permalink
on_validation is the decider of which persistence logic to use
Browse files Browse the repository at this point in the history
  • Loading branch information
pboling committed Mar 24, 2021
1 parent 4b8cc2d commit 03f6201
Showing 1 changed file with 6 additions and 19 deletions.
25 changes: 6 additions & 19 deletions lib/omniauth/strategies/identity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,19 @@ def registration_phase
if model.respond_to?(:column_names) && model.column_names.include?('provider')
attributes.reverse_merge!(provider: 'identity')
end
@identity = model.new(attributes)
if saving_instead_of_creating?
if validating?
@identity = model.new(attributes)
env['omniauth.identity'] = @identity
if !validating? || valid?
if valid?
@identity.save
registration_result
else
registration_failure(options[:validation_failure_message])
end
else
deprecated_registration(attributes)
@identity = model.create(attributes)
env['omniauth.identity'] = @identity
registration_result
end
end

Expand Down Expand Up @@ -141,10 +143,6 @@ def build_omniauth_registration_form(validation_message)
end
end

def saving_instead_of_creating?
@identity.respond_to?(:save) && @identity.respond_to?(:persisted?)
end

# Validates the model before it is persisted
#
# @return [truthy or falsey] :on_validation option is truthy or falsey
Expand Down Expand Up @@ -177,17 +175,6 @@ def registration_result
registration_failure(options[:registration_failure_message])
end
end

def deprecated_registration(attributes)
warn <<~CREATEDEP
[DEPRECATION] Please define '#{model.class}#save'.
Behavior based on '#{model.class}.create' will be removed in omniauth-identity v4.0.
See lib/omniauth/identity/model.rb
CREATEDEP
@identity = model.create(attributes)
env['omniauth.identity'] = @identity
registration_result
end
end
end
end

0 comments on commit 03f6201

Please sign in to comment.