60 lines
1.8 KiB
PHP
60 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Auth;
|
|
|
|
use App\Entities\UserEntity;
|
|
use App\Models\UserModel;
|
|
use App\Libraries\MySocket\GoogleSocket\CURL;
|
|
use CodeIgniter\Exceptions\PageNotFoundException;
|
|
use CodeIgniter\HTTP\IncomingRequest;
|
|
|
|
class GoogleService extends AuthService
|
|
{
|
|
private $_mySocket = null;
|
|
public function __construct(mixed $mySocket, ?IncomingRequest $request = null)
|
|
{
|
|
$this->_mySocket = $mySocket;
|
|
parent::__construct($request);
|
|
}
|
|
public function getMySocket(): mixed
|
|
{
|
|
if (!$this->_mySocket) {
|
|
throw new \Exception("Socket이 지정되지 않았습니다.");
|
|
}
|
|
return $this->_mySOcket;
|
|
}
|
|
public function getClassName(): string
|
|
{
|
|
return parent::getClassName() . DIRECTORY_SEPARATOR . "Google";
|
|
}
|
|
final public function getModelClass(): UserModel
|
|
{
|
|
return new UserModel();
|
|
}
|
|
final public function getEntityClass(): UserEntity
|
|
{
|
|
return new UserEntity();
|
|
}
|
|
|
|
public function checkUser(string $access_code): UserEntity
|
|
{
|
|
try {
|
|
// Google 서비스 설정
|
|
$this->this->getMySocket()->setToken($access_code);
|
|
$sns_entity = $this->_mySocket->signup();
|
|
// local db 사용와의 연결 확인
|
|
$entity = $this->getEntity($sns_entity->getParent());
|
|
if (!$entity) {
|
|
throw new PageNotFoundException("회원[{$sns_entity->getTitle()}]님은 아직 로컬사용자 연결이 이루어지지 않았습니다.");
|
|
}
|
|
return $entity;
|
|
} catch (\Google_Service_Exception $e) {
|
|
log_message('error', '구글 서비스 예외발생: ' . $e->getMessage());
|
|
throw new PageNotFoundException("구글 로그인 중 오류가 발생했습니다. 다시 시도해 주세요.");
|
|
} catch (\Exception $e) {
|
|
log_message('error', $e->getMessage());
|
|
throw new PageNotFoundException("관리자에게 문의하시기 바랍니다.\n{$e->getMessage()}");
|
|
}
|
|
}
|
|
}
|