File tree Expand file tree Collapse file tree 2 files changed +20
-11
lines changed
Expand file tree Collapse file tree 2 files changed +20
-11
lines changed Original file line number Diff line number Diff line change @@ -224,21 +224,13 @@ public function getPasswordHash(): ?string
224224 }
225225
226226 /**
227- * Returns the last login information for this
228- * user as
227+ * Returns the last login information for this user as
229228 */
230229 public function lastLogin (bool $ allowFailed = false ): ?Login
231230 {
231+ /** @var LoginModel $logins */
232232 $ logins = model (LoginModel::class);
233233
234- if (! $ allowFailed ) {
235- $ logins ->where ('success ' , 1 )
236- ->where ('user_id ' , $ this ->attributes ['id ' ] ?? null );
237- }
238-
239- return $ logins
240- ->where ('identifier ' , $ this ->getEmail ())
241- ->orderBy ('date ' , 'desc ' )
242- ->first ();
234+ return $ logins ->lastLogin ($ this , $ allowFailed );
243235 }
244236}
Original file line number Diff line number Diff line change 55use CodeIgniter \I18n \Time ;
66use CodeIgniter \Model ;
77use CodeIgniter \Shield \Entities \Login ;
8+ use CodeIgniter \Shield \Entities \User ;
89use Exception ;
910use Faker \Generator ;
1011
@@ -57,6 +58,22 @@ public function recordLoginAttempt(
5758 $ this ->checkQueryReturn ($ return );
5859 }
5960
61+ /**
62+ * Returns the last login information for the user
63+ */
64+ public function lastLogin (User $ user , bool $ allowFailed = false ): ?Login
65+ {
66+ if (! $ allowFailed ) {
67+ $ this ->where ('success ' , 1 )
68+ ->where ('user_id ' , $ user ->id );
69+ }
70+
71+ return $ this
72+ ->where ('identifier ' , $ user ->email )
73+ ->orderBy ('date ' , 'desc ' )
74+ ->first ();
75+ }
76+
6077 /**
6178 * Generate a fake login for testing
6279 *
You can’t perform that action at this time.
0 commit comments