Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow a block to be passed to authenticate #704

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
Change the order in which things are checked
  • Loading branch information
Fustrate authored Jun 10, 2016
commit 39562a26cf1f8afaaf321b43b5670873af4d9549
16 changes: 8 additions & 8 deletions lib/sorcery/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,18 @@ def authenticate(*credentials, &block)

user = sorcery_adapter.find_by_credentials(credentials)

if user.respond_to?(:active_for_authentication?) && !user.active_for_authentication?
return authentication_response(failure: :inactive, user: user, &block)
unless user
return authentication_response(failure: :invalid_login, &block)
end

set_encryption_attributes

unless user
return authentication_response(failure: :invalid_login, &block)
unless user.valid_password?(credentials[1])
return authentication_response(user: user, failure: :invalid_password, &block)
end

if user.respond_to?(:active_for_authentication?) && !user.active_for_authentication?
return authentication_response(failure: :inactive, user: user, &block)
end

@sorcery_config.before_authenticate.each do |callback|
Expand All @@ -112,10 +116,6 @@ def authenticate(*credentials, &block)
end
end

unless user.valid_password?(credentials[1])
return authentication_response(user: user, failure: :invalid_password, &block)
end

authentication_response(user: user, return_value: user, &block)
end

Expand Down