cfmgrv4 init...2
This commit is contained in:
parent
d7e48a4ac8
commit
6849f34934
@ -13,8 +13,7 @@ abstract class CommonController extends BaseController
|
||||
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
||||
{
|
||||
parent::initController($request, $response, $logger);
|
||||
// 세션 서비스 초기화
|
||||
$this->session = \Config\Services::session();
|
||||
$this->myauth = service('myauth');
|
||||
}
|
||||
final public function __get($name)
|
||||
{
|
||||
@ -31,20 +30,4 @@ abstract class CommonController extends BaseController
|
||||
{
|
||||
return $this->_viewDatas;
|
||||
}
|
||||
|
||||
final protected function pushCurrentUrl()
|
||||
{
|
||||
$urlStack = $this->session->get('url_stack') ?? [];
|
||||
$urlStack[] = current_url() . $this->request->getUri()->getQuery() ? "?" . $this->request->getUri()->getQuery() : "";
|
||||
$this->session->set('url_stack', $urlStack);
|
||||
}
|
||||
|
||||
final protected function popPreviousUrl()
|
||||
{
|
||||
$urlStack = $this->session->get('url_stack') ?? [];
|
||||
if (!empty($urlStack)) {
|
||||
return array_pop($urlStack);
|
||||
}
|
||||
return '/'; // 기본 URL
|
||||
}
|
||||
}
|
||||
|
||||
@ -88,9 +88,7 @@ abstract class MVController extends CommonController
|
||||
));
|
||||
}
|
||||
}
|
||||
protected function create_form_process(): void
|
||||
{
|
||||
}
|
||||
protected function create_form_process(): void {}
|
||||
final protected function create_form_procedure(): RedirectResponse|string
|
||||
{
|
||||
try {
|
||||
@ -214,7 +212,7 @@ abstract class MVController extends CommonController
|
||||
$this->message = "{$this->class_name} : 일괄처리작업이 완료되었습니다.";
|
||||
log_message("notice", __FUNCTION__ . $this->message);
|
||||
// 이전 URL로 리다이렉트
|
||||
return redirect()->to($this->popPreviousUrl())->with('error', $this->message);
|
||||
return redirect()->to($this->myauth->popPreviousUrl())->with('error', $this->message);
|
||||
} catch (\Exception $e) {
|
||||
//Transaction Rollback
|
||||
$this->getModel()->transRollback();
|
||||
@ -235,7 +233,7 @@ abstract class MVController extends CommonController
|
||||
$this->getModel()->transCommit();
|
||||
log_message("notice", __FUNCTION__ . $this->message);
|
||||
// 이전 URL로 리다이렉트
|
||||
return redirect()->to($this->popPreviousUrl())->with('error', $this->message);
|
||||
return redirect()->to($this->myauth->popPreviousUrl())->with('error', $this->message);
|
||||
} catch (\Exception $e) {
|
||||
//Transaction Rollback
|
||||
$this->getModel()->transRollback();
|
||||
@ -263,7 +261,7 @@ abstract class MVController extends CommonController
|
||||
$this->getModel()->transCommit();
|
||||
log_message("notice", __FUNCTION__ . $this->message);
|
||||
// 이전 URL로 리다이렉트
|
||||
return redirect()->to($this->popPreviousUrl())->with('error', $this->message);
|
||||
return redirect()->to($this->myauth->popPreviousUrl())->with('error', $this->message);
|
||||
} catch (\Exception $e) {
|
||||
//Transaction Rollback
|
||||
$this->getModel()->transRollback();
|
||||
@ -361,7 +359,7 @@ abstract class MVController extends CommonController
|
||||
//모델 처리
|
||||
$this->entitys = $this->list_entitys_process();
|
||||
// 현재 URL을 스택에 저장
|
||||
$this->pushCurrentUrl();
|
||||
$this->myauth->pushCurrentUrl(current_url() . $this->request->getUri()->getQuery() ? "?" . $this->request->getUri()->getQuery() : "");
|
||||
return view(
|
||||
$this->view_path . "index",
|
||||
['viewDatas' => $this->getViewDatas()]
|
||||
|
||||
@ -108,7 +108,7 @@ class UserController extends FrontController
|
||||
$this->message = "로그인 성공";
|
||||
log_message("notice", __FUNCTION__ . $this->message);
|
||||
// 이전 URL로 리다이렉트
|
||||
return redirect()->to($this->popPreviousUrl())->with('message', $this->message);
|
||||
return redirect()->to($this->myauth->popPreviousUrl())->with('message', $this->message);
|
||||
} catch (\Exception $e) {
|
||||
log_message("error", $e->getMessage());
|
||||
return redirect()->back()->withInput()->with('error', __FUNCTION__ . " 실패하였습니다.\n" . $e->getMessage());
|
||||
@ -127,7 +127,7 @@ class UserController extends FrontController
|
||||
$this->message = "로그인 성공";
|
||||
log_message("notice", __FUNCTION__ . $this->message);
|
||||
// 이전 URL로 리다이렉트
|
||||
return redirect()->to($this->popPreviousUrl())->with('message', $this->message);
|
||||
return redirect()->to($this->myauth->popPreviousUrl())->with('message', $this->message);
|
||||
} catch (\Exception $e) {
|
||||
log_message("error", $e->getMessage());
|
||||
return redirect()->back()->withInput()->with('error', __FUNCTION__ . " 실패하였습니다.\n" . $e->getMessage());
|
||||
|
||||
@ -30,16 +30,18 @@ class AuthFilter implements FilterInterface
|
||||
// log_message("debug", var_export($arguments, true));
|
||||
// 로그인 않했으면
|
||||
if (!$auth->isLoggedIn()) {
|
||||
$urlStack = session()->get('url_stack') ?? [];
|
||||
$urlStack[] = current_url() . $request->getUri()->getQuery() ? "?" . $request->getUri()->getQuery() : "";
|
||||
session()->set('url_stack', $urlStack);
|
||||
$currentURL = current_url();
|
||||
$queryString = $request->getUri()->getQuery();
|
||||
$auth->pushCurrentUrl($queryString ? "{$currentURL}?{$queryString}" : $currentURL);
|
||||
return redirect()->to(URLS['LOGIN'])->with('error', '로그인을하셔야합니다.');
|
||||
}
|
||||
//User Role 비교 // 회원 ROLES이 필요ROLE($arguments[0]) 목록에 존재하지 않으면(ACL)
|
||||
$auth = session()->get(SESSION_NAMES['AUTH']);
|
||||
$roles = explode(DEFAULTS['DELIMITER_ROLE'], $auth['role']);
|
||||
if (!isset($auth['role']) || !in_array($arguments[0], $roles)) {
|
||||
return redirect()->back()->with('error', "회원[{$auth['name']}]님은 접속에 필요한 권한{$arguments[0]}이 없습니다. ");
|
||||
if (!$auth->isAccessRole($arguments[0])) {
|
||||
$auth->popPreviousUrl();
|
||||
return redirect()->back()->with(
|
||||
'error',
|
||||
"회원[{$auth->getAuthInfo('name')}]님은 접속에 필요한 권한{$arguments[0]}이 없습니다. "
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -4,24 +4,63 @@ namespace App\Libraries\MyAuth;
|
||||
|
||||
use App\Entities\UserEntity;
|
||||
use App\Libraries\CommonLibrary;
|
||||
|
||||
use CodeIgniter\Session\Session;
|
||||
// 참고:https://github.com/SyntaxPhoenix/iloclient
|
||||
class MyAuth extends CommonLibrary
|
||||
{
|
||||
private $_session = null;
|
||||
public function __construct()
|
||||
private ?Session $_session = null;
|
||||
public function __construct() {}
|
||||
final public function getSession(): Session
|
||||
{
|
||||
if ($this->_session == null) {
|
||||
$this->_session = \Config\Services::session();
|
||||
}
|
||||
return $this->_session;
|
||||
}
|
||||
final public function getAuthInfo(string $key = ""): array|string
|
||||
{
|
||||
if ($key) {
|
||||
return isset($this->getSession()->get(SESSION_NAMES['AUTH'])[$key]) ? $this->getSession()->get(SESSION_NAMES['AUTH'])[$key] : "";
|
||||
}
|
||||
return $this->getSession()->get(SESSION_NAMES['AUTH']);
|
||||
}
|
||||
|
||||
final public function isLoggedIn(): bool
|
||||
{
|
||||
return $this->_session->has(SESSION_NAMES['ISLOGIN']);
|
||||
return $this->getSession()->has(SESSION_NAMES['ISLOGIN']);
|
||||
}
|
||||
final public function isAccessRole(string $role): bool
|
||||
{
|
||||
if ($this->getAuthInfo('role') === "") {
|
||||
return false;
|
||||
}
|
||||
$roles = explode(DEFAULTS['DELIMITER_ROLE'], $this->getAuthInfo('role'));
|
||||
if (!in_array($role, $roles)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
final public function pushCurrentUrl(string $url): void
|
||||
{
|
||||
$urlStack = $this->getSession()->get('url_stack') ?? [];
|
||||
$urlStack[] = $url;
|
||||
$this->getSession()->set('url_stack', $urlStack);
|
||||
}
|
||||
|
||||
final public function popPreviousUrl()
|
||||
{
|
||||
$urlStack = $this->getSession()->get('url_stack') ?? [];
|
||||
if (!empty($urlStack)) {
|
||||
return array_pop($urlStack);
|
||||
}
|
||||
return '/'; // 기본 URL
|
||||
}
|
||||
|
||||
final public function login(UserEntity $entity): void
|
||||
{
|
||||
$this->_session->set(SESSION_NAMES['ISLOGIN'], true);
|
||||
$this->_session->set(SESSION_NAMES['AUTH'], [
|
||||
$this->getSession()->set(SESSION_NAMES['ISLOGIN'], true);
|
||||
$this->getSession()->set(SESSION_NAMES['AUTH'], [
|
||||
'uid' => $entity->getPK(),
|
||||
'name' => $entity->getTitle(),
|
||||
'role' => $entity->role
|
||||
@ -31,11 +70,11 @@ class MyAuth extends CommonLibrary
|
||||
final public function logout(): void
|
||||
{
|
||||
// 세션 데이터 삭제
|
||||
$this->_session->remove(SESSION_NAMES['ISLOGIN']);
|
||||
$this->_session->remove(SESSION_NAMES['AUTH']);
|
||||
$this->getSession()->remove(SESSION_NAMES['ISLOGIN']);
|
||||
$this->getSession()->remove(SESSION_NAMES['AUTH']);
|
||||
|
||||
// 모든 세션 데이터 삭제
|
||||
$this->_session->destroy();
|
||||
$this->getSession()->destroy();
|
||||
|
||||
// 세션 쿠키 삭제
|
||||
if (ini_get("session.use_cookies")) {
|
||||
@ -53,6 +92,6 @@ class MyAuth extends CommonLibrary
|
||||
|
||||
// 세션 재생성
|
||||
session_start();
|
||||
$this->_session->regenerate(true);
|
||||
$this->getSession()->regenerate(true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -84,7 +84,7 @@ class API extends GoogleSocket
|
||||
$this->getClient()->refreshToken($tokenInfo['refresh_token']);
|
||||
}
|
||||
// 세션에 Token 값 설정
|
||||
$this->session->set($this->_token_name, $this->_access_token);
|
||||
$this->getSession()->set($this->_token_name, $this->_access_token);
|
||||
}
|
||||
|
||||
// DEBUG - 2024-10-10 12:00:13 --> \Google\Service\Oauth2\Userinfo::__set_state(array(
|
||||
|
||||
@ -102,7 +102,7 @@ class CURL extends GoogleSocket
|
||||
// 토큰 정보 가져오기
|
||||
$this->_access_token = $tokenInfo[$this->_token_name];
|
||||
// 세션에 Token 값 설정
|
||||
$this->session->set($this->_token_name, $this->_access_token);
|
||||
$this->getSession()->set($this->_token_name, $this->_access_token);
|
||||
}
|
||||
|
||||
// throw new \Exception(__METHOD__ . "에서 데이터 처리 필요");
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Libraries\MySocket\GoogleSocket;
|
||||
|
||||
use Config\Services;
|
||||
use CodeIgniter\Session\Session;
|
||||
use CodeIgniter\Exceptions\PageNotFoundException;
|
||||
use App\Models\UserSNSModel;
|
||||
use App\Libraries\MySocket\MySocket;
|
||||
@ -13,19 +13,23 @@ abstract class GoogleSocket extends MySocket
|
||||
private string $_site = "GOOGLE";
|
||||
private ?UserSNSModel $_model = null;
|
||||
protected $_client = null;
|
||||
protected $session;
|
||||
private ?Session $_session = null;
|
||||
protected string $_access_token = "";
|
||||
protected string $_token_name = "access_token";
|
||||
public function __construct()
|
||||
{
|
||||
$this->session = Services::session();
|
||||
}
|
||||
public function __construct() {}
|
||||
abstract public function createAuthUrl(): string;
|
||||
abstract public function setToken(string $access_code): void;
|
||||
abstract public function getUserSNSEntity(): UserSNSEntity;
|
||||
final public function getSession(): Session
|
||||
{
|
||||
if ($this->_session == null) {
|
||||
$this->_session = \Config\Services::session();
|
||||
}
|
||||
return $this->_session;
|
||||
}
|
||||
final public function getToken(): string
|
||||
{
|
||||
return $this->session->get($this->_token_name);
|
||||
return $this->getSession()->get($this->_token_name);
|
||||
}
|
||||
final public function getSite(): string
|
||||
{
|
||||
|
||||
@ -21,10 +21,10 @@
|
||||
</ul>
|
||||
<ul class="nav justify-content-end">
|
||||
<li class="nav-item">
|
||||
<?php if ($viewDatas['session']->get(SESSION_NAMES['ISLOGIN'])): ?>
|
||||
<?php if ($viewDatas['myauth']->isLoggedIn()): ?>
|
||||
<div class="btn-group">
|
||||
<button type="button" class="btn btn-outline-primary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
<b><?= ICONS['LOGIN'] . $viewDatas['session']->get(SESSION_NAMES['AUTH'])['name'] ?></b>
|
||||
<b><?= ICONS['LOGIN'] . $viewDatas['myauth']->getAuthInfo('name') ?></b>
|
||||
</button>
|
||||
<ul class="dropdown-menu dropdown-menu-end">
|
||||
<li><?= form_label(
|
||||
@ -32,7 +32,7 @@
|
||||
"modify",
|
||||
[
|
||||
"class" => "dropdown-item",
|
||||
"data-src" => "/admin/user/modify/" . $viewDatas['session']->get(SESSION_NAMES['AUTH'])['uid'],
|
||||
"data-src" => "/admin/user/modify/" . $viewDatas['myauth']->getAuthInfo('uid'),
|
||||
"data-bs-toggle" => "modal",
|
||||
"data-bs-target" => "#index_action_form"
|
||||
]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user