dbms_init_base

This commit is contained in:
최준흠 2025-05-02 17:15:36 +09:00
parent 09a0e81247
commit f921c04108
25 changed files with 347 additions and 273 deletions

View File

@ -123,13 +123,15 @@ define('MESSAGES', [
'NOT_SYNC_NOTHING' => '동기화할 데이터가 없습니다.',
'NOT_SYNC_NOTHING_RESULT' => '동기화 결과가 없습니다.',
'NOT_SYNC_NOTHING_ERROR' => '동기화 결과가 없습니다.',
'LOGIN' => '로그인 하셨습니다.',
'LOGOUT' => '로그아웃 하셨습니다.'
]);
//URL
define('URLS', [
'LOGIN' => '/user/login',
'GOOGLE_LOGIN' => '/user/google_login',
'SIGNUP' => '/user/signup',
'LOGOUT' => '/user/logout',
'LOGIN' => '/auth/login',
'GOOGLE_LOGIN' => '/auth/google_login',
'SIGNUP' => '/auth/signup',
'LOGOUT' => '/auth/logout',
]);
//회원ROLE
define('ROLES', [

View File

@ -14,11 +14,11 @@ $routes->addPlaceholder('uuid', '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}
$routes->group('cli', ['namespace' => 'App\Controllers\CLI'], function ($routes) {});
$routes->group('', ['namespace' => 'App\Controllers'], function ($routes) {
$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');
$routes->group('auth', ['namespace' => 'App\Controllers\Auth'], function ($routes) {
$routes->get('login', 'LocalController::login_form');
$routes->post('login', 'LocalController::login');
$routes->get('google_login', 'GoogleController::login');
$routes->get('logout', 'LocalController::logout');
});
});
$routes->group('admin', ['namespace' => 'App\Controllers\Admin', 'filter' => 'authFilter:manager'], function ($routes) {

View File

@ -69,8 +69,9 @@ class MyLogController extends AdminController
protected function view_process($uid): mixed
{
$fields = [
'fields' => ['user_uid', 'class_name', 'method_name', $this->getService()->getModel()::TITLE, 'created_at', 'status', 'content'],
'fields' => ['user_uid', 'class_name', 'method_name', $this->getService()->getModel()::TITLE, 'status', 'created_at', 'content'],
];
$this->init('view', $fields);
return parent::view_process($uid);
}
}

View File

@ -0,0 +1,109 @@
<?php
namespace App\Controllers\Auth;
use App\Controllers\CommonController;
use CodeIgniter\HTTP\RedirectResponse;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface;
use App\Libraries\MySocket\GoogleSocket\API as GoogleSocket;
use App\Services\UserService;
use App\Entities\UserEntity as Entity;
abstract class AuthController extends CommonController
{
private ?GoogleSocket $_socket = null;
private ?UserService $_userService = null;
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
parent::initController($request, $response, $logger);
$this->layout = "auth";
$this->uri_path = "auth/";
$this->view_path = "auth" . DIRECTORY_SEPARATOR;
}
abstract protected function login_process(): Entity;
final public function getSocket()
{
if (!$this->_socket) {
$this->_socket = new GoogleSocket();
}
return $this->_socket;
}
final public function getUserService(): UserService
{
if (!$this->_userService) {
$this->_userService = new UserService($this->request);
}
return $this->_userService;
}
//Index,FieldForm관련
public function getFields(): array
{
return ['id', 'passwd'];
}
public function getFilterFields(): array
{
return ['role', 'status'];
}
public function getBatchJobFields(): array
{
return ['status'];
}
//Index,FieldForm관련
protected function getResultPageByActon(string $action, string $message = MESSAGES["SUCCESS"]): RedirectResponse|string
{
switch ($action) {
case 'login_form':
$result = view($this->view_path . $action, ['viewDatas' => $this->getViewDatas()]);
break;
default:
$result = parent::getResultPageByActon($action, $message);
break;
}
return $result;
}
//로그인화면
final public function login_form(): RedirectResponse|string
{
try {
$this->init(__FUNCTION__);
helper(['form']);
//구글 로그인 BUTTON용
$this->google_url = $this->getSocket()->createAuthUrl();
$this->forms = ['attributes' => ['method' => "post",], 'hiddens' => []];
return $this->getResultPageByActon($this->action);
} catch (\Exception $e) {
return redirect()->back()->withInput()->with('error', $e->getMessage());
}
}
//로그인
final public function login(): RedirectResponse|string
{
try {
$this->entity = $this->login_process();
return $this->getResultPageByActon($this->action, MESSAGES['LOGIN']);
} catch (\Exception $e) {
return redirect()->back()->withInput()->with('error', $e->getMessage());
}
}
//로그아웃
final public function logout(): RedirectResponse
{
try {
$this->init(__FUNCTION__);
$this->getService()->logout();
// 홈페이지로 리다이렉트
return redirect()->route('/')->with('error', MESSAGES['LOGOUT']);
} catch (\Exception $e) {
log_message("error", $e->getMessage());
return redirect()->back()->with('error', "로그아웃 중 오류가 발생했습니다.");
}
}
}

View File

@ -0,0 +1,41 @@
<?php
namespace App\Controllers\Auth;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface;
use App\Helpers\AuthHelper as Helper;
use App\Services\Auth\GoogleService as Service;
use App\Entities\UserEntity as Entity;
class GoogleController extends AuthController
{
private ?Service $_service = null;
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
parent::initController($request, $response, $logger);
$this->uri_path .= strtolower($this->getService()->getClassName()) . '/';
$this->title = lang("{$this->getService()->getClassPath()}.title");;
$this->helper = new Helper($this->getService());
}
final public function getService(): Service
{
if (!$this->_service) {
$this->_service = new Service($this->getSocket(), $this->request);
}
return $this->_service;
}
//로그인처리
protected function login_process(): Entity
{
$access_code = $this->request->getVar('code');
if (!$access_code) {
throw new \Exception("구글 로그인 실패");
}
return $this->getService()->login($this->getService()->checkUser($access_code));
}
}

View File

@ -0,0 +1,39 @@
<?php
namespace App\Controllers\Auth;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface;
use CodeIgniter\HTTP\RedirectResponse;
use App\Helpers\AuthHelper as Helper;
use App\Services\Auth\LocalService as Service;
use App\Entities\UserEntity as Entity;
class LocalController extends AuthController
{
private ?Service $_service = null;
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
parent::initController($request, $response, $logger);
$this->uri_path .= strtolower($this->getService()->getClassName()) . '/';
$this->title = lang("{$this->getService()->getClassPath()}.title");;
$this->helper = new Helper($this->getService());
}
final public function getService(): Service
{
if (!$this->_service) {
$this->_service = new Service($this->request);
}
return $this->_service;
}
//로그인처리
protected function login_process(): Entity
{
$this->init(__FUNCTION__);
$this->formDatas = $this->doValidate($this->action, $this->fields);
return $this->getService()->login($this->getService()->checkUser($this->formDatas));
}
}

View File

@ -115,7 +115,7 @@ abstract class CommonController extends BaseController
{
switch ($field) {
default:
$validation->setRule($field, $field, $rule ?? $this->getService()->getModel()->getFieldRule($action, $field));
$validation->setRule($field, $field, $rule ?? $this->getService()->getFieldRule($action, $field));
break;
}
return $validation;
@ -133,10 +133,12 @@ abstract class CommonController extends BaseController
$this->batchjob_fields = array_key_exists('batchjob_fields', $fields) && is_array($fields['batchjob_fields']) && count($fields['batchjob_fields']) ? $fields['filter_fields'] : $this->getBatchJobFields();
}
//데이터 검증
final protected function doValidate(string $action, array $fields): array
final protected function doValidate(string $action, array $fields, ?Validation $validation = null): array
{
//변경할 값 확인 : Upload된 파일 검증시 $this->request->getPOST()보다 먼처 체크필요
$validation = service('validation');
if (!$validation) {
$validation = service('validation');
}
// var_dump($this->field_rules);
// exit;
foreach ($fields as $field) {
@ -191,12 +193,7 @@ abstract class CommonController extends BaseController
//수정관련
protected function modify_form_process(mixed $uid): mixed
{
$this->getService()->getModel()->where($this->getService()->getModel()::PK, $uid);
$entity = $this->getService()->getEntity();
if (!$entity) {
throw new \Exception("해당 정보를 찾을수 없습니다.");
}
return $entity;
return $this->getService()->getEntity($uid);
}
final public function modify_form(mixed $uid): RedirectResponse|string
{
@ -215,11 +212,7 @@ abstract class CommonController extends BaseController
//데이터 검증
$this->formDatas = $this->doValidate($this->action, $this->fields);
//자신정보정의
$this->getService()->getModel()->where($this->getService()->getModel()::PK, $uid);
$entity = $this->getService()->getEntity();
if (!$entity) {
throw new \Exception(__FUNCTION__ . " => {$uid} 정보를 찾을수 없습니다.");
}
$entity = $this->getService()->getEntity($uid);
return $this->getService()->modify($entity, $this->formDatas);
}
final public function modify(int $uid): RedirectResponse|string
@ -245,11 +238,7 @@ abstract class CommonController extends BaseController
//데이터 검증
$this->formDatas = $this->doValidate($this->action, $this->fields);
//자신정보정의
$this->getService()->getModel()->where($this->getService()->getModel()::PK, $uid);
$entity = $this->getService()->getEntity();
if (!$entity) {
throw new \Exception(__FUNCTION__ . " => {$uid} 정보를 찾을수 없습니다.");
}
$entity = $this->getService()->getEntity($uid);
return $this->getService()->modify($entity, $this->formDatas);
}
final public function toggle(mixed $uid, string $field): RedirectResponse
@ -270,23 +259,19 @@ abstract class CommonController extends BaseController
}
}
//일괄처리작업
protected function batchjob_process(array $uids): array
protected function batchjob_process(array $entities): array
{
//데이터 검증
$this->formDatas = $this->doValidate($this->action, $this->fields);
$temps = [];
foreach ($uids as $uid) {
$entity = $this->getService()->getEntity();
if (!$entity) {
throw new \Exception("{$uid} 정보를 찾을수 없습니다.");
}
$temps[] = $entity;
foreach ($entities as $entity) {
// echo var_dump($entity->toArray());
// echo "<HR>";
// echo $this->formDatas['status'];
// exit;
$temps[] = $this->getService()->modify($entity, $this->formDatas);
}
$entities = [];
foreach ($temps as $entity) {
$entities[] = $this->getService()->modify($entity, $this->formDatas);
}
return $entities;
return $temps;
}
final public function batchjob(): RedirectResponse
{
@ -295,8 +280,8 @@ abstract class CommonController extends BaseController
try {
$this->init(__FUNCTION__);
//변경할 UIDS
$uids = $this->request->getVar('batchjob_uids');
if (!$uids) {
$uids = $this->request->getVar('batchjob_uids[]');
if (!is_array($uids) || !count($uids)) {
throw new \Exception("적용할 리스트를 선택하셔야합니다.");
}
//데이터가 있는경우 Field만 처리하기위해
@ -306,8 +291,16 @@ abstract class CommonController extends BaseController
$fields[] = $field;
}
}
if (!count($fields)) {
throw new \Exception("변경할 정보를 선택하셔야합니다.");
}
$this->fields = $fields;
$this->entities = $this->batchjob_process(explode(",", $uids));
$entities = [];
foreach ($uids as $uid) {
$entity = $this->getService()->getEntity($uid);
$entities[] = $entity;
}
$this->entities = $this->batchjob_process($entities);
$this->getService()->getModel()->transCommit();
$this->getMyLogService()->save($this->getService(), __FUNCTION__, $this->myauth, MESSAGES["SUCCESS"]);
return $this->getResultPageByActon($this->action);
@ -333,11 +326,7 @@ abstract class CommonController extends BaseController
$this->getService()->getModel()->transStart();
try {
$this->init(__FUNCTION__);
$this->getService()->getModel()->where($this->getService()->getModel()::PK, $uid);
$entity = $this->getService()->getEntity();
if (!$entity) {
throw new \Exception("{$uid} 정보를 찾을수 없습니다.");
}
$entity = $this->getService()->getEntity($uid);
$this->entity = $this->delete_process($entity);
$this->getService()->getModel()->transCommit();
$this->getMyLogService()->save($this->getService(), __FUNCTION__, $this->myauth, MESSAGES["SUCCESS"]);
@ -349,27 +338,20 @@ abstract class CommonController extends BaseController
}
}
//일괄삭제
protected function batchjob_delete_process(array $uids): void
protected function batchjob_delete_process(array $entities): void
{
$entities = [];
foreach ($uids as $uid) {
$this->getService()->getModel()->where($this->getService()->getModel()::PK, $uid);
$entity = $this->getService()->getEntity();
if (!$entity) {
throw new \Exception("{$uid} 정보를 찾을수 없습니다.");
}
$entities[] = $entity;
}
$fail_cnt = 0;
$cnt = 0;
foreach ($entities as $entity) {
$result = $this->getService()->delete($entity);
if (!$result) {
LogCollector::error("[{$entity->getTitle()}] 삭제실패");
$fail_cnt++;
$cnt++;
}
}
if ($fail_cnt) {
throw new \Exception("총:" . count($entities) . "중에 " . $fail_cnt . "개를 실패");
if ($cnt) {
$message = "총:" . count($entities) . "중에 " . $cnt . "개를 실패";
LogCollector::error($message);
throw new \Exception($message);
}
}
final public function batchjob_delete(): RedirectResponse|string
@ -379,11 +361,16 @@ abstract class CommonController extends BaseController
try {
$this->init(__FUNCTION__);
//변경할 UIDS
$uids = $this->request->getVar('batchjob_uids');
if (!$uids) {
$uids = $this->request->getVar('batchjob_uids[]');
if (!is_array($uids) || !count($uids)) {
throw new \Exception("적용할 리스트를 선택하셔야합니다.");
}
$this->batchjob_delete_process(explode(",", $uids));
$entities = [];
foreach ($uids as $uid) {
$entity = $this->getService()->getEntity($uid);
$entities[] = $entity;
}
$this->batchjob_delete_process($entities);
$this->getService()->getModel()->transCommit();
$this->getMyLogService()->save($this->getService(), __FUNCTION__, $this->myauth, MESSAGES["SUCCESS"]);
return $this->getResultPageByActon($this->action);
@ -398,8 +385,7 @@ abstract class CommonController extends BaseController
protected function view_process($uid): mixed
{
//자신정보정의
$this->getService()->getModel()->where($this->getService()->getModel()::PK, $uid);
$entity = $this->getService()->getEntity();
$entity = $this->getService()->getEntity($uid);
if (!$entity) {
throw new \Exception("해당 사용자정보를 찾을수 없습니다.");
}
@ -531,7 +517,7 @@ abstract class CommonController extends BaseController
case 'pdf':
// string buffer에서 읽어오는 경우
$this->entities = $this->index_process();
$html = view('templates' . DIRECTORY_SEPARATOR . $this->action, ['viewDatas' => $this->getViewDatas()]);
$html = view('templates' . DIRECTORY_SEPARATOR . 'common' . DIRECTORY_SEPARATOR . __FUNCTION__, ['viewDatas' => $this->getViewDatas()]);
//data loading
$reader = new Html();
$loaded_data = $reader->loadFromString($html);
@ -542,11 +528,7 @@ abstract class CommonController extends BaseController
if (!$uid) {
throw new \Exception("{$output_type}은 반드시 uid의 값이 필요합니다.");
}
$this->getService()->getModel()->where($this->getService()->getModel()::PK, $uid);
$this->entity = $this->getService()->getEntity();
if (!$this->entity) {
throw new \Exception("{$uid} 정보를 찾을수 없습니다.");
}
$this->entity = $this->getService()->getEntity($uid);
list($file_name, $uploaded_filename) = $this->entity->getDownlaodFile();
$full_path = WRITEPATH . DIRECTORY_SEPARATOR . "uploads" . DIRECTORY_SEPARATOR . $uploaded_filename;
break;

View File

@ -1,122 +0,0 @@
<?php
namespace App\Controllers;
use App\Helpers\UserHelper as Helper;
use App\Libraries\MySocket\GoogleSocket\API as GoogleSocket;
use App\Services\Auth\GoogleService;
use App\Services\Auth\LocalService;
use App\Services\UserService as Service;
use CodeIgniter\HTTP\RedirectResponse;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface;
class UserController extends CommonController
{
private $_service = null;
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
parent::initController($request, $response, $logger);
$this->uri_path .= strtolower($this->getService()->getClassName()) . DIRECTORY_SEPARATOR;
$this->view_path = $this->uri_path;
$this->title = lang("{$this->getService()->getClassPath()}.title");;
$this->helper = new Helper($this->getService());
}
final public function getService(): Service
{
if (!$this->_service) {
$this->_service = new Service($this->request);
}
return $this->_service;
}
//Index,FieldForm관련
public function getFields(): array
{
return ['id', $this->getService()->getModel()::TITLE, 'email', 'mobile', 'role', 'status'];
}
public function getFilterFields(): array
{
return ['role', 'status'];
}
public function getBatchJobFields(): array
{
return ['status'];
}
//Index,FieldForm관련
private function login_init(string $action, array $fields = []): void
{
$this->action = $action;
$fields = ['fields' => ['id', 'passwd'],];
$this->init($action, $fields);
}
//로그인화면
public function login_form(): RedirectResponse|string
{
try {
$this->login_init('login');
helper(['form']);
//구글 로그인 BUTTON용
$google_socket = new GoogleSocket();
$this->google_url = $google_socket->createAuthUrl();
$this->forms = ['attributes' => ['method' => "post",], 'hiddens' => []];
return view($this->view_path . "login", data: ['viewDatas' => $this->getViewDatas()]);
} catch (\Exception $e) {
log_message("error", $e->getMessage());
return redirect()->back()->withInput()->with('error', __FUNCTION__ . " 실패하였습니다.\n" . $e->getMessage());
}
}
//로그인처리
public function login(): RedirectResponse|string
{
try {
$this->login_init('login');
$this->formDatas = $this->doValidate($this->action, $this->fields);
$auth = new LocalService();
$auth->login($auth->checkUser($this->formDatas));
$this->message = "로그인 성공";
log_message("notice", __FUNCTION__ . $this->message);
// 이전 URL로 리다이렉트
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());
}
}
public function google_login(): RedirectResponse|string
{
try {
$access_code = $this->request->getVar('code');
if (!$access_code) {
throw new \Exception("구글 로그인 실패");
}
$auth = new GoogleService(new GoogleSocket());
$auth->login($auth->checkUser($access_code));
$this->message = "로그인 성공";
log_message("notice", __FUNCTION__ . $this->message);
// 이전 URL로 리다이렉트
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());
}
}
//로그아웃
public function logout(): RedirectResponse
{
try {
$auth = new LocalService();
$auth->logout();
// 성공 메시지 설정
$message = "로그아웃 되었습니다.";
// 홈페이지로 리다이렉트
return redirect()->route('/')->with('message', $message);
} catch (\Exception $e) {
log_message("error", $e->getMessage());
return redirect()->back()->with('error', "로그아웃 중 오류가 발생했습니다.");
}
}
}

View File

@ -27,7 +27,7 @@ abstract class CommonEntity extends Entity
$field = constant("static::TITLE");
return $this->attributes[$field];
}
final public function getUpdatedAt(): string
final public function getUpdatedAt(): string|null
{
return $this->attributes['updated_at'];
}

View File

@ -0,0 +1,31 @@
<?php
namespace App\Helpers;
class AuthHelper extends CommonHelper
{
public function __construct($service)
{
parent::__construct($service);
}
public function getFieldForm(string $field, mixed $value, array $viewDatas, array $extras = []): string
{
if (in_array($viewDatas['action'], ['create', 'modify'])) {
$extras = (strpos($viewDatas['field_rules'][$field], 'required') !== false) ? ["class" => "form-control", "required" => "", ...$extras] : ["class" => "form-control", ...$extras];
}
$value = $value ?: DEFAULTS['EMPTY'];
switch ($field) {
case 'id':
case $this->getService()->getModel()::TITLE:
$form = form_input($field, $value, $extras);
break;
case 'passwd':
$form = form_password($field, "", ["autocomplete" => $field, ...$extras]);
break;
default:
$form = parent::getFieldForm($field, $value, $viewDatas, $extras);
break;
}
return $form;
} //
}

View File

@ -288,14 +288,14 @@ class CommonHelper
$action = form_submit("batchjob_submit", '일괄처리', [
"formaction" => current_url() . '/batchjob',
"class" => "btn btn-outline btn-warning",
"onclick" => "return submitBatchJob()"
// "onclick" => "return submitBatchJob()"
]);
break;
case 'batchjob_delete':
$action = form_submit("batchjob_submit", '일괄삭제', [
"formaction" => current_url() . '/batchjob_delete',
"class" => "btn btn-outline btn-danger",
"onclick" => "return submitBatchJobDelete()"
// "onclick" => "return submitBatchJobDelete()"
]);
break;
}

