trafficmonitor/app/Controllers/Auth/GoogleController.php
2025-11-11 14:51:31 +09:00

64 lines
2.4 KiB
PHP

<?php
namespace App\Controllers\Auth;
use App\DTOs\Auth\GoogleDTO;
use App\Entities\UserEntity;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface;
class GoogleController 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('googleauth');
}
$this->addActionPaths(self::PATH);
}
protected function action_init_process(string $action): void
{
parent::action_init_process($action);
$fields = ['access_code'];
$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()->getFormOptions($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());
}
public function login_form_process(): void
{
//구글 로그인 BUTTON용
$this->addViewDatas('SNSButton', anchor($this->service->socket->createAuthUrl(), ICONS['GOOGLE'] . 'Google 로그인', ["class" => "btn-google"]));
}
//로그인처리
protected function login_process(): UserEntity
{
//요청 데이터를 DTO 객체로 변환
$dto = new GoogleDTO($this->request->getPost());
return $this->service->login($dto);
}
protected function logout_process(): void
{
$this->service->logout();
}
}