servermgrv2 init...

This commit is contained in:
최준흠 2023-07-19 12:42:31 +09:00
parent e494edd250
commit 514cba6a9d
5 changed files with 13 additions and 12 deletions

View File

@ -144,7 +144,7 @@ define('LOGINS', [
define('AUTHS', [ define('AUTHS', [
'DEBUG' => getenv('auth.debug') == 'true' ? true : false, 'DEBUG' => getenv('auth.debug') == 'true' ? true : false,
'ADAPTERS' => getenv('auth.adapters') ? implode(",", getenv('auth.adapters')) : ['Local', 'Google'], 'ADAPTERS' => getenv('auth.adapters') ? implode(",", getenv('auth.adapters')) : ['Local', 'Google'],
'GOOGLE' => [ 'Google' => [
'ICON' => '<img src="/images/auth/google_login_button.png"/>', 'ICON' => '<img src="/images/auth/google_login_button.png"/>',
'CLIENT_ID' => getenv("auth.google.client.id"), 'CLIENT_ID' => getenv("auth.google.client.id"),
'CLIENT_KEY' => getenv("auth.google.client.key"), 'CLIENT_KEY' => getenv("auth.google.client.key"),

View File

@ -26,17 +26,18 @@ class AuthController extends BaseController
private function initAdapters() private function initAdapters()
{ {
foreach (AUTHS['ADAPTERS'] as $adapter) { foreach (AUTHS['ADAPTERS'] as $site) {
$this->getAdapter($adapter); $this->getAdapter($site);
} }
} }
private function getAdapter(string $adapter): Adapter private function getAdapter(string $site): Adapter
{ {
if (!array_key_exists($adapter, $this->_adapters)) { $site = ucfirst($site);
$adapterClass = sprintf("\App\Libraries\Adapter\Auth\%sAdapter", $adapter); if (!array_key_exists($site, $this->_adapters)) {
$this->_adapters[$adapter] = new $adapterClass($adapter, AUTHS['DEBUG']); $adapterClass = sprintf("\App\Libraries\Adapter\Auth\%sAdapter", $site);
$this->_adapters[$site] = new $adapterClass($site, AUTHS['DEBUG']);
} }
return $this->_adapters[$adapter]; return $this->_adapters[$site];
} }
public function login() public function login()

View File

@ -23,7 +23,7 @@ abstract class Adapter
if (is_null($this->_site)) { if (is_null($this->_site)) {
throw new \Exception("Auth Adpater Site명이 정의 되지 않았습니다."); throw new \Exception("Auth Adpater Site명이 정의 되지 않았습니다.");
} }
return strtoupper($this->_site); return ucfirst($this->_site);
} }
abstract public function getAuthButton(); abstract public function getAuthButton();
abstract public function signin(array $formDatas): UserEntity; abstract public function signin(array $formDatas): UserEntity;

View File

@ -103,7 +103,7 @@ class GoogleAdapter extends Adapter
array("site" => $this->getSiteName(), "uid" => $result['id']) array("site" => $this->getSiteName(), "uid" => $result['id'])
)->first(); )->first();
if (is_null($snsEntity)) { if (is_null($snsEntity)) {
$snsEntity = $this->getUserSNSModel()->create($result); $snsEntity = $this->getUserSNSModel()->create($this->getSiteName(), $result);
} }
if (is_null($snsEntity->getUserUID())) { if (is_null($snsEntity->getUserUID())) {
throw new \Exception($this->getSiteName() . "{$result['email']}:{$result['name']}님은 아직 사용자 지정이 되지 않았습니다."); throw new \Exception($this->getSiteName() . "{$result['email']}:{$result['name']}님은 아직 사용자 지정이 되지 않았습니다.");

View File

@ -31,10 +31,10 @@ class UserSNSModel extends CommonModel
{ {
return $this->getEntityByField($this->primaryKey, $uid); return $this->getEntityByField($this->primaryKey, $uid);
} }
public function create(array $datas): UserSNSEntity public function create(string $site, array $datas): UserSNSEntity
{ {
$entity = new UserSNSEntity(); $entity = new UserSNSEntity();
$entity->site = $this->getSiteName(); $entity->site = $site;
$entity->id = $datas['id']; $entity->id = $datas['id'];
$entity->name = $datas['name']; $entity->name = $datas['name'];
$entity->email = $datas['email']; $entity->email = $datas['email'];