File tree Expand file tree Collapse file tree 2 files changed +44
-0
lines changed
src/Authentication/Authenticators
tests/Authentication/Authenticators Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Original file line number Diff line number Diff line change @@ -88,6 +88,27 @@ public function attempt(array $credentials): Result
8888
8989 $ user = $ result ->extraInfo ();
9090
91+ if ($ user ->isBanned ()) {
92+ if ($ config ->recordLoginAttempt >= Auth::RECORD_LOGIN_ATTEMPT_FAILURE ) {
93+ // Record a banned login attempt.
94+ $ this ->tokenLoginModel ->recordLoginAttempt (
95+ self ::ID_TYPE_JWT ,
96+ $ credentials ['token ' ] ?? '' ,
97+ false ,
98+ $ ipAddress ,
99+ $ userAgent ,
100+ $ user ->id
101+ );
102+ }
103+
104+ $ this ->user = null ;
105+
106+ return new Result ([
107+ 'success ' => false ,
108+ 'reason ' => $ user ->getBanMessage () ?? lang ('Auth.bannedUser ' ),
109+ ]);
110+ }
111+
91112 $ this ->login ($ user );
92113
93114 if ($ config ->recordLoginAttempt === Auth::RECORD_LOGIN_ATTEMPT_ALL ) {
Original file line number Diff line number Diff line change @@ -198,6 +198,29 @@ public function testAttemptBadSignatureToken(): void
198198 ]);
199199 }
200200
201+ public function testAttemptBannedUser (): void
202+ {
203+ $ token = $ this ->generateJWT ();
204+
205+ $ this ->user ->ban ();
206+
207+ $ result = $ this ->auth ->attempt ([
208+ 'token ' => $ token ,
209+ ]);
210+
211+ $ this ->assertInstanceOf (Result::class, $ result );
212+ $ this ->assertFalse ($ result ->isOK ());
213+ $ this ->assertSame (lang ('Auth.bannedUser ' ), $ result ->reason ());
214+
215+ // The login attempt should have been recorded
216+ $ this ->seeInDatabase ('auth_token_logins ' , [
217+ 'id_type ' => JWT ::ID_TYPE_JWT ,
218+ 'identifier ' => $ token ,
219+ 'success ' => 0 ,
220+ 'user_id ' => $ this ->user ->id ,
221+ ]);
222+ }
223+
201224 public function testAttemptSuccess (): void
202225 {
203226 // Change $recordLoginAttempt in Config.
You can’t perform that action at this time.
0 commit comments