58 lines
1.9 KiB
PHP
58 lines
1.9 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()->setFormOptions($filters);
|
|
$this->service->getFormService()->setBatchjobFilters($filters);
|
|
}
|
|
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();
|
|
}
|
|
}
|