File tree Expand file tree Collapse file tree 6 files changed +21
-0
lines changed
Authentication/Authenticators Expand file tree Collapse file tree 6 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -115,6 +115,8 @@ public function check(array $credentials): Result
115115 ]);
116116 }
117117
118+ assert ($ token ->last_used_at instanceof Time || $ token ->last_used_at === null );
119+
118120 // Hasn't been used in a long time
119121 if (
120122 $ token ->last_used_at
Original file line number Diff line number Diff line change 55namespace CodeIgniter \Shield \Entities ;
66
77use CodeIgniter \Entity \Entity ;
8+ use CodeIgniter \I18n \Time ;
89
910/**
1011 * Class AccessToken
1112 *
1213 * Represents a single Personal Access Token, used
1314 * for authenticating users for an API.
15+ *
16+ * @property Time|null $last_used_at
1417 */
1518class AccessToken extends Entity
1619{
Original file line number Diff line number Diff line change 55namespace CodeIgniter \Shield \Entities ;
66
77use CodeIgniter \Database \Exceptions \DataException ;
8+ use CodeIgniter \I18n \Time ;
89use CodeIgniter \Shield \Authentication \Authenticators \Session ;
910use CodeIgniter \Shield \Authentication \Traits \HasAccessTokens ;
1011use CodeIgniter \Shield \Authorization \Traits \Authorizable ;
1112use CodeIgniter \Shield \Models \LoginModel ;
1213use CodeIgniter \Shield \Models \UserIdentityModel ;
1314
15+ /**
16+ * @property string|null $email
17+ * @property UserIdentity[]|null $identities
18+ * @property Time|null $last_active
19+ * @property string|null $password
20+ * @property string|null $password_hash
21+ */
1422class User extends Entity
1523{
1624 use Authorizable;
Original file line number Diff line number Diff line change 44
55namespace CodeIgniter \Shield \Entities ;
66
7+ use CodeIgniter \I18n \Time ;
78use CodeIgniter \Shield \Authentication \Passwords ;
89
910/**
1920 * OAUTH or JWT tokens, etc. A user can have multiple of each,
2021 * though a Authenticator may want to enforce only one exists for that
2122 * user, like a password.
23+ *
24+ * @property Time|null $last_used_at
2225 */
2326class UserIdentity extends Entity
2427{
Original file line number Diff line number Diff line change 55namespace CodeIgniter \Shield \Models ;
66
77use CodeIgniter \Database \Exceptions \DataException ;
8+ use CodeIgniter \I18n \Time ;
89use CodeIgniter \Model ;
910use CodeIgniter \Shield \Authentication \Authenticators \Session ;
1011use CodeIgniter \Shield \Entities \User ;
@@ -325,6 +326,8 @@ protected function saveEmailIdentity(array $data): array
325326 */
326327 public function updateActiveDate (User $ user ): void
327328 {
329+ assert ($ user ->last_active instanceof Time);
330+
328331 // Safe date string for database
329332 $ last_active = $ user ->last_active ->format ('Y-m-d H:i:s ' );
330333
Original file line number Diff line number Diff line change @@ -89,6 +89,7 @@ public function testLoginActionEmailSuccess(): void
8989 ]);
9090 // Last Used date should have been set
9191 $ identity = $ this ->user ->getEmailIdentity ();
92+ $ this ->assertInstanceOf (Time::class, $ identity ->last_used_at );
9293 $ this ->assertSame (Time::now ()->getTimestamp (), $ identity ->last_used_at ->getTimestamp ());
9394
9495 // Session should have `logged_in` value with user's id
@@ -151,6 +152,7 @@ public function testLoginActionUsernameSuccess(): void
151152 ]);
152153 // Last Used date should have been set
153154 $ identity = $ this ->user ->getEmailIdentity ();
155+ $ this ->assertInstanceOf (Time::class, $ identity ->last_used_at );
154156 $ this ->assertSame (Time::now ()->getTimestamp (), $ identity ->last_used_at ->getTimestamp ());
155157
156158 // Session should have `logged_in` value with user's id
You can’t perform that action at this time.
0 commit comments