Skip to content
This repository was archived by the owner on Feb 6, 2024. It is now read-only.

Commit 4177592

Browse files
committed
Fixes the check whether a user is actually locked.
Before, the user was claimed to be locked when any CASino::User sharing the same username was locked. But a user is actually only locked, if he does not have any CASino::User left, which is unlocked. The reason herefore is, that he could have any secondary/legacy authentication providers, on which he can never login. Therefore, one of his 'alter egos' may be getting locked on any regular (and otherwise successful) login attempt and he would be locked out regardless. That is now changed, so that all CASino::Users sharing the same username must be first be in locked state before one is considered locked.
1 parent e57aa73 commit 4177592

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

app/helpers/casino/sessions_helper.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,16 @@ def sign_out
5252
end
5353

5454
def user_locked?(username)
55-
CASino::User.locked.where(username: username).any?
55+
result = CASino::User.where(username: username)
56+
57+
58+
# If we've never seen this user before, it can't be locked already.
59+
return false if result.empty?
60+
61+
# A user is only locked, if all its CASino::Users, from all providers, are locked.
62+
# Because it might be, that it is locked for one (e.g. legacy) provider, but not for another.
63+
# So it should still have the chance to login to said other provider.
64+
return result.where('locked_until IS NULL or locked_until <= :now', username: username, now: Time.now).empty?
5665
end
5766

5867
def handle_failed_login(username)

0 commit comments

Comments
 (0)