View File

@ -115,14 +115,14 @@ class API extends GoogleSocket
// 'picture' => 'https://lh3.googleusercontent.com/a/VDSJj3D925VP-pt9ppnwsPtm4pyYE6IO7bei-RyVM0Q=s96-c',
// 'verifiedEmail' => true,
// ))
public function getEntity(): Entity
public function signup(): Entity
{
$this->getClient()->setAccessToken($this->getToken());
$oauth = new Oauth2($this->getClient());
$userInfo = $oauth->userinfo->get();
$detail = var_export($userInfo, true);
// log_message("debug", $detail);
// 사용자정보 설정하기
return $this->setEntity($userInfo->id, $userInfo->name, $userInfo->email, $detail);
// 사용자정보 등록하기
return $this->signup_process($userInfo->id, $userInfo->name, $userInfo->email, $detail);
}
}

View File

@ -133,7 +133,7 @@ class CURL extends GoogleSocket
// 'picture' => 'https://lh3.googleusercontent.com/a/AAcHTteFSgefsdfsdRJBkJA2tBEmg4PQrvI1Ta_5IXu5=s96-c',
// 'verifiedEmail' => true,
// ))
public function getEntity(): Entity
public function signup(): Entity
{
$options = [
"headers" => [
@ -165,7 +165,7 @@ class CURL extends GoogleSocket
log_message("error", $message);
throw new \Exception($message);
}
// 사용자정보 설정하기
return $this->setEntity($userInfo["id"], $userInfo["name"], $userInfo["email"], $detail);
// 사용자정보 등록하기
return $this->signup_process($userInfo["id"], $userInfo["name"], $userInfo["email"], $detail);
}
}

