Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: datetime for defaultLocale set fa #238

Merged
2 changes: 1 addition & 1 deletion src/Authentication/Authenticators/AccessTokens.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Authorization/Traits/Authorizable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
];
}

Expand Down
2 changes: 1 addition & 1 deletion src/Controllers/MagicLinkController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Models/LoginModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Models/TokenLoginModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]);
}
Expand Down
22 changes: 22 additions & 0 deletions tests/Authorization/AuthorizableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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',
]);
kenjis marked this conversation as resolved.
Show resolved Hide resolved

Locale::setDefault($currentLocale);
}
}