addClassPaths('Auth'); } abstract public function login(mixed $dto): UserEntity; final public function getHelper(): AuthHelper { if ($this->helperInstance === null) { $this->helperInstance = new AuthHelper(); $this->helperInstance->setAttributes([ 'pk_field' => $this->model->getPKField(), 'title_field' => $this->model->getTitleField(), 'table' => $this->model->getTable(), 'useAutoIncrement' => $this->model->useAutoIncrement(), 'class_path' => $this->getClassPaths(false) ]); } return $this->helperInstance; } //Index,FieldForm관련 final public function getSession(): Session { if ($this->_session === null) { $this->_session = \Config\Services::session(); } return $this->_session; } private function getAuthInfo(string $key = ""): array|string|null { $authInfo = $this->getSession()->get(SESSION_NAMES['AUTH']); if ($key) { return $authInfo[$key] ?? null; } return $authInfo; } public function getFormFields(): array { return ['id', 'passwd']; } final public function getUID(): string|null { return $this->getAuthInfo('uid'); } final public function getID(): string|null { return $this->getAuthInfo('id'); } final public function getName(): string|null { return $this->getAuthInfo('name'); } final public function getRole(): string|null { return $this->getAuthInfo('role'); } final public function isLoggedIn(): bool { return $this->getSession()->has(SESSION_NAMES['ISLOGIN']); } final public function isAccessRole(array $roles): bool { $role = $this->getRole(); if ($role === "") { return false; } // 교집합이 없으면 false return !empty(array_intersect(explode(DEFAULTS['DELIMITER_ROLE'], $role), $roles)); } final public function pushCurrentUrl(string $url): void { $this->getSession()->set($this->url_stack_name, $url); } final public function popPreviousUrl(): string { $url = $this->getSession()->get($this->url_stack_name) ?? ""; if (!empty($url)) { $this->pushCurrentUrl(""); return $url; } return '/'; // 기본 URL } final protected function login_process(UserEntity $entity): UserEntity { $this->getSession()->set(SESSION_NAMES['ISLOGIN'], true); $this->getSession()->set(SESSION_NAMES['AUTH'], [ 'uid' => $entity->getPK(), 'id' => $entity->getID(), 'name' => $entity->getTitle(), 'role' => $entity->role ]); return $entity; } 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); } }