Skip to content

Commit

Permalink
progress refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
jturbide committed Dec 1, 2024
1 parent a568b1d commit 4e12737
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
29 changes: 18 additions & 11 deletions src/Identity.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,23 @@ public function getJwt(bool $refresh = false): array
$token ??= $this->helper->random(Random::RANDOM_ALNUM, rand(111, 222));
$newToken = $refresh ? $this->helper->random(Random::RANDOM_ALNUM, rand(111, 222)) : $token;

// retrieve or create a new session
$sessionClass = $this->getSessionClass();
$session = $this->getSession($key, $token) ?? new $sessionClass();
assert($session instanceof SessionInterface);

// save the key token into the store (database or session)
$session->setKey($key);
$session->setToken($session->hash($key . $newToken));
$session->setDate(date('Y-m-d H:i:s'));
$saved = $session->save();
$adapter = $this->config->path('identity.adapter') ?: 'database';
// if ($adapter === 'database') {
// retrieve or create a new session
$sessionClass = $this->getSessionClass();
$session = $this->getSession($key, $token) ?? new $sessionClass();
assert($session instanceof SessionInterface);

// save the key token into the store (database or session)
$session->setKey($key);
$session->setToken($session->hash($key . $newToken));
$session->setDate(date('Y-m-d H:i:s'));
$saved = $session->save();
// }
// else if ($adapter === 'session') {
// $this->session->get($key);
// $this->session->set($key, $newToken);
// }

// temporary store the new key token pair
$this->store = ['key' => $session->getKey(), 'token' => $newToken];
Expand Down Expand Up @@ -235,7 +242,6 @@ public function getIdentity(bool $inherit = true): array
if (!empty($inheritedRoleIndexList)) {

SecurityBehavior::staticStart();
$roleClass = $this->getRoleClass();
$inheritedRoleList = $this->models->getRole()::find([
'index in ({role:array})',
'bind' => ['role' => $inheritedRoleIndexList],
Expand All @@ -259,6 +265,7 @@ public function getIdentity(bool $inherit = true): array

// To avoid breaking stuff in production, create a new role if it doesn't exist
if (!$this->config->path('app.debug', false)) {
$roleClass = $this->getRoleClass();
foreach ($inheritedRoleIndexList as $inheritedRoleIndex) {
$roleList[$inheritedRoleIndex] = new $roleClass();
$roleList[$inheritedRoleIndex]->setIndex($inheritedRoleIndex);
Expand Down
8 changes: 5 additions & 3 deletions src/Modules/Api/Controllers/RecordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ public function initializeSearchFields(): void
'uuid = :uuid:',
'bind' => ['uuid' => $advanced['tableUuid']]
]);
$columns = $table->getColumnList();
foreach ($columns as $column) {
$collection->set($column->getUuid(), $column->getUuid());
if ($table) {
$columns = $table->getColumnList();
foreach ($columns as $column) {
$collection->set($column->getUuid(), $column->getUuid());
}
}
}

Expand Down

0 comments on commit 4e12737

Please sign in to comment.