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

Add failure reason argument for after_failed_login callback #175

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/sorcery/controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def login(*credentials)

user_class.authenticate(*credentials) do |user, failure_reason|
if failure_reason
after_failed_login!(credentials)
after_failed_login!(credentials, failure_reason)

yield(user, failure_reason) if block_given?

Expand Down Expand Up @@ -143,8 +143,8 @@ def after_login!(user, credentials = [])
Config.after_login.each { |c| send(c, user, credentials) }
end

def after_failed_login!(credentials)
Config.after_failed_login.each { |c| send(c, credentials) }
def after_failed_login!(credentials, failure_reason)
Config.after_failed_login.each { |c| send(c, credentials, failure_reason) }
end

def before_logout!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module InstanceMethods

# Increments the failed logins counter on every failed login.
# Runs as a hook after a failed login.
def update_failed_logins_count!(credentials)
def update_failed_logins_count!(credentials, _failure_reason)
songhuangcn marked this conversation as resolved.
Show resolved Hide resolved
user = user_class.sorcery_adapter.find_by_credentials(credentials)
user.register_failed_login! if user
end
Expand Down