dbms_init...1

This commit is contained in:
최준흠 2025-06-06 14:00:13 +09:00
parent 460fa7e347
commit 6ced3137cb
37 changed files with 320 additions and 420 deletions

View File

@ -15,9 +15,9 @@ $routes->group('cli', ['namespace' => 'App\Controllers\CLI'], function ($routes)
$routes->group('', ['namespace' => 'App\Controllers'], function ($routes) {
$routes->get('/', 'Home::index');
$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('login', 'LocalController::create_form');
$routes->post('login', 'LocalController::create');
$routes->get('google_login', 'GoogleController::create');
$routes->get('logout', 'LocalController::logout');
});
});

View File

@ -50,11 +50,9 @@ class AccountController extends CustomerController
}
return $entity;
}
protected function create_process(string $action, array $fields, array $formDatas = []): AccountEntity
protected function create_process(array $formDatas): AccountEntity
{
//데이터 검증
$formDatas = $this->doValidate($action, $fields, $formDatas);
$entity = $this->getService()->create($formDatas);
$entity = parent::create_process($formDatas);
//고객예치금처리
$this->setAccountBalance($formDatas);
return $entity;

View File

@ -2,17 +2,14 @@
namespace App\Controllers\Admin\Customer;
use App\Entities\Customer\AccountEntity;
use App\Entities\Customer\ClientEntity;
use App\Entities\Customer\CouponEntity;
use App\Helpers\Customer\ClientHelper;
use App\Services\Customer\ClientService;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use CodeIgniter\Validation\Validation;
use Psr\Log\LoggerInterface;
use App\Helpers\Customer\ClientHelper;
use App\Services\Customer\ClientService;
class ClientController extends CustomerController
{
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
@ -39,7 +36,7 @@ class ClientController extends CustomerController
return $this->_helper;
}
//Index,FieldForm관련
protected function setValidation(Validation $validation, string $action, string $field, string $rule): Validation
protected function setValidation(Validation $validation, string $field, string $rule): Validation
{
switch ($field) {
case 'role':
@ -47,7 +44,7 @@ class ClientController extends CustomerController
$validation->setRule("{$field}.*", $field, $rule);
break;
default:
$validation = parent::setValidation($validation, $action, $field, $rule);
$validation = parent::setValidation($validation, $field, $rule);
break;
}
return $validation;

View File

@ -49,11 +49,9 @@ class CouponController extends CustomerController
}
return $entity;
}
protected function create_process(string $action, array $fields, array $formDatas = []): CouponEntity
protected function create_process(array $formDatas): CouponEntity
{
//데이터 검증
$formDatas = $this->doValidate($action, $fields, $formDatas);
$entity = $this->getService()->create($formDatas);
$entity = parent::create_process($formDatas);
//고객쿠폰처리
$this->setCouponBalance($formDatas);
return $entity;

View File

@ -50,11 +50,9 @@ class PointController extends CustomerController
}
return $entity;
}
protected function create_process(string $action, array $fields, array $formDatas = []): PointEntity
protected function create_process(array $formDatas): PointEntity
{
//데이터 검증
$formDatas = $this->doValidate($action, $fields, $formDatas);
$entity = $this->getService()->create($formDatas);
$entity = parent::create_process($formDatas);
//고객포인트처리
$this->setPointBalance($formDatas);
return $entity;

View File

@ -45,22 +45,21 @@ class ServiceController extends CustomerController
}
return $this->_serviceItemService;
}
protected function getResultPageByActon(string $action, string $message = MESSAGES["SUCCESS"]): RedirectResponse|string
protected function getResultSuccess(string $message = MESSAGES["SUCCESS"]): RedirectResponse|string
{
$this->action = $action;
switch ($action) {
switch ($this->getAction()) {
case 'index':
$this->getHelper()->setViewDatas($this->getViewDatas());
$result = view($this->view_path . 'service' . DIRECTORY_SEPARATOR . $action, ['viewDatas' => $this->getViewDatas()]);
$result = view($this->view_path . 'service' . DIRECTORY_SEPARATOR . $this->getAction(), ['viewDatas' => $this->getViewDatas()]);
break;
default:
$result = parent::getResultPageByActon($action, $message);
$result = parent::getResultSuccess($message);
break;
}
return $result;
}
//Index,FieldForm관련
protected function index_process(string $action, array $fields): array
protected function index_process(): array
{
//추가 Field작업 처리
$this->item_types = lang($this->getServiceItemService()->getClassName() . '.' . strtoupper('ITEM_TYPE'));
@ -68,7 +67,7 @@ class ServiceController extends CustomerController
$this->field_options = $this->getFormFieldOption($field, $this->field_options);
}
$entities = [];
foreach (parent::index_process($action, $fields) as $entity) {
foreach (parent::index_process() as $entity) {
foreach ($this->item_types as $field => $label) {
$itemEntities = $this->getServiceItemService()->getEntities(['item_type' => $field]);
$entity->setItemEntities($field, $itemEntities);

View File

@ -74,34 +74,32 @@ class ServiceItemController extends CustomerController
}
return $options;
}
protected function getResultPageByActon(string $action, string $message = MESSAGES["SUCCESS"]): RedirectResponse|string
protected function getResultSuccess(string $message = MESSAGES["SUCCESS"]): RedirectResponse|string
{
$this->action = $action;
switch ($action) {
switch ($this->getAction()) {
case 'index':
$this->getHelper()->setViewDatas($this->getViewDatas());
$result = view($this->view_path . 'popup' . DIRECTORY_SEPARATOR . $action, ['viewDatas' => $this->getViewDatas()]);
$result = view($this->view_path . 'popup' . DIRECTORY_SEPARATOR . $this->getAction(), ['viewDatas' => $this->getViewDatas()]);
break;
default:
$result = parent::getResultPageByActon($action, $message);
$result = parent::getResultSuccess($message);
break;
}
return $result;
}
//Index,FieldForm관련
protected function create_process(string $action, array $fields, array $formDatas = []): mixed
protected function create_process(array $formDatas): mixed
{
$this->field_rules = $this->getFieldRules($action, $fields);
//데이터 검증
$validatedFormDatas = $this->doValidate($action, $fields, $formDatas);
//도메인의 경우 domaininfo에 등록 후 ItemEntity의 item_uid에 넣어줘야함
if ($validatedFormDatas['item_type'] === 'DOMAIN') {
$serviceEntity = $this->getServiceService()->getEntity($validatedFormDatas['serviceinfo_uid']);
$tempDatas = ['clientinfo_uid' => $serviceEntity->getClientInfoUID(), 'domain' => $validatedFormDatas['item_uid']];
$equipmentEntity = $this->getEquipmentService($validatedFormDatas['item_type'])->create($tempDatas);
//도메인의 경우 domaininfo에 등록 후 ServiceItemEntity의 item_uid에 넣고 create해야함
if ($formDatas['item_type'] === 'DOMAIN') {
$serviceEntity = $this->getServiceService()->getEntity($formDatas['serviceinfo_uid']);
$equipmentEntity = $this->getEquipmentService($formDatas['item_type'])->create([
'clientinfo_uid' => $serviceEntity->getClientInfoUID(),
'domain' => $formDatas['item_uid']
]);
//도메인용 항목의 item_uid로 전달함
$validatedFormDatas['item_uid'] = $equipmentEntity->getPK();
$formDatas['item_uid'] = $equipmentEntity->getPK();
}
return $this->getService()->create($validatedFormDatas);
return parent::create_process($formDatas);
}
}

View File

@ -48,17 +48,15 @@ class LineController extends PartController
//Index,FieldForm관련
//생성
protected function create_process(string $action, array $fields, array $formDatas = []): LineEntity
protected function create_process(array $formDatas): LineEntity
{
//Line 등록
if (!$this->getHelper()->isValidCIDR($this->formDatas['bandwith'])) {
throw new \Exception("{$this->formDatas['bandwith']}는 CIDR 형식에 부합되지 않습니다.");
if (!$this->getHelper()->isValidCIDR($formDatas['bandwith'])) {
throw new \Exception("{$formDatas['bandwith']}는 CIDR 형식에 부합되지 않습니다.");
}
//데이터 검증
$validatedFormDatas = $this->doValidate($action, $fields, $formDatas);
return $this->getService()->create($validatedFormDatas);
//IP 등록
foreach ($this->getHelper()->cidrToIpRange($this->formDatas['bandwith']) as $ip) {
$entity = parent::create_process($formDatas);
//Prefixed IP to array 등록
foreach ($this->getHelper()->cidrToIpRange($formDatas['bandwith']) as $ip) {
$this->getIpService()->createByLineInfo($entity, $ip);
}
return $entity;

View File

@ -32,20 +32,6 @@ class Home extends AdminController
}
//Index,FieldForm관련
public function getFields(): array
{
return [];
}
public function getFilterFields(): array
{
return [];
}
public function getBatchJobFields(): array
{
return [];
}
//Index,FieldForm관련
public function index(): string
{
helper(['form']);

View File

@ -40,7 +40,7 @@ class UserController extends AdminController
return $this->_helper;
}
//Index,FieldForm관련
protected function setValidation(Validation $validation, string $action, string $field, string $rule): Validation
protected function setValidation(Validation $validation, string $field, string $rule): Validation
{
switch ($field) {
case 'role':
@ -48,7 +48,7 @@ class UserController extends AdminController
$validation->setRule("{$field}.*", $field, $rule);
break;
default:
$validation = parent::setValidation($validation, $action, $field, $rule);
$validation = parent::setValidation($validation, $field, $rule);
break;
}
return $validation;

View File

@ -26,7 +26,7 @@ abstract class AuthController extends CommonController
$this->individualScripts = [];
}
abstract protected function getSNSButton(): string;
abstract protected function login_process(string $action): UserEntity;
abstract protected function create_process(array $formDatas): UserEntity;
final public function getHelper(): mixed
{
@ -35,50 +35,15 @@ abstract class AuthController extends CommonController
}
return $this->_helper;
}
final public function getFields(): array
{
return ['id', 'passwd'];
}
//로그인화면
final public function login_form(): RedirectResponse|string
public function create_form_process(): void
{
$action = __FUNCTION__;
try {
helper(['form']);
$this->sns_buttoh = $this->getSNSButton();
$this->forms = ['attributes' => ['method' => "post",], 'hiddens' => []];
return $this->getResultPageByActon($action);
} catch (\Exception $e) {
if (env('app.debug.' . $action)) {
echo $e->getMessage();
exit;
} else {
return redirect()->back()->withInput()->with('error', $e->getMessage());
}
}
}
//로그인
final public function login(): RedirectResponse|string
{
$action = __FUNCTION__;
try {
$this->entity = $this->login_process($action);
return $this->getResultPageByActon($action, MESSAGES['LOGIN']);
} catch (\Exception $e) {
if (env('app.debug.' . $action)) {
echo $e->getMessage();
exit;
} else {
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']);

View File

@ -41,12 +41,11 @@ class GoogleController extends AuthController
}
//로그인처리
protected function login_process(string $action): UserEntity
protected function create_process(array $formDatas): UserEntity
{
$access_code = $this->request->getVar('code');
if (!$access_code) {
if (!array_key_exists('access_code', $formDatas) || !$formDatas['access_code']) {
throw new \Exception("구글 로그인 실패");
}
return $this->getService()->login($this->getService()->checkUser($access_code));
return ($this->getService()->login($formDatas));
}
}

View File

@ -29,11 +29,8 @@ class LocalController extends AuthController
return "";
}
//로그인처리
protected function login_process(string $action, array $formDatas = []): UserEntity
protected function create_process(array $formDatas): UserEntity
{
foreach ($this->fields as $field) {
$formDatas[] = $this->request->getVar($field);
}
return $this->getService()->login($this->getService()->checkUser($formDatas));
return ($this->getService()->login($formDatas));
}
}

View File

@ -23,6 +23,7 @@ abstract class CommonController extends BaseController
private $_myAuth = null;
private ?MyLogService $_myLogService = null;
private $_viewDatas = [];
private $_control = [];
abstract public function getService(): mixed;
abstract function getHelper(): mixed;
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
@ -34,13 +35,6 @@ abstract class CommonController extends BaseController
$this->myAuthName = $this->getMyAuth()->getNameByAuthInfo();
$this->myAuthUID = $this->getMyAuth()->getUIDByAuthInfo();
}
//각 Field 초기화
$this->form_fields = $this->getFormFields();
$this->filter_fields = $this->getFilterFields();
$this->field_options = $this->getFormFieldOptions($this->getFormFields());
$this->index_fields = $this->getIndexFields();
$this->view_fields = $this->getViewFields();
$this->batchjob_fields = $this->getBatchJobFields();
}
final public function __get($name)
{
@ -72,75 +66,114 @@ abstract class CommonController extends BaseController
return $this->_myLogService;
}
//Index,FieldForm관련
public function getFormFields(?array $form_fields = null): array
final protected function setAction(string $action): void
{
if (is_array($form_fields)) {
$this->form_fields = $form_fields;
$this->_control['action'] = $action;
}
if (!is_array($this->form_fields)) {
$this->form_fields = $this->getService()->getFormFields();;
}
return $this->form_fields;
}
public function getFilterFields(?array $filter_fields = null): array
final protected function getAction(): string
{
if (is_array($filter_fields)) {
$this->filter_fields = $filter_fields;
if (!array_key_exists('action', $this->_control)) {
throw new \Exception("action이 정의되지 않았습니다.");
}
if (!is_array($this->filter_fields)) {
$this->filter_fields = $this->getService()->getFilterFields();;
return $this->_control['action'];
}
return $this->filter_fields;
}
public function getIndexFields(?array $index_fields = null): array
final protected function setFormFields(array $fields): void
{
if (is_array($index_fields)) {
$this->index_fields = $index_fields;
$this->_control['form_fields'] = $fields;
}
if (!is_array($this->index_fields)) {
$this->index_fields = $this->getService()->getIndexFields();;
}
return $this->index_fields;
}
public function getViewFields(?array $view_fields = null): array
final protected function getFormFields(): array
{
if (is_array($view_fields)) {
$this->view_fields = $view_fields;
return $this->_control['form_fields'] ?? [];
}
if (!is_array($this->view_fields)) {
$this->view_fields = $this->getService()->getViewFields();;
}
return $this->view_fields;
}
public function getBatchJobFields(?array $batchjob_fields = null): array
final protected function setIndexFields(array $fields): void
{
if (is_array($batchjob_fields)) {
$this->batchjob_fields = $batchjob_fields;
$this->_control['index_fields'] = $fields;
}
if (!is_array($this->batchjob_fields)) {
$this->batchjob_fields = $this->getService()->getBatchJobFields();;
final protected function getIndexFields(): array
{
return $this->_control['index_fields'] ?? [];
}
return $this->batchjob_fields;
final protected function setViewFields(array $fields): void
{
$this->_control['view_fields'] = $fields;
}
protected function getFieldRule(string $action, string $field): string
final protected function getViewFields(): array
{
return $this->_control['view_fields'] ?? [];
}
final protected function setFilterFields(array $fields): void
{
$this->_control['filter_fields'] = $fields;
}
final protected function getFilterFields(): array
{
return $this->_control['filter_fields'] ?? [];
}
final protected function setBatchjobFields(array $fields): void
{
$this->_control['batchjob_fields'] = $fields;
}
final protected function getBatchjobFields(): array
{
return $this->_control['batchjob_fields'] ?? [];
}
final protected function setFieldRule(string $field, string $rule): void
{
if (!array_key_exists('field_rules', $this->_control)) {
$this->_control['field_rules'] = [];
}
$this->_control['field_rules'][$field] = $rule;
}
final protected function getFieldRule(string $field): string
{
return $this->_control['field_rules'][$field] ?? [];
}
final protected function getFieldRules(): array
{
return $this->_control['field_rules'] ?? [];
}
final protected function setFilterFieldOption(string $field, array $options): void
{
if (!array_key_exists('filter_optons', $this->_control)) {
$this->_control['filter_optons'] = [];
}
$this->_control['filter_optons'][$field] = $options;
}
final protected function getFilterFieldOption(string $field): string
{
return $this->_control['filter_optons'][$field] ?? [];
}
final protected function getFilterFieldOptions(): array
{
return $this->_control['filter_optons'] ?? [];
}
protected function initAction(string $action): void
{ //각 Field 초기화
$this->setAction($action);
$this->setFormFields($this->getService()->getFormFields());
$this->setIndexFields($this->getService()->getIndexFields());
$this->setViewFields($this->getService()->setViewFields());
$this->setFilterFields($this->getService()->getFilterFields());
foreach ($this->getFormFields() as $field) {
$this->setFieldRule($field, $this->getFormFieldRule($this->getAction(), $field));
}
foreach ($this->getFilterFields() as $field) {
$this->setFilterFieldOption($field, $this->getFormFieldOption($field, $this->getFilterFieldOptions()));
}
}
protected function getFormFieldRule(string $action, string $field): string
{
if (is_array($field)) {
throw new \Exception(__FUNCTION__ . "=> field가 array 입니다.\n" . var_export($field, true));
}
switch ($field) {
default:
$rule = $this->getService()->getFieldRule($action, $field);
$rule = $this->getService()->getFormFieldRule($action, $field);
break;
}
return $rule;
}
final protected function getFieldRules(string $action, array $fields, $rules = []): array
{
foreach ($fields as $field) {
$rules[$field] = $this->getFieldRule($action, $field);
}
return $rules;
}
protected function getFormFieldOption(string $field, array $options): array
{
switch ($field) {
@ -153,20 +186,7 @@ abstract class CommonController extends BaseController
}
return $options;
}
final protected function getFormFieldOptions(array $fields, array $options = []): array
{
foreach ($fields as $field) {
if (is_array($field)) {
throw new \Exception(__FUNCTION__ . "에서 field array 입니다.\n" . var_export($field, true));
}
if (!array_key_exists($field, $options)) {
$options[$field] = [];
}
$options = $this->getFormFieldOption($field, $options);
}
return $options;
}
protected function setValidation(Validation $validation, string $action, string $field, string $rule): Validation
protected function setValidation(Validation $validation, string $field, string $rule): Validation
{
switch ($field) {
default:
@ -177,14 +197,14 @@ abstract class CommonController extends BaseController
}
//Field관련
//데이터 검증
final protected function doValidate(string $action, array $fields, array $formDatas, ?Validation $validation = null): array
final protected function doValidate(array $rules, array $formDatas, ?Validation $validation = null): array
{
//변경할 값 확인 : Upload된 파일 검증시 $this->request->getPOST()보다 먼처 체크필요
if (!$validation) {
$validation = service('validation');
}
foreach ($fields as $field) {
$validation = $this->setValidation($validation, $action, $field, $this->getFieldRule($action, $field));
foreach ($rules as $field => $rule) {
$validation = $this->setValidation($validation, $field, $rule);
}
if (!$validation->run($formDatas)) {
throw new \Exception("{$this->getService()->getClassName()} 작업 데이터 검증 오류발생\n" . implode(
@ -192,14 +212,26 @@ abstract class CommonController extends BaseController
$validation->getErrors()
));
}
return $validation->getValidated();
return $formDatas;
// return $validation->getValidated();
}
protected function getResultPageByActon(string $action, string $message = MESSAGES["SUCCESS"]): RedirectResponse|string
protected function getResultFail(string $message = MESSAGES["FAILED"]): RedirectResponse|string
{
$this->action = $action;
switch ($action) {
if (env('app.debug.' . $this->getAction())) {
$result = $message;
} else {
LogCollector::debug($message);
$this->getMyLogService()->save($this->getService(), __FUNCTION__, $this->getMyAuth(), $message);
$result = redirect()->back()->withInput()->with('error', $message);
}
return $result;
}
protected function getResultSuccess(string $message = MESSAGES["SUCCESS"]): RedirectResponse|string
{
switch ($this->getAction()) {
case 'create':
case 'modify':
$this->getMyLogService()->save($this->getService(), __FUNCTION__, $this->getMyAuth(), $message);
$result = $this->view($this->entity->getPK());
break;
case 'create_form':
@ -208,7 +240,7 @@ abstract class CommonController extends BaseController
case 'index':
case 'view':
// $this->getHelper()->setViewDatas($this->getViewDatas());
$result = view($this->view_path . $action, ['viewDatas' => $this->getViewDatas()]);
$result = view($this->view_path . $this->getAction(), ['viewDatas' => $this->getViewDatas()]);
break;
default:
$result = redirect()->to($this->getMyAuth()->popPreviousUrl())->with('error', $message);
@ -219,14 +251,12 @@ abstract class CommonController extends BaseController
//Index,FieldForm관련
// 생성
final protected function create_form_process($action): void
{
$this->field_rules = $this->getFieldRules($action, $this->getFormFields());
}
protected function create_form_process(): void {}
final public function create_form(): RedirectResponse|string
{
$action = 'create';
try {
//각 Field 초기화
$this->initAction(__FUNCTION__);
helper(['form']);
//filter_fields에 해당하는 값이 있을 경우 정의
foreach ($this->getFilterFields() as $field) {
@ -235,61 +265,48 @@ abstract class CommonController extends BaseController
$this->$field = $value;
}
}
$this->create_form_process($action);
$this->create_form_process();
$this->forms = ['attributes' => ['method' => "post",], 'hiddens' => []];
return $this->getResultPageByActon($action);
return $this->getResultSuccess();
} catch (\Exception $e) {
if (env('app.debug.' . $action)) {
echo $e->getMessage();
exit;
} else {
return redirect()->back()->withInput()->with('error', $e->getMessage());
return $this->getResultFail($e->getMessage());
}
}
}
protected function create_process(string $action, array $fields, array $formDatas = []): mixed
protected function create_process(array $formDatas): mixed
{
$this->field_rules = $this->getFieldRules($action, $fields);
//데이터 검증
$validatedFormDatas = $this->doValidate($action, $fields, $formDatas);
return $this->getService()->create($validatedFormDatas);
$formDatas = $this->doValidate($this->getFieldRules(), $formDatas);
return $this->getService()->create($formDatas);
}
final public function create(): RedirectResponse|string
{
$action = __FUNCTION__;
$this->getService()->getModel()->transStart();
try {
//각 Field 초기화
$this->initAction(__FUNCTION__);
//입력값정의
$formDatas = [];
foreach ($this->getFormFields() as $field) {
$formDatas[] = $this->request->getVar($field);
}
$this->entity = $this->create_process($action, $this->getFormFields(), $formDatas);
$this->entity = $this->create_process($formDatas);
$this->getService()->getModel()->transCommit();
$this->getMyLogService()->save($this->getService(), __FUNCTION__, $this->getMyAuth(), MESSAGES["SUCCESS"]);
return $this->getResultPageByActon($action);
return $this->getResultSuccess();
} catch (\Exception $e) {
$this->getService()->getModel()->transRollback();
LogCollector::debug($e->getMessage());
$this->getMyLogService()->save($this->getService(), __FUNCTION__, $this->getMyAuth(), MESSAGES["FAILED"]);
if (env('app.debug.' . $action)) {
echo $e->getMessage();
exit;
} else {
return redirect()->back()->withInput()->with('error', $e->getMessage());
}
return $this->getResultFail($e->getMessage());
}
}
//수정관련
final protected function modify_form_process(string $action, mixed $entity): mixed
protected function modify_form_process(mixed $entity): mixed
{
$this->field_rules = $this->getFieldRules($action, $this->getFormFields());
return $entity;
}
final public function modify_form(mixed $uid): RedirectResponse|string
{
$action = 'modify';
try {
//각 Field 초기화
$this->initAction(__FUNCTION__);
helper(['form']);
//filter_fields에 해당하는 값이 있을 경우 정의
foreach ($this->getFilterFields() as $field) {
@ -300,108 +317,86 @@ abstract class CommonController extends BaseController
}
//기존 Entity 가져오기
$entity = $this->getService()->getEntity($uid);
$this->entity = $this->modify_form_process($action, $entity);
$this->entity = $this->modify_form_process($entity);
$this->forms = ['attributes' => ['method' => "post",], 'hiddens' => []];
return $this->getResultPageByActon($action);
$this->getService()->getModel()->transCommit();
return $this->getResultSuccess();
} catch (\Exception $e) {
if (env('app.debug.' . $action)) {
echo $e->getMessage();
exit;
} else {
return redirect()->back()->withInput()->with('error', $e->getMessage());
return $this->getResultFail($e->getMessage());
}
}
}
protected function modify_process(string $action, mixed $entity, array $fields, array $formDatas = []): mixed
protected function modify_process(mixed $entity, array $formDatas): mixed
{
$this->field_rules = $this->getFieldRules($action, $fields);
//데이터 검증
$validatedFormDatas = $this->doValidate($action, $fields, $formDatas);
return $this->getService()->modify($entity, $validatedFormDatas);
$formDatas = $this->doValidate($this->getFieldRules(), $formDatas);
return $this->getService()->modify($entity, $formDatas);
}
final public function modify(int $uid): RedirectResponse|string
{
$action = __FUNCTION__;
//Transaction Start
$this->getService()->getModel()->transStart();
try {
//기존 Entity 가져오기
$entity = $this->getService()->getEntity($uid);
//각 Field 초기화
$this->initAction(__FUNCTION__);
//입력값정의
$formDatas = [];
foreach ($this->getFormFields() as $field) {
$formDatas[] = $this->request->getVar($field);
}
//기존 Entity 가져오기
$entity = $this->getService()->getEntity($uid);
$this->entity = $this->modify_process($action, $entity, $this->getFormFields(), $formDatas);
$this->entity = $this->modify_process($entity, $formDatas);
$this->getService()->getModel()->transCommit();
$this->getMyLogService()->save($this->getService(), __FUNCTION__, $this->getMyAuth(), MESSAGES["SUCCESS"]);
return $this->getResultPageByActon($action);
return $this->getResultSuccess();
} catch (\Exception $e) {
$this->getService()->getModel()->transRollback();
LogCollector::debug($e->getMessage());
$this->getMyLogService()->save($this->getService(), __FUNCTION__, $this->getMyAuth(), MESSAGES["FAILED"]);
if (env('app.debug.' . $action)) {
echo $e->getMessage();
exit;
} else {
return redirect()->back()->withInput()->with('error', $e->getMessage());
}
return $this->getResultFail($e->getMessage());
}
}
//단일필드작업
protected function toggle_process(string $action, mixed $entity, array $fields, array $formDatas = []): mixed
protected function toggle_process(mixed $entity, array $formDatas): mixed
{
$this->field_rules = $this->getFieldRules($action, $fields);
//데이터 검증
$validatedFormDatas = $this->doValidate($action, $fields, $formDatas);
return $this->getService()->modify($entity, $validatedFormDatas);
$formDatas = $this->doValidate($this->getFieldRules(), $formDatas);
return $this->getService()->modify($entity, $formDatas);
}
final public function toggle(mixed $uid, string $field): RedirectResponse
{
$action = __FUNCTION__;
//Transaction Start
$this->getService()->getModel()->transStart();
try {
//데이터가 있는경우 Field만 처리하기위해
$fields = [$field];
//입력값정의
$formDatas = [$this->request->getVar($field)];
//기존 Entity 가져오기
$entity = $this->getService()->getEntity($uid);
$this->entity = $this->toggle_process($action, $entity, $fields, $formDatas);
//각 Field 초기화:Field는 한개만 존재하므로 Field와 Rule을 재정의
$this->setAction(__FUNCTION__);
$this->setFormFields([$field]);
$this->setFieldRule($field, $this->getFormFieldRule($this->getAction(), $field));
//입력값정의
$formDatas = [$this->request->getVar($field)];
$this->entity = $this->toggle_process($entity, $formDatas);
$this->getService()->getModel()->transCommit();
$this->getMyLogService()->save($this->getService(), __FUNCTION__, $this->getMyAuth(), MESSAGES["SUCCESS"]);
return $this->getResultPageByActon($action);
return $this->getResultSuccess();
} catch (\Exception $e) {
$this->getService()->getModel()->transRollback();
LogCollector::debug($e->getMessage());
$this->getMyLogService()->save($this->getService(), __FUNCTION__, $this->getMyAuth(), MESSAGES["FAILED"]);
if (env('app.debug.' . $action)) {
echo $e->getMessage();
exit;
} else {
return redirect()->back()->withInput()->with('error', $e->getMessage());
}
return $this->getResultFail($e->getMessage());
}
}
//일괄처리작업
protected function batchjob_process(string $action, mixed $entity, array $fields, array $formDatas = []): array
protected function batchjob_process(mixed $entity, array $formDatas): mixed
{
$this->field_rules = $this->getFieldRules($action, $fields);
//데이터 검증
$validatedFormDatas = $this->doValidate($action, $fields, $formDatas);
return $this->getService()->modify($entity, $validatedFormDatas);
$formDatas = $this->doValidate($this->getFieldRules(), $formDatas);
return $this->getService()->modify($entity, $formDatas);
}
final public function batchjob(): RedirectResponse
{
$action = __FUNCTION__;
//Transaction Start
$this->getService()->getModel()->transStart();
try {
//데이터가 있는경우 Field만 처리하기위해
//변경할 FormField 정의
$fields = [];
$formDatas = [];
foreach ($this->getBatchJobFields() as $field) {
foreach ($this->getBatchjobFields() as $field) {
$value = $this->request->getVar($field);
if ($value) {
$fields[] = $field;
@ -411,31 +406,29 @@ abstract class CommonController extends BaseController
if (!count($fields)) {
throw new \Exception("변경할 정보를 선택하셔야합니다.");
}
//변경할 UIDS
//변경할 UIDS 정의
$uids = $this->request->getVar('batchjob_uids[]');
if (!is_array($uids) || !count($uids)) {
throw new \Exception("적용할 리스트를 선택하셔야합니다.");
}
//각 Field 초기화:Bachjob의 데이터가 있는경우 Field만 처리하기위해 Field와 Rule을 재정의
$this->setAction(__FUNCTION__);
$this->setFormFields($fields);
foreach ($this->getFormFields() as $field) {
$this->setFieldRule($field, $this->getFormFieldRule($this->getAction(), $field));
}
$entities = [];
foreach ($uids as $uid) {
//기존 Entity 가져오기
$entity = $this->getService()->getEntity($uid);
$entities[] = $this->batchjob_process($action, $entity, $fields, $formDatas);
$entities[] = $this->batchjob_process($entity, $formDatas);
}
$this->entities = $entities;
$this->getService()->getModel()->transCommit();
$this->getMyLogService()->save($this->getService(), __FUNCTION__, $this->getMyAuth(), MESSAGES["SUCCESS"]);
return $this->getResultPageByActon($action);
return $this->getResultSuccess();
} catch (\Exception $e) {
$this->getService()->getModel()->transRollback();
LogCollector::debug($e->getMessage());
$this->getMyLogService()->save($this->getService(), __FUNCTION__, $this->getMyAuth(), MESSAGES["FAILED"]);
if (env('app.debug.' . $action)) {
echo $e->getMessage();
exit;
} else {
return redirect()->back()->withInput()->with('error', $e->getMessage());
}
return $this->getResultFail($e->getMessage());
}
}
@ -450,26 +443,19 @@ abstract class CommonController extends BaseController
}
final public function delete(mixed $uid): RedirectResponse|string
{
$action = __FUNCTION__;
//Transaction Start
$this->getService()->getModel()->transStart();
try {
//각 Field 초기화:삭제는 다른 초기화 필요없음
$this->setAction(__FUNCTION__);
//기존 Entity 가져오기
$entity = $this->getService()->getEntity($uid);
$this->entity = $this->delete_process($entity);
$this->getService()->getModel()->transCommit();
$this->getMyLogService()->save($this->getService(), __FUNCTION__, $this->getMyAuth(), MESSAGES["SUCCESS"]);
return $this->getResultPageByActon($action);
return $this->getResultSuccess();
} catch (\Exception $e) {
$this->getService()->getModel()->transRollback();
LogCollector::debug($e->getMessage());
$this->getMyLogService()->save($this->getService(), __FUNCTION__, $this->getMyAuth(), MESSAGES["FAILED"]);
if (env('app.debug.' . $action)) {
echo $e->getMessage();
exit;
} else {
return redirect()->back()->withInput()->with('error', $e->getMessage());
}
return $this->getResultFail($e->getMessage());
}
}
//일괄삭제
@ -483,7 +469,6 @@ abstract class CommonController extends BaseController
}
final public function batchjob_delete(): RedirectResponse|string
{
$action = __FUNCTION__;
//Transaction Start
$this->getService()->getModel()->transStart();
try {
@ -492,6 +477,8 @@ abstract class CommonController extends BaseController
if (!is_array($uids) || !count($uids)) {
throw new \Exception("적용할 리스트를 선택하셔야합니다.");
}
//각 Field 초기화:삭제는 다른 초기화 필요없음
$this->setAction(__FUNCTION__);
$entities = [];
foreach ($uids as $uid) {
//기존 Entity 가져오기
@ -500,44 +487,31 @@ abstract class CommonController extends BaseController
}
$this->entities = $entities;
$this->getService()->getModel()->transCommit();
$this->getMyLogService()->save($this->getService(), __FUNCTION__, $this->getMyAuth(), MESSAGES["SUCCESS"]);
return $this->getResultPageByActon($action);
return $this->getResultSuccess();
} catch (\Exception $e) {
$this->getService()->getModel()->transRollback();
LogCollector::debug($e->getMessage());
$this->getMyLogService()->save($this->getService(), __FUNCTION__, $this->getMyAuth(), MESSAGES["FAILED"]);
if (env('app.debug.' . $action)) {
echo $e->getMessage();
exit;
} else {
return redirect()->back()->withInput()->with('error', $e->getMessage());
}
return $this->getResultFail($e->getMessage());
}
}
//View
protected function view_process(string $action, mixed $entity, array $fields): mixed
protected function view_process(mixed $entity): mixed
{
$this->field_rules = $this->getFieldRules($action, $fields);
return $entity;
}
final public function view(string $uid): RedirectResponse|string
{
$action = __FUNCTION__;
try {
//각 Field 초기화
$this->initAction(__FUNCTION__);
helper(['form']);
//기존 Entity 가져오기
$entity = $this->getService()->getEntity($uid);
$this->entity = $this->view_process($action, $entity, $this->getViewFields());
$this->entity = $this->view_process($entity);
$this->forms = ['attributes' => ['method' => "post",], 'hiddens' => []];
return $this->getResultPageByActon($action);
return $this->getResultSuccess();
} catch (\Exception $e) {
if (env('app.debug.index')) {
echo $e->getMessage();
exit;
} else {
return redirect()->back()->withInput()->with('error', $e->getMessage());
}
return $this->getResultFail($e->getMessage());
}
}
@ -611,9 +585,8 @@ abstract class CommonController extends BaseController
$this->total_page = $pager->getPageCount($pager_group);
return $pager->links($pager_group, $template);
}
protected function index_process(string $action, array $fields): array
protected function index_process(): array
{
$this->field_rules = $this->getFieldRules($action, $fields);
//조건절 처리
$this->setConditionForList();
//TotalCount
@ -629,20 +602,16 @@ abstract class CommonController extends BaseController
}
public function index()
{
$action = __FUNCTION__;
try {
//각 Field 초기화
$this->initAction(__FUNCTION__);
// 현재 URL을 스택에 저장
$this->getMyAuth()->pushCurrentUrl($this->request->getUri()->getPath() . ($this->request->getUri()->getQuery() ? "?" . $this->request->getUri()->getQuery() : ""));
helper(['form']);
$this->entities = $this->index_process($action, $this->getIndexFields());
return $this->getResultPageByActon($action);
$this->entities = $this->index_process();
return $this->getResultSuccess();
} catch (\Exception $e) {
if (env('app.debug.' . $action)) {
echo $e->getMessage();
exit;
} else {
return redirect()->back()->withInput()->with('error', $e->getMessage());
}
return $this->getResultFail($e->getMessage());
}
}
@ -667,15 +636,16 @@ abstract class CommonController extends BaseController
// Download
final public function download(string $output_type, mixed $uid = false): DownloadResponse|RedirectResponse
{
$action = __FUNCTION__;
try {
//각 Field 초기화
$this->initAction(__FUNCTION__);
//URL처리
// $this->uri = $this->request->getUri();
switch ($output_type) {
case 'excel':
case 'pdf':
// string buffer에서 읽어오는 경우
$this->entities = $this->index_process($action, $this->getIndexFields());
$this->entities = $this->index_process();
$html = view('templates' . DIRECTORY_SEPARATOR . 'common' . DIRECTORY_SEPARATOR . __FUNCTION__, ['viewDatas' => $this->getViewDatas()]);
//data loading
$reader = new Html();
@ -694,12 +664,7 @@ abstract class CommonController extends BaseController
}
return $this->response->download($full_path, null)->setFileName($file_name);
} catch (\Exception $e) {
if (env('app.debug.' . $action)) {
echo $e->getMessage();
exit;
} else {
return redirect()->back()->withInput()->with('error', $e->getMessage());
}
return $this->getResultFail($e->getMessage());
}
}
}

View File

@ -80,14 +80,14 @@ abstract class CommonModel extends Model
$data[8] = chr(ord($data[8]) & 0x3f | 0x80); // variant 10
return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4));
}
final protected function getFieldRules(string $action, array $fields, $rules = []): array
final protected function getFormFieldRules(string $action, array $fields, $rules = []): array
{
foreach ($fields as $field) {
$rules[$field] = $this->getFieldRule($action, $field);
$rules[$field] = $this->getFormFieldRule($action, $field);
}
return $rules;
}
public function getFieldRule(string $action, string $field): string
public function getFormFieldRule(string $action, string $field): string
{
if (is_array($field)) {
throw new \Exception(__FUNCTION__ . "=> field가 array 입니다.\n" . var_export($field, true));

View File

@ -24,7 +24,7 @@ class AccountModel extends CustomerModel
{
parent::__construct();
}
public function getFieldRule(string $action, string $field): string
public function getFormFieldRule(string $action, string $field): string
{
if (is_array($field)) {
throw new \Exception(__FUNCTION__ . "=> field가 array 입니다.\n" . var_export($field, true));
@ -40,7 +40,7 @@ class AccountModel extends CustomerModel
$rule = "required|trim|string";
break;
default:
$rule = parent::getFieldRule($action, $field);
$rule = parent::getFormFieldRule($action, $field);
break;
}
return $rule;

View File

@ -27,7 +27,7 @@ class ClientModel extends CustomerModel
{
parent::__construct();
}
public function getFieldRule(string $action, string $field): string
public function getFormFieldRule(string $action, string $field): string
{
if (is_array($field)) {
throw new \Exception(__FUNCTION__ . "=> field가 array 입니다.\n" . var_export($field, true));
@ -47,7 +47,7 @@ class ClientModel extends CustomerModel
$rule = "if_exist|numeric";
break;
default:
$rule = parent::getFieldRule($action, $field);
$rule = parent::getFormFieldRule($action, $field);
break;
}
return $rule;

View File

@ -23,7 +23,7 @@ class CouponModel extends CustomerModel
{
parent::__construct();
}
public function getFieldRule(string $action, string $field): string
public function getFormFieldRule(string $action, string $field): string
{
if (is_array($field)) {
throw new \Exception(__FUNCTION__ . "=> field가 array 입니다.\n" . var_export($field, true));
@ -38,7 +38,7 @@ class CouponModel extends CustomerModel
$rule = "required|trim|string";
break;
default:
$rule = parent::getFieldRule($action, $field);
$rule = parent::getFormFieldRule($action, $field);
break;
}
return $rule;

View File

@ -23,7 +23,7 @@ class PointModel extends CustomerModel
{
parent::__construct();
}
public function getFieldRule(string $action, string $field): string
public function getFormFieldRule(string $action, string $field): string
{
if (is_array($field)) {
throw new \Exception(__FUNCTION__ . "=> field가 array 입니다.\n" . var_export($field, true));
@ -38,7 +38,7 @@ class PointModel extends CustomerModel
$rule = "required|trim|string";
break;
default:
$rule = parent::getFieldRule($action, $field);
$rule = parent::getFormFieldRule($action, $field);
break;
}
return $rule;

View File

@ -29,7 +29,7 @@ class ServiceItemModel extends CustomerModel
{
parent::__construct();
}
public function getFieldRule(string $action, string $field): string
public function getFormFieldRule(string $action, string $field): string
{
if (is_array($field)) {
throw new \Exception(__FUNCTION__ . "=> field가 array 입니다.\n" . var_export($field, true));
@ -53,7 +53,7 @@ class ServiceItemModel extends CustomerModel
$rule = "if_exist|valid_date";
break;
default:
$rule = parent::getFieldRule($action, $field);
$rule = parent::getFormFieldRule($action, $field);
break;
}
return $rule;

View File

@ -28,7 +28,7 @@ class ServiceModel extends CustomerModel
{
parent::__construct();
}
public function getFieldRule(string $action, string $field): string
public function getFormFieldRule(string $action, string $field): string
{
if (is_array($field)) {
throw new \Exception(__FUNCTION__ . "=> field가 array 입니다.\n" . var_export($field, true));
@ -53,7 +53,7 @@ class ServiceModel extends CustomerModel
$rule = "if_exist|trim|string";
break;
default:
$rule = parent::getFieldRule($action, $field);
$rule = parent::getFormFieldRule($action, $field);
break;
}
return $rule;

View File

@ -22,7 +22,7 @@ class DomainModel extends EquipmentModel
{
parent::__construct();
}
public function getFieldRule(string $action, string $field): string
public function getFormFieldRule(string $action, string $field): string
{
if (is_array($field)) {
throw new \Exception(__FUNCTION__ . "=> field가 array 입니다.\n" . var_export($field, true));
@ -38,7 +38,7 @@ class DomainModel extends EquipmentModel
$rule = "required|trim|valid_domain";
break;
default:
$rule = parent::getFieldRule($action, $field);
$rule = parent::getFormFieldRule($action, $field);
break;
}
return $rule;

View File

@ -21,7 +21,7 @@ class CpuModel extends PartModel
{
parent::__construct();
}
final public function getFieldRule(string $action, string $field): string
final public function getFormFieldRule(string $action, string $field): string
{
if (is_array($field)) {
throw new \Exception(__FUNCTION__ . "=> field가 array 입니다.\n" . var_export($field, true));
@ -34,7 +34,7 @@ class CpuModel extends PartModel
$rule = "required|numeric";
break;
default:
$rule = parent::getFieldRule($action, $field);
$rule = parent::getFormFieldRule($action, $field);
break;
}
return $rule;

View File

@ -25,7 +25,7 @@ class DefenceModel extends PartModel
{
parent::__construct();
}
public function getFieldRule(string $action, string $field): string
public function getFormFieldRule(string $action, string $field): string
{
if (is_array($field)) {
throw new \Exception(__FUNCTION__ . "=> field가 array 입니다.\n" . var_export($field, true));
@ -42,7 +42,7 @@ class DefenceModel extends PartModel
$rule = "required|numeric";
break;
default:
$rule = parent::getFieldRule($action, $field);
$rule = parent::getFormFieldRule($action, $field);
break;
}
return $rule;

View File

@ -22,7 +22,7 @@ class IpModel extends PartModel
{
parent::__construct();
}
public function getFieldRule(string $action, string $field): string
public function getFormFieldRule(string $action, string $field): string
{
if (is_array($field)) {
throw new \Exception(__FUNCTION__ . "=> field가 array 입니다.\n" . var_export($field, true));
@ -38,7 +38,7 @@ class IpModel extends PartModel
$rule = "required|trim|valid_ip[both]"; //ipv4 , ipv6 , both(ipv4,ipv6)
break;
default:
$rule = parent::getFieldRule($action, $field);
$rule = parent::getFormFieldRule($action, $field);
break;
}
return $rule;

View File

@ -25,7 +25,7 @@ class LineModel extends PartModel
{
parent::__construct();
}
public function getFieldRule(string $action, string $field): string
public function getFormFieldRule(string $action, string $field): string
{
if (is_array($field)) {
throw new \Exception(__FUNCTION__ . "=> field가 array 입니다.\n" . var_export($field, true));
@ -43,7 +43,7 @@ class LineModel extends PartModel
$rule = "required|trim|string";
break;
default:
$rule = parent::getFieldRule($action, $field);
$rule = parent::getFormFieldRule($action, $field);
break;
}
return $rule;

View File

@ -22,7 +22,7 @@ class RamModel extends PartModel
{
parent::__construct();
}
final public function getFieldRule(string $action, string $field): string
final public function getFormFieldRule(string $action, string $field): string
{
if (is_array($field)) {
throw new \Exception(__FUNCTION__ . "=> field가 array 입니다.\n" . var_export($field, true));
@ -35,7 +35,7 @@ class RamModel extends PartModel
$rule = "required|numeric";
break;
default:
$rule = parent::getFieldRule($action, $field);
$rule = parent::getFormFieldRule($action, $field);
break;
}
return $rule;

View File

@ -23,7 +23,7 @@ class SoftwareModel extends PartModel
{
parent::__construct();
}
public function getFieldRule(string $action, string $field): string
public function getFormFieldRule(string $action, string $field): string
{
if (is_array($field)) {
throw new \Exception(__FUNCTION__ . "=> field가 array 입니다.\n" . var_export($field, true));
@ -37,7 +37,7 @@ class SoftwareModel extends PartModel
$rule = "required|numeric";
break;
default:
$rule = parent::getFieldRule($action, $field);
$rule = parent::getFormFieldRule($action, $field);
break;
}
return $rule;

View File

@ -21,7 +21,7 @@ class StorageModel extends PartModel
{
parent::__construct();
}
final public function getFieldRule(string $action, string $field): string
final public function getFormFieldRule(string $action, string $field): string
{
if (is_array($field)) {
throw new \Exception(__FUNCTION__ . "=> field가 array 입니다.\n" . var_export($field, true));
@ -34,7 +34,7 @@ class StorageModel extends PartModel
$rule = "required|numeric";
break;
default:
$rule = parent::getFieldRule($action, $field);
$rule = parent::getFormFieldRule($action, $field);
break;
}
return $rule;

View File

@ -22,7 +22,7 @@ class ServerModel extends EquipmentModel
{
parent::__construct();
}
public function getFieldRule(string $action, string $field): string
public function getFormFieldRule(string $action, string $field): string
{
if (is_array($field)) {
throw new \Exception(__FUNCTION__ . "=> field가 array 입니다.\n" . var_export($field, true));
@ -35,7 +35,7 @@ class ServerModel extends EquipmentModel
$rule = "required|numeric";
break;
default:
$rule = parent::getFieldRule($action, $field);
$rule = parent::getFormFieldRule($action, $field);
break;
}
return $rule;

View File

@ -25,7 +25,7 @@ class MyLogModel extends CommonModel
{
parent::__construct();
}
public function getFieldRule(string $action, string $field): string
public function getFormFieldRule(string $action, string $field): string
{
if (is_array($field)) {
throw new \Exception(__FUNCTION__ . "=> field가 array 입니다.\n" . var_export($field, true));
@ -35,7 +35,7 @@ class MyLogModel extends CommonModel
$rule = "if_exist|numeric";
break;
default:
$rule = parent::getFieldRule($action, $field);
$rule = parent::getFormFieldRule($action, $field);
break;
}
return $rule;

View File

@ -26,7 +26,7 @@ class UserModel extends CommonModel
{
parent::__construct();
}
public function getFieldRule(string $action, string $field): string
public function getFormFieldRule(string $action, string $field): string
{
if (is_array($field)) {
throw new \Exception(__FUNCTION__ . "=> field가 array 입니다.\n" . var_export($field, true));
@ -50,7 +50,7 @@ class UserModel extends CommonModel
$rule = "required|trim|string";
break;
default:
$rule = parent::getFieldRule($action, $field);
$rule = parent::getFormFieldRule($action, $field);
break;
}
return $rule;

View File

@ -28,15 +28,7 @@ class UserSNSModel extends CommonModel
{
parent::__construct();
}
public function getFilterFields(): array
{
return ['status'];
}
public function getBatchJobFields(): array
{
return ['status'];
}
public function getFieldRule(string $action, string $field): string
public function getFormFieldRule(string $action, string $field): string
{
switch ($field) {
case "id":
@ -55,7 +47,7 @@ class UserSNSModel extends CommonModel
$rule = "required|trim|string";
break;
default:
$rule = parent::getFieldRule($action, $field);
$rule = parent::getFormFieldRule($action, $field);
break;
}
return $rule;

View File

@ -17,8 +17,8 @@ abstract class AuthService extends CommonService
parent::__construct($request);
$this->addClassName('Auth');
}
abstract public function login(array $formDatas): UserEntity;
//Index,FieldForm관련
final public function getSession(): Session
{
if (!$this->_session) {
@ -26,7 +26,6 @@ abstract class AuthService extends CommonService
}
return $this->_session;
}
private function getAuthInfo(string $key = ""): array|string
{
$authInfo = $this->getSession()->get(SESSION_NAMES['AUTH']);
@ -35,45 +34,30 @@ abstract class AuthService extends CommonService
}
return $authInfo;
}
public function getFormFields(): array
{
return ['id', 'passwd'];
}
public function getFilterFields(): array
{
return [];
}
public function getBatchJobFields(): array
{
return [];
}
final public function getUIDByAuthInfo(): string
{
return $this->getAuthInfo('uid');
}
final public function getIDByAuthInfo(): string
{
return $this->getAuthInfo('id');
}
final public function getNameByAuthInfo(): string
{
return $this->getAuthInfo('name');
}
final public function getRoleByAuthInfo(): string
{
return $this->getAuthInfo('role');
}
final public function isLoggedIn(): bool
{
return $this->getSession()->has(SESSION_NAMES['ISLOGIN']);
}
final public function isAccessRole(array $roles): bool
{
$role = $this->getRoleByAuthInfo();
@ -83,12 +67,10 @@ abstract class AuthService extends CommonService
// 교집합이 없으면 false
return !empty(array_intersect(explode(DEFAULTS['DELIMITER_ROLE'], $role), $roles));
}
final public function pushCurrentUrl(string $url): void
{
$this->getSession()->set($this->url_stack_name, $url);
}
final public function popPreviousUrl(): string
{
$url = $this->getSession()->get($this->url_stack_name) ?? "";
@ -98,14 +80,12 @@ abstract class AuthService extends CommonService
}
return '/'; // 기본 URL
}
public function login(UserEntity $entity): UserEntity
final protected function login_process(UserEntity $entity): UserEntity
{
$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

@ -33,11 +33,26 @@ class GoogleService extends AuthService
return new UserEntity();
}
public function checkUser(string $access_code): UserEntity
public function getFormFields(): array
{
return [
"access_code",
];
}
public function getFilterFields(): array
{
return [];
}
public function getBatchJobFields(): array
{
return [];
}
public function login(array $formDatas): UserEntity
{
try {
// Google 서비스 설정
$this->this->getMySocket()->setToken($access_code);
$this->getMySocket()->setToken($formDatas['access_code']);
$sns_entity = $this->_mySocket->signup();
// local db 사용와의 연결 확인
$entity = $this->getEntity($sns_entity->getParent());

View File

@ -22,14 +22,29 @@ class LocalService extends AuthService
return new UserEntity();
}
public function checkUser(array $formDatas): UserEntity
public function getFormFields(): array
{
return [
"id",
"passwd",
];
}
public function getFilterFields(): array
{
return [];
}
public function getBatchJobFields(): array
{
return [];
}
public function login(array $formDatas): UserEntity
{
$entity = $this->getEntity(['id' => $formDatas['id'], 'status' => DEFAULTS['STATUS']]);
if (!password_verify($formDatas['passwd'], $entity->getPassword())) {
// log_message("error", "암호: {$formDatas['passwd']}, {$entity->passwd}");
throw new \Exception("암호가 맞지 않습니다.");
}
return $entity;
return $this->login_process($entity);
}
}

View File

@ -84,14 +84,14 @@ abstract class CommonService
return $entitys;
} //
//FieldForm관련용
public function getFieldRule(string $action, string $field): string
public function getFormFieldRule(string $action, string $field): string
{
if (is_array($field)) {
throw new \Exception(__FUNCTION__ . "=> field가 array 입니다.\n" . var_export($field, true));
}
switch ($field) {
default:
$rule = $this->getModel()->getFieldRule($action, $field);
$rule = $this->getModel()->getFormFieldRule($action, $field);
break;
}
return $rule;