diff --git a/src/Authentication/Authenticators/AccessTokens.php b/src/Authentication/Authenticators/AccessTokens.php index 98ce6b0f0..1c6884475 100644 --- a/src/Authentication/Authenticators/AccessTokens.php +++ b/src/Authentication/Authenticators/AccessTokens.php @@ -124,7 +124,7 @@ public function check(array $credentials): Result ]); } - $token->last_used_at = Time::now()->toDateTimeString(); + $token->last_used_at = Time::now()->format('Y-m-d H:i:s'); $identityModel->save($token); // Ensure the token is set as the current token diff --git a/src/Authorization/Traits/Authorizable.php b/src/Authorization/Traits/Authorizable.php index b239a449b..3a1f8fba9 100644 --- a/src/Authorization/Traits/Authorizable.php +++ b/src/Authorization/Traits/Authorizable.php @@ -367,7 +367,7 @@ private function saveGroupsOrPermissions(string $type, $model, array $cache): vo $inserts[] = [ 'user_id' => $this->id, $type => $item, - 'created_at' => Time::now()->toDateTimeString(), + 'created_at' => Time::now()->format('Y-m-d H:i:s'), ]; } diff --git a/src/Controllers/MagicLinkController.php b/src/Controllers/MagicLinkController.php index 0dedeee7d..e06f6f44b 100644 --- a/src/Controllers/MagicLinkController.php +++ b/src/Controllers/MagicLinkController.php @@ -78,7 +78,7 @@ public function loginAction() 'user_id' => $user->id, 'type' => Session::ID_TYPE_MAGIC_LINK, 'secret' => $token, - 'expires' => Time::now()->addSeconds(setting('Auth.magicLinkLifetime'))->toDateTimeString(), + 'expires' => Time::now()->addSeconds(setting('Auth.magicLinkLifetime'))->format('Y-m-d H:i:s'), ]); // Send the user an email with the code diff --git a/src/Models/LoginModel.php b/src/Models/LoginModel.php index 654f5d428..fbaf8b113 100644 --- a/src/Models/LoginModel.php +++ b/src/Models/LoginModel.php @@ -91,7 +91,7 @@ public function fake(Generator &$faker): Login 'id_type' => Session::ID_TYPE_EMAIL_PASSWORD, 'identifier' => $faker->email, 'user_id' => null, - 'date' => Time::parse('-1 day')->toDateTimeString(), + 'date' => Time::parse('-1 day')->format('Y-m-d H:i:s'), 'success' => true, ]); } diff --git a/src/Models/TokenLoginModel.php b/src/Models/TokenLoginModel.php index 59f159bcf..fcb8dee25 100644 --- a/src/Models/TokenLoginModel.php +++ b/src/Models/TokenLoginModel.php @@ -22,7 +22,7 @@ public function fake(Generator &$faker): Login 'ip_address' => $faker->ipv4, 'identifier' => 'token: ' . random_string('crypto', 64), 'user_id' => fake(UserModel::class)->id, - 'date' => Time::parse('-1 day')->toDateTimeString(), + 'date' => Time::parse('-1 day')->format('Y-m-d H:i:s'), 'success' => true, ]); } diff --git a/tests/Authorization/AuthorizableTest.php b/tests/Authorization/AuthorizableTest.php index 34ed87a63..4a3ea3daa 100644 --- a/tests/Authorization/AuthorizableTest.php +++ b/tests/Authorization/AuthorizableTest.php @@ -6,6 +6,7 @@ use CodeIgniter\Shield\Authorization\AuthorizationException; use CodeIgniter\Shield\Models\UserModel; use CodeIgniter\Test\DatabaseTestTrait; +use Locale; use Tests\Support\FakeUser; use Tests\Support\TestCase; @@ -295,4 +296,25 @@ public function testCanCascadesToGroupsWithWildcards(): void $this->assertTrue($this->user->can('admin.access')); } + + /** + * @see https://github.com/codeigniter4/shield/pull/238 + */ + public function testCreatedAtIfDefaultLocaleSetFaWithAddGroup(): void + { + $currentLocale = Locale::getDefault(); + Locale::setDefault('fa'); + + Time::setTestNow('March 10, 2017', 'America/Chicago'); + + $this->user->addGroup('admin'); + + $this->seeInDatabase('auth_groups_users', [ + 'user_id' => $this->user->id, + 'group' => 'admin', + 'created_at' => '2017-03-10 00:00:00', + ]); + + Locale::setDefault($currentLocale); + } }