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) {
|
||||
|
||||
@ -20,8 +20,8 @@ class UserController extends AdminController
|
||||
parent::initController($request, $response, $logger);
|
||||
$this->class_name = "User";
|
||||
$this->class_path .= $this->class_name;
|
||||
$this->title = lang("{$this->class_path}.title");
|
||||
$this->helper = new UserHelper();
|
||||
$this->title = lang("{$this->class_path}.title");
|
||||
$this->helper = new UserHelper();
|
||||
}
|
||||
protected function getModel(): UserModel
|
||||
{
|
||||
@ -70,11 +70,11 @@ class UserController extends AdminController
|
||||
}
|
||||
private function init(string $action): void
|
||||
{
|
||||
$this->action = $action;
|
||||
$this->fields = ['id', 'passwd', 'confirmpassword', $this->getModel()::TITLE, 'email', 'mobile', 'role'];
|
||||
$this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields);
|
||||
$this->filter_fields = ['role', 'status'];
|
||||
$this->field_options = $this->getFormFieldOptions($this->filter_fields);
|
||||
$this->action = $action;
|
||||
$this->fields = ['id', 'passwd', 'confirmpassword', $this->getModel()::TITLE, 'email', 'mobile', 'role'];
|
||||
$this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields);
|
||||
$this->filter_fields = ['role', 'status'];
|
||||
$this->field_options = $this->getFormFieldOptions($this->filter_fields);
|
||||
}
|
||||
//생성
|
||||
public function create_form(): RedirectResponse|string
|
||||
@ -101,30 +101,30 @@ class UserController extends AdminController
|
||||
//일괄작업
|
||||
public function batcjob(): RedirectResponse
|
||||
{
|
||||
$this->action = __FUNCTION__;
|
||||
$this->fields = ['status'];
|
||||
$this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields);
|
||||
$this->action = __FUNCTION__;
|
||||
$this->fields = ['status'];
|
||||
$this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields);
|
||||
return $this->batcjob_procedure();
|
||||
}
|
||||
// 리스트
|
||||
public function index(): string
|
||||
{
|
||||
$this->action = __FUNCTION__;
|
||||
$this->fields = ['id', $this->getModel()::TITLE, 'email', 'mobile', 'role', 'status'];
|
||||
$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->action = __FUNCTION__;
|
||||
$this->fields = ['id', $this->getModel()::TITLE, 'email', 'mobile', 'role', 'status'];
|
||||
$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 = ['role', 'status'];
|
||||
return $this->list_procedure();
|
||||
}
|
||||
// Download
|
||||
public function download(string $output_type, $uid = false): DownloadResponse|string
|
||||
{
|
||||
$this->action = __FUNCTION__;
|
||||
$this->fields = ['id', $this->getModel()::TITLE, 'email', 'mobile', 'role', 'status'];
|
||||
$this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields);
|
||||
$this->filter_fields = ['role', 'status'];
|
||||
$this->field_options = $this->getFormFieldOptions($this->filter_fields);
|
||||
$this->action = __FUNCTION__;
|
||||
$this->fields = ['id', $this->getModel()::TITLE, 'email', 'mobile', 'role', 'status'];
|
||||
$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'];
|
||||
return $this->download_procedure($output_type, $uid);
|
||||
}
|
||||
|
||||
@ -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($entity);
|
||||
$this->create_validate($this->action, $this->fields);
|
||||
$this->formDatas = $this->getFormDatas();
|
||||
$auth = new LocalAuth();
|
||||
$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();
|
||||
}
|
||||
}
|
||||
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);
|
||||
|
||||
@ -1,30 +1,29 @@
|
||||
<?php
|
||||
return [
|
||||
'title' => "계정정보",
|
||||
'label' => [
|
||||
'uid' => "번호",
|
||||
'id' => "계정",
|
||||
'passwd' => "암호",
|
||||
'title' => "계정정보",
|
||||
'label' => [
|
||||
'uid' => "번호",
|
||||
'id' => "계정",
|
||||
'passwd' => "암호",
|
||||
'confirmpassword' => "암호확인",
|
||||
'email' => "메일",
|
||||
'mobile' => "연락처",
|
||||
'role' => "권한",
|
||||
'name' => "이름",
|
||||
'status' => "상태",
|
||||
'updated_at' => "수정일",
|
||||
'created_at' => "작성일",
|
||||
'email' => "메일",
|
||||
'mobile' => "연락처",
|
||||
'role' => "권한",
|
||||
'name' => "이름",
|
||||
'status' => "상태",
|
||||
'updated_at' => "수정일",
|
||||
'created_at' => "작성일",
|
||||
],
|
||||
"ROLE" => [
|
||||
"guest" => "비회원",
|
||||
"user" => "일반회원",
|
||||
"vip" => "VIP회원",
|
||||
"manager" => "관리자",
|
||||
"ROLE" => [
|
||||
"user" => "일반회원",
|
||||
"vip" => "VIP회원",
|
||||
"manager" => "관리자",
|
||||
"cloudflare" => "Cloudflare관리자",
|
||||
"director" => "감독자",
|
||||
"master" => "마스터",
|
||||
"director" => "감독자",
|
||||
"master" => "마스터",
|
||||
],
|
||||
"STATUS" => [
|
||||
"use" => "사용",
|
||||
"use" => "사용",
|
||||
"unuse" => "사용않함",
|
||||
],
|
||||
];
|
||||
|
||||
@ -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'],
|
||||
@ -90,10 +89,10 @@ class GoogleAuth extends MyAuth
|
||||
if ($entity === null) {
|
||||
//없다면 새로 등록
|
||||
$formDatas = [
|
||||
'site' => $this->_site,
|
||||
'id' => $authInfo['id'],
|
||||
'name' => $authInfo['name'],
|
||||
'email' => $authInfo['email'],
|
||||
'site' => $this->_site,
|
||||
'id' => $authInfo['id'],
|
||||
'name' => $authInfo['name'],
|
||||
'email' => $authInfo['email'],
|
||||
'detail' => json_encode($authInfo),
|
||||
'status' => 'standby',
|
||||
];
|
||||
@ -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