_session == null) { $this->_session = \Config\Services::session(); } return $this->_session; } final public function getAuthInfo(string $key = ""): array|string { if ($key) { return isset($this->getSession()->get(SESSION_NAMES['AUTH'])[$key]) ? $this->getSession()->get(SESSION_NAMES['AUTH'])[$key] : ""; } return $this->getSession()->get(SESSION_NAMES['AUTH']); } final public function isLoggedIn(): bool { return $this->getSession()->has(SESSION_NAMES['ISLOGIN']); } final public function isAccessRole(string $role): bool { if ($this->getAuthInfo('role') === "") { return false; } $roles = explode(DEFAULTS['DELIMITER_ROLE'], $this->getAuthInfo('role')); if (!in_array($role, $roles)) { return false; } return true; } final public function pushCurrentUrl(string $url): void { $this->getSession()->set('url_stack', $url); } final public function popPreviousUrl(): string { $url = $this->getSession()->get('url_stack') ?? ""; if (!empty($url)) { $this->pushCurrentUrl(""); return $url; } return '/'; // 기본 URL } final public function login(UserEntity $entity): void { $this->getSession()->set(SESSION_NAMES['ISLOGIN'], true); $this->getSession()->set(SESSION_NAMES['AUTH'], [ 'uid' => $entity->getPK(), 'name' => $entity->getTitle(), 'role' => $entity->role ]); } final public function logout(): void { // 세션 데이터 삭제 $this->getSession()->remove(SESSION_NAMES['ISLOGIN']); $this->getSession()->remove(SESSION_NAMES['AUTH']); // 모든 세션 데이터 삭제 $this->getSession()->destroy(); // 세션 쿠키 삭제 if (ini_get("session.use_cookies")) { $params = session_get_cookie_params(); setcookie( session_name(), '', time() - 42000, $params["path"], $params["domain"], $params["secure"], $params["httponly"] ); } // 세션 재생성 session_start(); $this->getSession()->regenerate(true); } }