View File

@ -21,7 +21,7 @@ abstract class GoogleSocket extends MySocket
public function __construct() {}
abstract public function createAuthUrl(): string;
abstract public function setToken(string $access_code): void;
abstract public function getEntity(): Entity;
abstract public function signup(): Entity;
final public function getSession(): Session
{
if ($this->_session == null) {
@ -44,11 +44,10 @@ abstract class GoogleSocket extends MySocket
}
return $this->_service;
}
final protected function setEntity(string $id, string $name, string $email, string $detail): Entity
final protected function signup_process(string $id, string $name, string $email, string $detail): Entity
{
$this->getService()->getModel()->where(Model::SITE, $this->getSite());
$this->getService()->getModel()->where('id', $id);
$entity = $this->getEntity();
//이미 등록된 사용자인지 확인 후 없으면 등록 처리리
$entity = $this->getService()->getEntity([Model::SITE => $this->getSite(), 'id' => $id], false);
if (!$entity) {
//Transaction Start
$this->getService()->getModel()->transStart();

View File

@ -138,26 +138,22 @@ abstract class CommonModel extends Model
private function save_process($entity): mixed
{
try {
// 최종 변경사항이 없으면
if (!$entity->hasChanged()) {
throw new \Exception(__FUNCTION__ . " 변경된 내용이 없습니다.");
}
// 최종 저장 시 오류 발생하면
if (!$this->save($entity)) {
throw new \Exception(var_export($this->errors(), true));
}
// 최종 변경사항이 없으면
if (!$entity->hasChanged()) {
return $entity;
} catch (\Exception $e) {
}
// 최종 저장 시 오류 발생하면
if (!$this->save($entity)) {
$message = sprintf(
"\n------%s SQL오류-----\n%s\n%s\n------------------------------\n",
"\n------%s 오류-----\n%s\n%s\n------------------------------\n",
__FUNCTION__,
$this->getLastQuery(),
$e->getMessage()
var_export($this->errors(), true)
);
LogCollector::error($message);
throw new \Exception($message);
}
return $entity;
}
public function create(array $formDatas, mixed $entity): mixed
{
@ -165,6 +161,7 @@ abstract class CommonModel extends Model
$this->setValidationRules($this->getFieldRules('create', $this->allowedFields));
// 저장하기 전에 데이터 값 변경이 필요한 Field
foreach (array_keys($formDatas) as $field) {
LogCollector::debug("{$field}:{$formDatas[$field]}");
$entity->$field = $this->convertEntityData($field, $formDatas);
}
// dd($entity);
@ -182,12 +179,12 @@ abstract class CommonModel extends Model
// Field에 맞는 Validation Rule 재정의
$this->setValidationRules($this->getFieldRules('modify', $this->allowedFields));
// 저장하기 전에 데이터 값 변경이 필요한 Field
LogCollector::debug("[{$entity->getPK()}/{$entity->getTitle()}] 변경내용");
foreach (array_keys($formDatas) as $field) {
LogCollector::debug("{$field}/{$entity->$field}=>{$formDatas[$field]}");
$entity->$field = $this->convertEntityData($field, $formDatas);
}
$this->save_process($entity);
// log_message("debug", $this->getTable() . " => " . __FUNCTION__ . " DB 작업 완료");
return $entity;
return $this->save_process($entity);
}
//List관련

View File

@ -3,15 +3,18 @@
namespace App\Services\Auth;
use App\Entities\UserEntity as Entity;
use App\Models\UserModel as Model;
use App\Services\CommonService;
use CodeIgniter\HTTP\IncomingRequest;
use CodeIgniter\Session\Session;
// 참고:https://github.com/SyntaxPhoenix/iloclient
abstract class AuthService extends CommonService
{
private ?Session $_session = null;
public function __construct() {}
public function __construct(?IncomingRequest $request = null)
{
parent::__construct($request);
}
final public function getSession(): Session
{
if (!$this->_session) {
@ -80,10 +83,11 @@ abstract class AuthService extends CommonService
return '/'; // 기본 URL
}
final public function login(Entity $entity): void
public function login(Entity $entity): Entity
{
$this->getSession()->set(SESSION_NAMES['ISLOGIN'], true);
$this->getSession()->set(SESSION_NAMES['AUTH'], ['uid' => $entity->getPK(), 'id' => $entity->getID(), 'name' => $entity->getTitle(), 'role' => $entity->role]);
return $entity;
}
final public function logout(): void

View File

@ -2,24 +2,23 @@
namespace App\Services\Auth;
use App\Models\UserModel as Model;
use App\Entities\UserEntity as Entity;
use App\Models\UserModel as Model;
// use App\Libraries\MySocket\GoogleSocket\CURL;
use CodeIgniter\Exceptions\PageNotFoundException;
use CodeIgniter\HTTP\IncomingRequest;
class GoogleService extends AuthService
{
private $_mySocket = null;
private string $_access_code = "";
public function __construct(mixed $mySocket)
public function __construct(mixed $mySocket, ?IncomingRequest $request = null)
{
$this->_mySocket = $mySocket;
parent::__construct();
parent::__construct($request);
}
final public function getClassName(): string
{
return "AuthGoogle";
return "GoogleAuth";
}
final public function getClassPath(): string
{
@ -34,29 +33,24 @@ class GoogleService extends AuthService
return Entity::class;
}
public function getMySocket(string $access_code): mixed
{
if (!$this->_mySocket) {
throw new \Exception("Socket 방식이 지정되지 않았습니다.");
}
$this->_mySocket->setToken($this->_access_code);
return $this->_mySocket;
}
public function checkUser(string $access_code): Entity
{
try {
// Google 서비스 설정
$userSNS_entity = $this->getMySocket($access_code)->getUserSNSEntity();
if (!$this->_mySocket) {
throw new \Exception("Socket 방식이 지정되지 않았습니다.");
}
$this->_mySocket->setToken($access_code);
$sns_entity = $this->_mySocket->signup();
// local db 사용와의 연결 확인
$this->getModel()->where($this->getModel()::PK, $userSNS_entity->getParent());
$this->getModel()->where($this->getModel()::PK, $sns_entity->getParent());
$entity = $this->getEntity();
if (!$entity) {
throw new PageNotFoundException("회원[{$userSNS_entity->getTitle()}]님은 아직 로컬사용자 연결이 이루어지지 않았습니다.");
throw new PageNotFoundException("회원[{$sns_entity->getTitle()}]님은 아직 로컬사용자 연결이 이루어지지 않았습니다.");
}
return $entity;
} catch (\Google_Service_Exception $e) {
log_message('error', '구글 서비스 예외: ' . $e->getMessage());
log_message('error', '구글 서비스 예외발생: ' . $e->getMessage());
throw new PageNotFoundException("구글 로그인 중 오류가 발생했습니다. 다시 시도해 주세요.");
} catch (\Exception $e) {
log_message('error', $e->getMessage());

View File

@ -2,18 +2,19 @@
namespace App\Services\Auth;
use App\Models\UserModel as Model;
use App\Entities\UserEntity as Entity;
use App\Models\UserModel as Model;
use CodeIgniter\HTTP\IncomingRequest;
class LocalService extends AuthService
{
public function __construct()
public function __construct(?IncomingRequest $request = null)
{
parent::__construct();
parent::__construct($request);
}
final public function getClassName(): string
{
return "AuthLocal";
return "LocalAuth";
}
final public function getClassPath(): string
{
@ -30,13 +31,6 @@ class LocalService extends AuthService
public function checkUser(array $formDatas): Entity
{
if (!isset($formDatas['id']) || !$formDatas['id']) {
throw new \Exception("사용자ID를 입력해주세요!");
}
if (!isset($formDatas['passwd']) || !$formDatas['passwd']) {
throw new \Exception("암호를 입력해주세요!");
}
$this->getModel()->where("id", $formDatas['id']);
$entity = $this->getEntity();
if (is_null($entity) || !isset($entity->passwd)) {

View File

@ -10,7 +10,7 @@ abstract class CommonService
private $_serviceDatas = [];
private $_model = null;
protected ?IncomingRequest $request = null;
public function __construct(IncomingRequest $_request)
public function __construct(?IncomingRequest $_request = null)
{
$this->request = $_request;
}
@ -41,9 +41,15 @@ abstract class CommonService
}
return $this->_model;
}
final public function getEntity(): mixed
final public function getEntity(mixed $where, $isThrow = true): mixed
{
return $this->getModel()->first();
$entity = is_array($where) ? $this->getModel()->where($where)->first() : $this->getModel()->find($where);
if (!$entity) {
if ($isThrow) {
throw new \Exception(__FUNCTION__ . " => 해당 정보를 찾을수 없습니다.");
}
}
return $entity;
}
final public function getEntities(array $columns = ['*']): array
{
@ -87,7 +93,6 @@ abstract class CommonService
}
public function modify(mixed $entity, array $formDatas): mixed
{
// die(var_export($formDatas, true));
$entity = $this->getModel()->modify($entity, $formDatas);
LogCollector::info("[{$entity->getTitle()}]" . MESSAGES["UPDATED"] . ":");
return $entity;

View File

@ -10,7 +10,7 @@ use App\Libraries\LogCollector;
class MyLogService extends CommonService
{
public function __construct(IncomingRequest $request)
public function __construct(?IncomingRequest $request = null)
{
parent::__construct($request);
}

View File

@ -9,7 +9,7 @@ use CodeIgniter\HTTP\IncomingRequest;
class UserService extends CommonService
{
protected ?IncomingRequest $request = null;
public function __construct(IncomingRequest $request)
public function __construct(?IncomingRequest $request = null)
{
parent::__construct($request);
}
@ -59,8 +59,4 @@ class UserService extends CommonService
// die(var_export($formDatas, true));
return parent::modify($entity, $formDatas);
}
public function delete(mixed $entity): bool
{
return parent::delete($entity);
}
}

View File

@ -17,6 +17,7 @@
<link href="/css/<?= $viewDatas['layout'] ?>/resizeTable.css" media="screen" rel="stylesheet" type="text/css" />
<div class="index_body">
<?= $this->include("templates/{$viewDatas['layout']}/index_content_top"); ?>
<?= form_open(current_url(), ['id' => 'batchjob_form', 'method' => "post"]) ?>
<table class="index_table data table table-bordered table-hover table-striped" data-rtc-resizable-table="reisze_table">
<thead>
<tr>
@ -44,6 +45,7 @@
</tbody>
</table>
<?= $this->include("templates/{$viewDatas['layout']}/index_content_batchjob"); ?>
<?= form_close() ?>
<div class=" index_pagination"><?= $viewDatas['pagination'] ?></div>
</div>
<div class="index_bottom"><?= $this->include("templates/common/modal_fetch"); ?></div>

View File

@ -1,13 +1,14 @@
<?= $this->section('content') ?>
<?php if ($error = session('error')): ?><?= $viewDatas['helper']->alert($error) ?><?php endif ?>
<link href="/css/front/login.css" media="screen" rel="stylesheet" type="text/css" />
<div class="login-page">
<div class="login-content">
<div class="login-container">
<h2 class="login-title">CF-MGR 로그인</h2>
<h2 class="login-title">DBMS 로그인</h2>
<?= form_open(current_url(), $viewDatas['forms']['attributes'], $viewDatas['forms']['hiddens']) ?>
<div class="input-group">
<label for="userId">아이디</label>
<input type="text" id="userId" name="id" value="<?= set_value('id') ?>" required>
<input type="text" id="userId" name="id" value="<?= old('id') ?>" required>
</div>
<div class="input-group">
<label for="userPassword">비밀번호</label>

View File

@ -1,6 +1,4 @@
<div class="index_batchjob">
<?= form_open("", ['id' => 'batchjob_form', 'method' => "post"]) ?>
<input type="hidden" name="batchjob_uids" id="batchjob_uids" value="">
<ul class="nav justify-content-center">
<li class="nav-item"><?= form_checkbox(array("id" => "batchjobuids_checkbox")) ?>ALL</li>
<?php foreach ($viewDatas['batchjob_fields'] as $field): ?>
@ -10,9 +8,10 @@
<li class="nav-item"><?= $viewDatas['helper']->getListButton('create', $viewDatas) ?></li>
<li class="nav-item"><?= $viewDatas['helper']->getListButton('batchjob_delete', $viewDatas) ?></li>
</ul>
<?= form_close() ?>
</div>
<script>
//이 스크립트를 사용하려면 Form 안에 아래 Tag필요
// <input type = "hidden"name = "batchjob_uids"id = "batchjob_uids"value = "" >
function submitBatchJob() {
var validate = false;
//batchjob용 선택사항 검증