cfmgrv4 init...2
This commit is contained in:
parent
375c6cd48a
commit
d18f24981c
@ -110,6 +110,7 @@ define('FORMS', [
|
||||
//URL
|
||||
define('URLS', [
|
||||
'LOGIN' => '/user/login',
|
||||
'GOOGLE_LOGIN' => '/user/google_login',
|
||||
'SIGNUP' => '/user/signup',
|
||||
'LOGOUT' => '/user/logout',
|
||||
]);
|
||||
@ -158,6 +159,7 @@ define('ICONS', [
|
||||
'LOGO' => '<img src="/images/logo/android-icon-48x48.png">',
|
||||
'EXCEL' => '<img src="/images/common/excel.png"/>',
|
||||
'PDF' => '<img src="/images/common/pdf.png"/>',
|
||||
'GOOGLE' => '<img src="https://www.google.com/favicon.ico" alt="Google" width="20" height="20" class="me-2">',
|
||||
'MEMBER' => '<i class="bi bi-people"></i>',
|
||||
'LOGIN' => '<i class="bi bi-shield-check"></i>',
|
||||
'LOGOUT' => '<i class="bi bi-sign-stop-fill"></i>',
|
||||
@ -182,7 +184,6 @@ define('ICONS', [
|
||||
'LEFT' => '<i class="bi bi-arrow-left"></i>',
|
||||
'RIGHT' => '<i class="bi bi-arrow-right"></i>',
|
||||
'IMAGE_FILE' => '<i class="bi bi-file-earmark-image"></i>',
|
||||
'GOOGLE' => '<i class="bi bi-google"></i>',
|
||||
'CLOUD' => '<i class="bi bi-cloud"></i>',
|
||||
'SIGNPOST' => '<i class="bi bi-signpost"></i>',
|
||||
'LOCK' => '<i class="bi bi-lock"></i>',
|
||||
|
||||
@ -15,6 +15,7 @@ $routes->get('/', 'Home::index');
|
||||
$routes->group('/user', function ($routes) {
|
||||
$routes->get('login', 'UserController::login_form');
|
||||
$routes->post('login', 'UserController::login');
|
||||
$routes->get('google_login', 'UserController::google_login');
|
||||
$routes->get('logout', 'UserController::logout', ['filter' => 'authFilter:user']);
|
||||
});
|
||||
$routes->group('cli', ['namespace' => 'App\CLI'], function ($routes) {
|
||||
|
||||
@ -114,7 +114,7 @@ class UserController extends AdminController
|
||||
$this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields);
|
||||
$this->filter_fields = ['role', 'status'];
|
||||
$this->field_options = $this->getFormFieldOptions($this->filter_fields);
|
||||
$this->batchjob_fields = ['status'];
|
||||
$this->batchjob_fields = ['role', 'status'];
|
||||
return $this->list_procedure();
|
||||
}
|
||||
// Download
|
||||
|
||||
@ -100,22 +100,33 @@ class UserController extends FrontController
|
||||
//Transaction Start
|
||||
$this->getModel()->transStart();
|
||||
try {
|
||||
$site = $this->request->getVar('site');
|
||||
switch ($site) {
|
||||
case 'local':
|
||||
$this->create_validate($this->action, $this->fields);
|
||||
$this->formDatas = $this->getFormDatas();
|
||||
$auth = new LocalAuth();
|
||||
$entity = $auth->checkUser($this->formDatas);
|
||||
break;
|
||||
case 'google':
|
||||
$auth = new GoogleAuth();
|
||||
$entity = $auth->checkUser();
|
||||
break;
|
||||
default:
|
||||
throw new \Exception("{$site}는 아직 지원하지 않는 사이트입니다.");
|
||||
$auth->setLogin($auth->checkUser($this->formDatas));
|
||||
$this->message = "로그인 성공";
|
||||
$this->getModel()->transCommit();
|
||||
log_message("notice", $this->message);
|
||||
$this->session->setFlashdata(SESSION_NAMES['RETURN_MSG'], $this->message);
|
||||
return redirect()->to($this->session->getFlashdata(SESSION_NAMES['RETURN_URL']) ?: "/");
|
||||
} catch (\Exception $e) {
|
||||
//Transaction Rollback
|
||||
$this->getModel()->transRollback();
|
||||
log_message("error", $e->getMessage());
|
||||
$this->session->setFlashdata(SESSION_NAMES['RETURN_MSG'], "로그인 실패하였습니다.\n" . $e->getMessage());
|
||||
$this->session->keepFlashdata(SESSION_NAMES['RETURN_URL']);
|
||||
return redirect()->back()->withInput();
|
||||
}
|
||||
$auth->setLogin($entity);
|
||||
}
|
||||
public function google_login(): RedirectResponse|string
|
||||
{
|
||||
$this->init('login');
|
||||
$this->init('login');
|
||||
//Transaction Start
|
||||
$this->getModel()->transStart();
|
||||
try {
|
||||
$auth = new GoogleAuth();
|
||||
$auth->setLogin($auth->checkUser());
|
||||
$this->message = "로그인 성공";
|
||||
$this->getModel()->transCommit();
|
||||
log_message("notice", $this->message);
|
||||
|
||||
@ -15,7 +15,6 @@ return [
|
||||
'created_at' => "작성일",
|
||||
],
|
||||
"ROLE" => [
|
||||
"guest" => "비회원",
|
||||
"user" => "일반회원",
|
||||
"vip" => "VIP회원",
|
||||
"manager" => "관리자",
|
||||
|
||||
@ -7,7 +7,6 @@ use App\Models\UserModel;
|
||||
use App\Models\SNSUserModel;
|
||||
use App\Libraries\MySocket\GoogleSocket;
|
||||
use App\Entities\UserEntity;
|
||||
use App\Entities\SNSUserEntity;
|
||||
|
||||
class GoogleAuth extends MyAuth
|
||||
{
|
||||
@ -23,7 +22,7 @@ class GoogleAuth extends MyAuth
|
||||
{
|
||||
if ($this->_mySocket === null) {
|
||||
$this->_mySocket = new GoogleSocket();
|
||||
$this->_mySocket->setAccessToken();
|
||||
$this->_mySocket->setMyToken();
|
||||
}
|
||||
return $this->_mySocket;
|
||||
}
|
||||
@ -31,7 +30,7 @@ class GoogleAuth extends MyAuth
|
||||
public function getAuthButton()
|
||||
{
|
||||
$button = "";
|
||||
if (!$this->getMySocket()->getAccessToken()) {
|
||||
if (!$this->getMySocket()->getMyToken()) {
|
||||
$button = anchor(
|
||||
getenv("socket.google.api.url"),
|
||||
ICONS['GOOGLE'],
|
||||
@ -107,11 +106,11 @@ class GoogleAuth extends MyAuth
|
||||
}
|
||||
//local db 사용와의 연결 확인
|
||||
$userModel = new UserModel();
|
||||
$userEntity = $userModel->getEntityByID($entity->getID());
|
||||
if ($userEntity === null) {
|
||||
$user_entity = $userModel->getEntityByID($entity->getID());
|
||||
if ($user_entity === null) {
|
||||
throw new \Exception("{$this->_site}의{$authInfo['email']}:{$authInfo['name']}님은 아직 사용자 연결이 이루어지지 않았습니다. ");
|
||||
}
|
||||
return $userEntity;
|
||||
return $user_entity;
|
||||
} catch (\Exception $e) {
|
||||
throw new \Exception("관리자에게 문의하시기 바랍니다.<BR>{$e->getMessage()}");
|
||||
}
|
||||
|
||||
@ -2,12 +2,15 @@
|
||||
|
||||
namespace App\Libraries\MySocket;
|
||||
|
||||
class GoogleSocket extends Google_Client
|
||||
use Google\Client;
|
||||
|
||||
class GoogleSocket extends Client
|
||||
{
|
||||
private $_session = null;
|
||||
private $_access_code = "";
|
||||
public function __construct()
|
||||
public function __construct(string $access_code)
|
||||
{
|
||||
$this->_access_code = $access_code;
|
||||
parent::__construct();
|
||||
$this->_session = \Config\Services::session();
|
||||
$this->setClientId(getenv("socket.google.client.id"));
|
||||
@ -17,22 +20,10 @@ class GoogleSocket extends Google_Client
|
||||
$this->addScope('profile');
|
||||
}
|
||||
|
||||
public function getAccessCode(): string
|
||||
{
|
||||
if ($this->_access_code === "") {
|
||||
throw new \Exception("access_code가 지정되지 않았습니다.");
|
||||
}
|
||||
return $this->_access_code;
|
||||
}
|
||||
public function setAccessCode(string $access_code)
|
||||
{
|
||||
$this->_access_code = $access_code;
|
||||
}
|
||||
|
||||
public function setAccessToken()
|
||||
public function setMyToken(): void
|
||||
{
|
||||
//2.토큰정보 가져오기
|
||||
$tokenInfo = $this->fetchAccessTokenWithAuthCode($this->getAccessCode());
|
||||
$tokenInfo = $this->fetchAccessTokenWithAuthCode($this->_access_code);
|
||||
if (isset($tokenInfo['error'])) {
|
||||
throw new \Exception($tokenInfo['error']);
|
||||
}
|
||||
@ -42,7 +33,7 @@ class GoogleSocket extends Google_Client
|
||||
//4. Google에 로그인이 했으므로 세션에 Token값 설정
|
||||
$this->_session->set(getenv("socket.google.client.token_name"), $token);
|
||||
}
|
||||
public function getAccessToken(): ?string
|
||||
public function getMyToken(): ?string
|
||||
{
|
||||
return $this->_session->get(getenv("socket.google.client.token_name"));
|
||||
}
|
||||
|
||||
@ -13,11 +13,8 @@
|
||||
<input type="password" class="form-control" id="userPassword" name="passwd" required>
|
||||
</div>
|
||||
<div class="d-flex justify-content-between align-items-center">
|
||||
<button type="submit" class="btn btn-primary" name="site" value="local">로그인</button>
|
||||
<button type="submit" class="btn btn-danger" name="site" value="google">
|
||||
<img src="https://www.google.com/favicon.ico" alt="Google" width="20" height="20" class="me-2">
|
||||
Google 로그인
|
||||
</button>
|
||||
<button type="submit" class="btn btn-primary">로그인</button>
|
||||
<?= anchor(URLS['GOOGLE_LOGIN'], ICONS['GOOGLE'] . 'Google 로그인', ["class" => "btn btn-danger"]) ?>
|
||||
<button type="button" class="btn btn-outline-primary">회원가입</button>
|
||||
</div>
|
||||
<?= form_close(); ?>
|
||||
|
||||
@ -13,6 +13,7 @@
|
||||
"php": "^8.3",
|
||||
"cloudflare/sdk": "^1.3",
|
||||
"codeigniter4/framework": "^4.5",
|
||||
"google/apiclient": "^2.0",
|
||||
"guzzlehttp/guzzle": "^7.9",
|
||||
"phpoffice/phpspreadsheet": "^1.27",
|
||||
"symfony/css-selector": "^7.1",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user