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

feat: Change session manipulation methods from private to protected #1113

Merged
merged 2 commits into from
Jun 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions src/Authentication/Authenticators/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public function startUpAction(string $type, User $user): bool
public function getAction(): ?ActionInterface
{
/** @var class-string<ActionInterface>|null $actionClass */
$actionClass = $this->getSessionKey('auth_action');
$actionClass = $this->getSessionUserKey('auth_action');

if ($actionClass === null) {
return null;
Expand Down Expand Up @@ -249,8 +249,8 @@ public function checkAction(UserIdentity $identity, string $token): bool
$this->userIdentityModel->deleteIdentitiesByType($user, $identity->type);

// Clean up our session
$this->removeSessionKey('auth_action');
$this->removeSessionKey('auth_action_message');
$this->removeSessionUserKey('auth_action');
$this->removeSessionUserKey('auth_action_message');

$this->user = $user;

Expand Down Expand Up @@ -387,7 +387,7 @@ private function checkUserState(): void
}

/** @var int|string|null $userId */
$userId = $this->getSessionKey('id');
$userId = $this->getSessionUserKey('id');

// Has User Info in Session.
if ($userId !== null) {
Expand All @@ -404,7 +404,7 @@ private function checkUserState(): void
}

// If having `auth_action`, it is pending.
if ($this->getSessionKey('auth_action')) {
if ($this->getSessionUserKey('auth_action')) {
$this->userState = self::STATE_PENDING;

return;
Expand Down Expand Up @@ -445,15 +445,15 @@ public function hasAction($userId = null): bool
if ($this->getIdentitiesForAction($user) !== []) {
// Make pending login state
$this->user = $user;
$this->setSessionKey('id', $user->id);
$this->setSessionUserKey('id', $user->id);
$this->setAuthAction();

return true;
}
}

// Check the Session
if ($this->getSessionKey('auth_action')) {
if ($this->getSessionUserKey('auth_action')) {
return true;
}

Expand Down Expand Up @@ -488,8 +488,8 @@ private function setAuthAction(): bool
if ($identity instanceof UserIdentity) {
$this->userState = self::STATE_PENDING;

$this->setSessionKey('auth_action', $actionClass);
$this->setSessionKey('auth_action_message', $identity->extra);
$this->setSessionUserKey('auth_action', $actionClass);
$this->setSessionUserKey('auth_action_message', $identity->extra);

return true;
}
Expand Down Expand Up @@ -561,7 +561,7 @@ public function getPendingMessage(): string
{
$this->checkUserState();

return $this->getSessionKey('auth_action_message') ?? '';
return $this->getSessionUserKey('auth_action_message') ?? '';
}

/**
Expand Down Expand Up @@ -644,7 +644,7 @@ private function checkRememberMeToken(string $remember)
public function startLogin(User $user): void
{
/** @var int|string|null $userId */
$userId = $this->getSessionKey('id');
$userId = $this->getSessionUserKey('id');

// Check if already logged in.
if ($userId !== null) {
Expand All @@ -668,7 +668,7 @@ public function startLogin(User $user): void
}

// Let the session know we're logged in
$this->setSessionKey('id', $user->id);
$this->setSessionUserKey('id', $user->id);

/** @var Response $response */
$response = service('response');
Expand All @@ -680,15 +680,15 @@ public function startLogin(User $user): void
/**
* Gets User Info in Session
*/
private function getSessionUserInfo(): array
protected function getSessionUserInfo(): array
{
return session(setting('Auth.sessionConfig')['field']) ?? [];
}

/**
* Removes User Info in Session
*/
private function removeSessionUserInfo(): void
protected function removeSessionUserInfo(): void
{
session()->remove(setting('Auth.sessionConfig')['field']);
}
Expand All @@ -698,7 +698,7 @@ private function removeSessionUserInfo(): void
*
* @return int|string|null
*/
private function getSessionKey(string $key)
protected function getSessionUserKey(string $key)
{
$sessionUserInfo = $this->getSessionUserInfo();

Expand All @@ -710,7 +710,7 @@ private function getSessionKey(string $key)
*
* @param int|string|null $value
*/
private function setSessionKey(string $key, $value): void
protected function setSessionUserKey(string $key, $value): void
{
$sessionUserInfo = $this->getSessionUserInfo();
$sessionUserInfo[$key] = $value;
Expand All @@ -720,7 +720,7 @@ private function setSessionKey(string $key, $value): void
/**
* Remove the key value in Session User Info
*/
private function removeSessionKey(string $key): void
protected function removeSessionUserKey(string $key): void
{
$sessionUserInfo = $this->getSessionUserInfo();
unset($sessionUserInfo[$key]);
Expand All @@ -744,7 +744,7 @@ public function login(User $user): void
);
}
// Check auth_action in Session
if ($this->getSessionKey('auth_action')) {
if ($this->getSessionUserKey('auth_action')) {
throw new LogicException(
'The user has auth action in session, so cannot complete login.'
. ' If you want to start to login with auth action, use startLogin() instead.'
Expand Down
Loading