70 lines
2.7 KiB
PHP
70 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers\Auth;
|
|
|
|
use App\Controllers\AbstractWebController;
|
|
use App\Entities\UserEntity;
|
|
use CodeIgniter\HTTP\RedirectResponse;
|
|
use CodeIgniter\HTTP\RequestInterface;
|
|
use CodeIgniter\HTTP\ResponseInterface;
|
|
use Psr\Log\LoggerInterface;
|
|
|
|
abstract class AuthController extends AbstractWebController
|
|
{
|
|
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
|
{
|
|
parent::initController($request, $response, $logger);
|
|
$this->addActionPaths('auth');
|
|
}
|
|
final protected function getLayout(): string
|
|
{
|
|
return 'auth';
|
|
}
|
|
protected function action_init_process(string $action, array $formDatas = []): void
|
|
{
|
|
$this->service->action_init_process($action);
|
|
parent::action_init_process($action);
|
|
$this->addViewDatas('layout', $this->getLayout());
|
|
$this->addViewDatas('helper', $this->service->getHelper());
|
|
$this->addViewDatas('formFields', $this->service->getFormService()->getFormFields());
|
|
$this->addViewDatas('formRules', $this->service->getFormService()->getFormRules());
|
|
$this->addViewDatas('formFilters', $this->service->getFormService()->getFormFilters());
|
|
$this->addViewDatas('formOptions', $this->service->getFormService()->getFormOptions());
|
|
}
|
|
//로그인화면
|
|
final public function login_form(): string|RedirectResponse
|
|
{
|
|
$action = __FUNCTION__;
|
|
try {
|
|
//초기화
|
|
$this->action_init_process($action);
|
|
} catch (\Throwable $e) {
|
|
log_message('error', $e->getMessage());
|
|
session()->setFlashdata('message', $e->getMessage());
|
|
}
|
|
return $this->action_render_process($action, $this->getViewDatas());
|
|
}
|
|
//로그인처리
|
|
abstract protected function login_process(): UserEntity;
|
|
final public function login(): RedirectResponse
|
|
{
|
|
$this->login_process();
|
|
$redirect_url = $this->getAuthContext()->popPreviousUrl() ?? implode(DIRECTORY_SEPARATOR, $this->getActionPaths());
|
|
return redirect()->to($redirect_url)->with('message', MESSAGES['LOGIN']);
|
|
}
|
|
//로그아웃
|
|
abstract protected function logout_process(): void;
|
|
final public function logout(): RedirectResponse
|
|
{
|
|
try {
|
|
$this->logout_process();
|
|
// 홈페이지로 리다이렉트
|
|
$redirect_url = $this->getAuthContext()->popPreviousUrl() ?? "/";
|
|
return redirect()->route($redirect_url)->with('message', MESSAGES['LOGOUT']);
|
|
} catch (\Throwable $e) {
|
|
log_message("error", $e->getMessage());
|
|
return redirect()->back()->withInput()->with('message', "로그아웃 중 오류가 발생했습니다.");
|
|
}
|
|
}
|
|
}
|