layout = "auth"; $this->uri_path = "auth/"; $this->view_path = "auth" . DIRECTORY_SEPARATOR; $this->content_title = "사용자인증"; } abstract protected function getSNSButton(): string; abstract protected function login_process(array $formDatas): UserEntity; final public function getHelper(): mixed { if (!$this->_helper) { $this->_helper = new AuthHelper(); } return $this->_helper; } protected function getResultFail(string $message = MESSAGES["FAILED"]): RedirectResponse { if ($this->request->getMethod() === 'POST') { return redirect()->back()->withInput()->with('error', $message); } return redirect()->to($this->getMyAuth()->popPreviousUrl())->with('error', $message); } protected function getResultSuccess(string $message = MESSAGES["SUCCESS"], ?string $actionTemplate = null): RedirectResponse|string { switch ($this->getAction()) { case 'create': //Login처리 $result = redirect()->to($this->getMyAuth()->popPreviousUrl())->with('error', $message); break; default: $result = parent::getResultSuccess($message, $actionTemplate); break; } return $result; } final protected function create_validate_process(array $formDatas): array { return $formDatas; } //로그인화면 public function login_form_process(): void { $this->sns_buttoh = $this->getSNSButton(); } public function login_form(): RedirectResponse|string { try { $this->setAction(__FUNCTION__); $this->setFormFields(); $this->setFormFilters(); $this->setFormRules(); $this->setFormOptions(); //기본값정의 $this->setFormDatas($this->request->getGet()); $this->login_form_process(); helper(['form']); $this->forms = ['attributes' => ['method' => "post",], 'hiddens' => []]; return $this->getResultSuccess(); } catch (\Exception $e) { dd($e->getMessage()); return $this->getResultFail($e->getMessage()); } } //로그인처리 public function login(): RedirectResponse|string { //Transaction Start $db = \Config\Database::connect(); $db->transStart(); try { $this->setAction(__FUNCTION__); $this->setFormFields(); $this->setFormFilters(); $this->setFormRules(); //전달값정의 $this->setFormDatas($this->request->getPost()); $this->doValidations(); $this->entity = $this->login_process($this->getFormDatas()); $db->transCommit(); return $this->getResultSuccess(); } catch (\Exception $e) { $db->transRollback(); return $this->getResultFail($e->getMessage()); } } //로그아웃 final public function logout(): RedirectResponse { try { $this->getService()->logout(); // 홈페이지로 리다이렉트 return redirect()->route('/')->with('error', MESSAGES['LOGOUT']); } catch (\Exception $e) { log_message("error", $e->getMessage()); return redirect()->back()->with('error', "로그아웃 중 오류가 발생했습니다."); } } }