trafficmonitor/app/Controllers/Auth/LocalController.php
2025-11-11 15:11:07 +09:00

64 lines
2.3 KiB
PHP

<?php
namespace App\Controllers\Auth;
use App\DTOs\Auth\LocalDTO;
use App\Entities\UserEntity;
use App\Services\Auth\LocalService;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface;
/**
* @property LocalService $service
* IDE에게 protected $service 속성이 LocalService 타입임을 알려줍니다.
*/
class LocalController extends AuthController
{
public const PATH = 'login';
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
parent::initController($request, $response, $logger);
if ($this->service === null) {
$this->service = service('localauth');
}
$this->addActionPaths(self::PATH);
}
protected function action_init_process(string $action): void
{
parent::action_init_process($action);
$fields = ['id', 'passwd'];
$filters = [];
switch ($action) {
case 'login':
case 'login_form':
break;
default:
throw new \Exception("지원하지 않는 action입니다.({$action})");
// break;
}
$this->service->getFormService()->setFormFields($fields);
$this->service->getFormService()->setFormRules($action, $fields);
$this->service->getFormService()->setFormFilters($filters);
$this->service->getFormService()->setFormOptions($filters);
$this->service->getFormService()->setBatchjobFilters($filters);
$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());
}
//로그인처리
protected function login_process(): UserEntity
{
$this->action_init_process('login');
$dto = new LocalDTO($this->request->getPost());
return $this->service->login($dto);
}
protected function logout_process(): void
{
$this->service->logout();
}
}