88 lines
2.8 KiB
PHP
88 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Auth;
|
|
|
|
use App\DTOs\Auth\GoogleDTO;
|
|
use App\Entities\UserEntity;
|
|
use App\Forms\Auth\GoogleForm;
|
|
use App\Libraries\MySocket\GoogleSocket\CURL;
|
|
use App\Models\UserModel;
|
|
use CodeIgniter\Exceptions\PageNotFoundException;
|
|
use CodeIgniter\Validation\Exceptions\ValidationException;
|
|
|
|
class GoogleService extends AuthService
|
|
{
|
|
private $_form = null;
|
|
public function __construct(UserModel $model, private CURL $socket)
|
|
{
|
|
parent::__construct($model);
|
|
$this->addClassPaths('Google');
|
|
}
|
|
public function createDTO(array $formDatas): GoogleDTO
|
|
{
|
|
return new GoogleDTO($formDatas);
|
|
}
|
|
public function getDTOClass(): string
|
|
{
|
|
return GoogleDTO::class;
|
|
}
|
|
public function getFormService(): GoogleForm
|
|
{
|
|
if ($this->_form === null) {
|
|
$this->_form = new GoogleForm();
|
|
$this->_form->setAttributes([
|
|
'pk_field' => $this->getPKField(),
|
|
'title_field' => $this->getTitleField(),
|
|
'table' => $this->model->getTable(),
|
|
'useAutoIncrement' => $this->model->useAutoIncrement(),
|
|
'class_path' => $this->getClassPaths(false),
|
|
]);
|
|
}
|
|
return $this->_form;
|
|
}
|
|
public function action_init_process(string $action, array $formDatas = []): void
|
|
{
|
|
$fields = ['access_code'];
|
|
$filters = [];
|
|
switch ($action) {
|
|
case 'login':
|
|
case 'login_form':
|
|
break;
|
|
}
|
|
$this->getFormService()->setFormFields($fields);
|
|
$this->getFormService()->setFormRules($action, $fields);
|
|
$this->getFormService()->setFormFilters($filters);
|
|
$this->getFormService()->setFormOptions($action, $filters);
|
|
$this->getFormService()->setBatchjobFilters($filters);
|
|
}
|
|
protected function getEntity_process(mixed $entity): UserEntity
|
|
{
|
|
return $entity;
|
|
}
|
|
//기본기능
|
|
protected function login_process(array $formDatas): UserEntity
|
|
{
|
|
try {
|
|
//입력값 검증
|
|
if (!$this->getFormService()->validate($formDatas)) {
|
|
throw new ValidationException(implode("\n", service('validation')->getErrors()));
|
|
}
|
|
|
|
$this->socket->setToken($formDatas['access_code']);
|
|
$sns_entity = $this->socket->signup();
|
|
// local db 사용와의 연결 확인
|
|
$entity = $this->getEntity($sns_entity->getParent());
|
|
if (!$entity instanceof UserEntity) {
|
|
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()}");
|
|
}
|
|
}
|
|
}
|