Automation/app/Libraries/MyAuth/GoogleAuth.php
2024-09-15 16:02:23 +09:00

112 lines
3.7 KiB
PHP

<?php
namespace App\Libraries\MyAuth;
use App\Libraries\MySocket\Web\GoogleSocket;
use App\Libraries\MyAuthLibrary;
use App\Entities\UserEntity;
use App\Entities\SNSUserEntity;
class GoogleAuth extends MyAuthLibrary
{
private $_mySocket = null;
private $_site = "GOOGLE";
public function __construct()
{
parent::__construct();
}
public function getMySocket(): GoogleSocket
{
if ($this->_mySocket === null) {
$this->_mySocket = new GoogleSocket(getenv('yamap.host.url'));
}
return $this->_mySocket;
}
public function getAuthButton()
{
$button = "";
if (!$this->getMySocket()->getAccessToken()) {
$button = anchor(
$this->getMySocket()->getClient()->createAuthUrl(),
ICONS['GOOGLE'],
["target" => "_self"]
);
}
return $button;
}
public function execute(): UserEntity
{
return new UserEntity();
// try {
// //Google 접근 권한 설정.
// $this->getMySocket()->setAccessToken();
// //Google 서비스 설정
// //$service = new \Google\Service\Oauth2($this->getMySocket());
// $service = new \Google\Service\Oauth2($this->getMySocket());
// $result = $service->userinfo->get();
// log_message("debug", var_export($result, true));
// // throw new \Exception(__METHOD__ . "에서 데이터 처리 필요");
// // DEBUG - 2023-07-13 12:54:51 --> \Google\Service\Oauth2\Userinfo::__set_state(array(
// // 'internal_gapi_mappings' =>
// // array (
// // 'familyName' => 'family_name',
// // 'givenName' => 'given_name',
// // 'verifiedEmail' => 'verified_email',
// // ),
// // 'modelData' =>
// // array (
// // 'verified_email' => true,
// // 'given_name' => '이름',
// // 'family_name' => '성',
// // ),
// // 'processed' =>
// // array (
// // ),
// // 'email' => 'twsdfsew342s@gmail.com',
// // 'familyName' => '성',
// // 'gender' => NULL,
// // 'givenName' => '이름',
// // 'hd' => NULL,
// // 'id' => '103667492432234234236838324',
// // 'link' => NULL,
// // 'locale' => 'ko',
// // 'name' => '성이름',
// // 'picture' => 'https://lh3.googleusercontent.com/a/AAcHTteFSgefsdfsdRJBkJA2tBEmg4PQrvI1Ta_5IXu5=s96-c',
// // 'verifiedEmail' => true,
// // ))
// //조건에 해당하는 이미 등록된 사용자가 있는지 검사
// $snsEntity = null;
// try {
// $snsEntity = $this->getUserSNSModel()->asObject(SNSUSerEntity::class)->where(
// array("site" => $this->_site, "id" => $result['id'])
// )->first();
// } catch (\Exception $e) {
// $snsEntity = new SNSUSerEntity([
// 'site' => $this->_site,
// 'id' => $result['id'],
// 'name' => $result['name'],
// 'email' => $result['email'],
// 'detail' => json_encode($result),
// 'status' => 'standby',
// ]);
// $snsEntity = $this->getUserSNSModel()->create($snsEntity);
// }
// //상태가 use(승인완료)가 아니라면
// if ($snsEntity->status !== DEFAULTS['STATUS']) {
// throw new \Exception("{$this->_site}}의{$result['email']}:{$result['name']}님은 " . $snsEntity->status . "입니다");
// }
// //user_id가 연결되어있지 않았다면
// if (!$snsEntity->getID()) {
// throw new \Exception("{$this->_site}의{$result['email']}:{$result['name']}님은 아직 사용자 지정이 되지 않았습니다. ");
// }
// //인증된 사용자 정보를 가져온후 로그인처리
// $entity = $this->getUserModel()->getEntityByID($snsEntity->getID());
// return $this->setSession_process($entity);;
// } catch (\Exception $e) {
// throw new \Exception("관리자에게 문의하시기 바랍니다.<BR>{$e->getMessage()}");
// }
}
}