trafficmonitor/app/Controllers/Auth/GoogleController.php
2025-11-05 18:58:37 +09:00

45 lines
1.4 KiB
PHP

<?php
namespace App\Controllers\Auth;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface;
use App\Libraries\MySocket\GoogleSocket\API as GoogleSocket;
use App\Entities\UserEntity;
class GoogleController extends AuthController
{
public const PATH = 'login';
private ?GoogleSocket $_socket = null;
private $_service = null;
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
parent::initController($request, $response, $logger);
if ($this->service === null) {
$this->service = service('googleauth');
}
}
public function login_form_process(array $viewDatas): array
{
//구글 로그인 BUTTON용
$viewDatas['SNSButton'] = anchor($this->service->socket->createAuthUrl(), ICONS['GOOGLE'] . 'Google 로그인', ["class" => "btn-google"]);
return $viewDatas;
}
//로그인처리
protected function login_process(): UserEntity
{
$formDatas = $this->doValidation(__FUNCTION__);
if (!array_key_exists('access_code', $formDatas) || !$formDatas['access_code']) {
throw new \Exception("구글 로그인 실패");
}
return $this->service->login($formDatas);
}
protected function logout_process(): void
{
$this->service->logout();
}
}