56 lines
1.7 KiB
PHP
56 lines
1.7 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\Services\Auth\GoogleService;
|
|
use App\Entities\UserEntity;
|
|
|
|
class GoogleController extends AuthController
|
|
{
|
|
|
|
private ?GoogleSocket $_socket = null;
|
|
private $_service = null;
|
|
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
|
{
|
|
parent::initController($request, $response, $logger);
|
|
$this->uri_path .= strtolower($this->getService()->getClassName()) . '/';
|
|
$this->class_path = $this->getService()->getClassPath();
|
|
$this->title = lang("{$this->getService()->getClassPath()}.title");;
|
|
}
|
|
final public function getSocket()
|
|
{
|
|
if (!$this->_socket) {
|
|
$this->_socket = new GoogleSocket();
|
|
}
|
|
return $this->_socket;
|
|
}
|
|
final public function getService(): GoogleService
|
|
{
|
|
if (!$this->_service) {
|
|
$this->_service = new GoogleService($this->getSocket(), $this->request);
|
|
}
|
|
return $this->_service;
|
|
}
|
|
|
|
public function getSNSButton(): string
|
|
{
|
|
//구글 로그인 BUTTON용
|
|
return anchor($this->getSocket()->createAuthUrl(), ICONS['GOOGLE'] . 'Google 로그인', ["class" => "btn-google"]);
|
|
}
|
|
|
|
//로그인처리
|
|
protected function login_process(): UserEntity
|
|
{
|
|
$access_code = $this->request->getVar('code');
|
|
if (!$access_code) {
|
|
throw new \Exception("구글 로그인 실패");
|
|
}
|
|
return $this->getService()->login($this->getService()->checkUser($access_code));
|
|
}
|
|
}
|