cfmgrv4 init...1

This commit is contained in:
최준흠 2024-10-02 20:39:02 +09:00
parent 66d34a9101
commit 86531c9ecf
17 changed files with 162 additions and 175 deletions

View File

@ -24,7 +24,6 @@ $routes->group('admin', ['namespace' => 'App\Controllers\Admin'], function ($rou
$routes->get('delete/(:num)', 'UserController::delete/$1');
$routes->get('toggle/(:num)/(:alpha)', 'UserController::toggle/$1/$2');
$routes->post('batchjob', 'UserController::batcjob');
$routes->get('roles/(:num)', 'UserController::roles/$1');
$routes->get('download/(:alpha)', 'UserController::download/$1');
$routes->get('download/(:alpha)/(:any)', 'UserController::download/$1/$2');
});

View File

@ -63,25 +63,16 @@ class AccountController extends CloudflareController
$this->batchjob_fields = ['typep', 'status'];
return $this->list_procedure();
}
public function reload(): RedirectResponse
//Zone Reload By Account
protected function reload_process(): void
{
//Transaction Start
$this->getModel()->transStart();
try {
foreach ($this->getModel()->getEntitys as $entity) {
$zone_socket = new ZoneSocket($entity);
$zone_socket->reload();
}
log_message("notice", __FUNCTION__ . "=> 작업을 완료하였습니다.");
$this->session->setFlashdata(SESSION_NAMES['RETURN_MSG'], __FUNCTION__ . " => 작업을 완료하였습니다.\n");
$this->getModel()->transCommit();
return redirect()->to($this->session->getFlashdata(SESSION_NAMES['RETURN_URL']) ?: "/");
} catch (\Exception $e) {
//Transaction Rollback
$this->getModel()->transRollback();
log_message("error", $e->getMessage());
$this->session->setFlashdata(SESSION_NAMES['RETURN_MSG'], __FUNCTION__ . " 실패하였습니다.\n" . $e->getMessage());
return redirect()->to($this->session->getFlashdata(SESSION_NAMES['RETURN_URL']) ?: "/");
foreach ($this->getModel()->getEntitys as $entity) {
$zone_socket = new ZoneSocket($entity);
$zone_socket->reload();
}
}
public function reload(): RedirectResponse
{
return $this->reload_procedure();
}
}

View File

@ -44,8 +44,6 @@ class AuthController extends CloudflareController
public function create(): RedirectResponse
{
$this->init(__FUNCTION__);
$this->create_validate($this->action, $this->fields);
$this->formDatas = $this->getFormDatas();
return $this->create_procedure();
}
//수정
@ -57,8 +55,6 @@ class AuthController extends CloudflareController
public function modify(string $uid): RedirectResponse
{
$this->init(__FUNCTION__);
$this->modify_validate($this->action, $this->fields);
$this->formDatas = $this->getFormDatas();
return $this->modify_procedure($uid);
}
//일괄처리작업
@ -67,8 +63,6 @@ class AuthController extends CloudflareController
$this->action = __FUNCTION__;
$this->fields = ['status'];
$this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields);
$this->modify_validate($this->action, $this->fields);
$this->formDatas = $this->getFormDatas();
return $this->batcjob_procedure();
}
// 리스트
@ -82,26 +76,16 @@ class AuthController extends CloudflareController
$this->batchjob_fields = ['status'];
return $this->list_procedure();
}
public function reload(): RedirectResponse
//Account Reload by Auth
protected function reload_process(): void
{
//Transaction Start
$this->getModel()->transStart();
try {
foreach ($this->getModel()->getEntitys as $entity) {
$account_socket = new AccountSocket($entity);
$account_socket->reload();
}
log_message("notice", __FUNCTION__ . "=> 작업을 완료하였습니다.");
$this->session->setFlashdata(SESSION_NAMES['RETURN_MSG'], __FUNCTION__ . " => 작업을 완료하였습니다.\n");
$this->getModel()->transCommit();
return redirect()->to($this->session->getFlashdata(SESSION_NAMES['RETURN_URL']) ?: "/");
} catch (\Exception $e) {
//Transaction Rollback
$this->getModel()->transRollback();
log_message("error", $e->getMessage());
$this->session->setFlashdata(SESSION_NAMES['RETURN_MSG'], __FUNCTION__ . " 실패하였습니다.\n" . $e->getMessage());
return redirect()->to($this->session->getFlashdata(SESSION_NAMES['RETURN_URL']) ?: "/");
foreach ($this->getModel()->getEntitys as $entity) {
$account_socket = new AccountSocket($entity);
$account_socket->reload();
}
}
public function reload(): RedirectResponse
{
return $this->reload_procedure();
}
}

View File

@ -5,6 +5,7 @@ namespace App\Controllers\Admin\Cloudflare;
use Psr\Log\LoggerInterface;
use CodeIgniter\HTTP\ResponseInterface;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\RedirectResponse;
use App\Models\Cloudflare\ZoneModel;
use App\Models\Cloudflare\RecordModel;
use App\Models\Cloudflare\AuthModel;
@ -51,4 +52,24 @@ abstract class CloudflareController extends AdminController
}
return $this->_recordModel;
}
protected function reload_process(): void {}
final protected function reload_procedure(): RedirectResponse
{
//Transaction Start
$this->getModel()->transStart();
try {
$this->reload_process();
log_message("notice", __FUNCTION__ . "=> 작업을 완료하였습니다.");
$this->session->setFlashdata(SESSION_NAMES['RETURN_MSG'], __FUNCTION__ . " => 작업을 완료하였습니다.\n");
$this->getModel()->transCommit();
return redirect()->to($this->session->getFlashdata(SESSION_NAMES['RETURN_URL']) ?: "/");
} catch (\Exception $e) {
//Transaction Rollback
$this->getModel()->transRollback();
log_message("error", $e->getMessage());
$this->session->setFlashdata(SESSION_NAMES['RETURN_MSG'], __FUNCTION__ . " 실패하였습니다.\n" . $e->getMessage());
return redirect()->to($this->session->getFlashdata(SESSION_NAMES['RETURN_URL']) ?: "/");
}
}
}

View File

@ -201,26 +201,16 @@ class ZoneController extends CloudflareController
$this->batchjob_fields = ['development_mode', 'ipv6', 'security_level'];
return $this->list_procedure();
}
//reload
public function reload(): RedirectResponse
//reload Record By Zone
protected function reload_process(): void
{
//Transaction Start
$this->getModel()->transStart();
try {
foreach ($this->getModel()->getEntitys as $entity) {
$record_socket = new RecordSocket($entity);
$record_socket->reload();
}
log_message("notice", __FUNCTION__ . "=> 작업을 완료하였습니다.");
$this->session->setFlashdata(SESSION_NAMES['RETURN_MSG'], __FUNCTION__ . " => 작업을 완료하였습니다.\n");
$this->getModel()->transCommit();
return redirect()->to($this->session->getFlashdata(SESSION_NAMES['RETURN_URL']) ?: "/");
} catch (\Exception $e) {
//Transaction Rollback
$this->getModel()->transRollback();
log_message("error", $e->getMessage());
$this->session->setFlashdata(SESSION_NAMES['RETURN_MSG'], __FUNCTION__ . " 실패하였습니다.\n" . $e->getMessage());
return redirect()->to($this->session->getFlashdata(SESSION_NAMES['RETURN_URL']) ?: "/");
foreach ($this->getModel()->getEntitys as $entity) {
$record_socket = new RecordSocket($entity);
$record_socket->reload();
}
}
public function reload(): RedirectResponse
{
return $this->reload_procedure();
}
}

View File

@ -95,8 +95,6 @@ class MapurlController extends AdminController
public function create(): RedirectResponse
{
$this->init(__FUNCTION__);
$this->create_validate($this->action, $this->fields);
$this->formDatas = $this->getFormDatas();
return $this->create_procedure();
}
//수정
@ -114,8 +112,6 @@ class MapurlController extends AdminController
public function modify(string $uid): RedirectResponse
{
$this->init(__FUNCTION__);
$this->modify_validate($this->action, $this->fields);
$this->formDatas = $this->getFormDatas();
return $this->modify_procedure($uid);
}
//일괄처리작업
@ -124,8 +120,6 @@ class MapurlController extends AdminController
$this->action = __FUNCTION__;
$this->fields = ['status'];
$this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields);
$this->modify_validate($this->action, $this->fields);
$this->formDatas = $this->getFormDatas();
return $this->batcjob_procedure();
}
//삭제

View File

@ -41,18 +41,11 @@ class UserController extends AdminController
{
switch ($field) {
case 'role':
$roles = $this->request->getVar($field . "[]");
if (!count($roles)) {
throw new \Exception("권한이 지정되지 않았습니다.");
}
$formDatas[$field] = implode(DEFAULTS["DELIMITER_ROLE"],);
break;
case 'roles[]':
$roles = $this->request->getVar($field);
if (!count($roles)) {
throw new \Exception("권한이 지정되지 않았습니다.");
}
$formDatas['role'] = implode(DEFAULTS["DELIMITER_ROLE"],);
$formDatas[$field] = implode(DEFAULTS["DELIMITER_ROLE"],);
break;
default:
$formDatas = parent::getFormData($field, $formDatas);
@ -69,6 +62,28 @@ class UserController extends AdminController
$this->field_options = $this->getFormFieldOptions($this->filter_fields);
}
//생성
protected function create_validate(string $action, array $fields): void
{
//변경할 값 확인 : Upload된 파일 검증시 $this->request->getVar()보다 먼처 체크필요
$this->validation = service('validation');
foreach ($fields as $field) {
switch ($field) {
case 'role':
//아래 Rule Array는 필드명.* checkbox를 사용
$this->validation->setRule($field . "*", $field, $this->getModel()->getRule($action, $field));
break;
default:
$this->validation->setRule($field, $field, $this->getModel()->getRule($action, $field));
break;
}
}
if (!$this->validation->withRequest($this->request)->run()) {
throw new \Exception("{$this->class_name} 작업 데이터 검증 오류발생\n" . implode(
"\n",
$this->validation->getErrors()
));
}
}
public function create_form(): RedirectResponse|string
{
$this->init('create');
@ -77,11 +92,31 @@ class UserController extends AdminController
public function create(): RedirectResponse
{
$this->init(__FUNCTION__);
$this->create_validate($this->action, $this->fields);
$this->formDatas = $this->getFormDatas();
return $this->create_procedure();
}
//수정
protected function modify_validate(string $action, array $fields): void
{
//변경할 값 확인 : Upload된 파일 검증시 $this->request->getVar()보다 먼처 체크필요
$this->validation = service('validation');
foreach ($fields as $field) {
switch ($field) {
case 'role':
//아래 Rule Array는 필드명.* checkbox를 사용
$this->validation->setRule($field . "*", $field, $this->getModel()->getRule($action, $field));
break;
default:
$this->validation->setRule($field, $field, $this->getModel()->getRule($action, $field));
break;
}
}
if (!$this->validation->withRequest($this->request)->run()) {
throw new \Exception("{$this->class_name} 작업 데이터 검증 오류발생\n" . implode(
"\n",
$this->validation->getErrors()
));
}
}
public function modify_form(string $uid): RedirectResponse|string
{
$this->init('modify');
@ -90,8 +125,6 @@ class UserController extends AdminController
public function modify(string $uid): RedirectResponse
{
$this->init(__FUNCTION__);
$this->modify_validate($this->action, $this->fields);
$this->formDatas = $this->getFormDatas();
return $this->modify_procedure($uid);
}
//일괄작업
@ -100,19 +133,8 @@ class UserController extends AdminController
$this->action = __FUNCTION__;
$this->fields = ['status'];
$this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields);
$this->modify_validate($this->action, $this->fields);
$this->formDatas = $this->getFormDatas();
return $this->batcjob_procedure();
}
//Role변경작업
public function roles(string $uid): RedirectResponse
{
$this->action = __FUNCTION__;
$this->fields = ["roles[]"];
$this->modify_validate($this->action, $this->fields);
$this->formDatas = $this->getFormDatas();
return $this->modify_procedure($uid);
}
// 리스트
public function index(): string
{

View File

@ -63,7 +63,9 @@ abstract class MVController extends CommonController
{
//변경할 값 확인 : Upload된 파일 검증시 $this->request->getVar()보다 먼처 체크필요
$this->validation = service('validation');
$this->validation->setRules($this->getModel()->getFieldRules($action, $fields));
foreach ($fields as $field) {
$this->validation->setRule($field, $this->getModel()->getFieldRule($action, $field));
}
if (!$this->validation->withRequest($this->request)->run()) {
throw new \Exception("{$this->class_name} 작업 데이터 검증 오류발생\n" . implode(
"\n",
@ -90,6 +92,8 @@ abstract class MVController extends CommonController
}
protected function create_process(): void
{
$this->create_validate($this->action, $this->fields);
$this->formDatas = $this->getFormDatas();
$this->entity = $this->getModel()->create(formDatas: $this->formDatas);
}
final protected function create_procedure(): RedirectResponse
@ -149,6 +153,8 @@ abstract class MVController extends CommonController
}
protected function modify_process(string $uid): void
{
$this->modify_validate($this->action, $this->fields);
$this->formDatas = $this->getFormDatas();
$this->entity = $this->getModel()->getEntityByPK(intval($uid));
if ($this->entity === null) {
throw new \Exception("{$uid} 정보를 찾을수 없습니다.");
@ -179,8 +185,6 @@ abstract class MVController extends CommonController
{
$this->action = __FUNCTION__;
$this->field = [$field];
$this->modify_validate($this->action, $this->fields);
$this->formDatas = $this->getFormDatas();
return $this->modify_procedure($uid);
}
//일괄처리작업

View File

@ -76,14 +76,6 @@ function getFieldView_UserHelper(string $field, UserEntity $entity, array $viewD
);
break;
case 'role':
foreach ($viewDatas['field_options'][$field] as $key => $label) {
$roles = explode(DEFAULTS["DELIMITER_ROLE"], $value);
$checkboxs[] = form_checkbox("roles[]", $key, in_array($key, $roles)) . $label;
}
$checkbox_form = implode(" ", $checkboxs);
$checkbox_form .= form_submit("", '권한처리', ["formaction" => current_url() . "/roles/{$entity->getPK()}", "class" => "btn btn-outline-primary"]);
$checkbox_form .= form_close();
$value = $checkbox_form;
break;
case 'updated_at':
case 'created_at':

View File

@ -26,23 +26,23 @@ class AccountModel extends CommonModel
{
return self::TITLE;
}
public function getFieldRule(string $action, string $field, array $rules): array
public function getFieldRule(string $action, string $field): string
{
switch ($field) {
case self::PARENT:
$rules[$field] = "required|numeric";
$rule = "required|numeric";
break;
case self::TITLE:
$rules[$field] = "required|trim|string";
$rule = "required|trim|string";
break;
case "type":
$rules[$field] = "if_exist|in_list[standard,enterprise]";
$rule = "if_exist|in_list[standard,enterprise]";
break;
default:
$rules = parent::getFieldRule($action, $field, $rules);
$rule = parent::getFieldRule($action, $field);
break;
}
return $rules;
return $rule;
}
public function getFormFieldOption(string $field, array $options = []): array
{

View File

@ -24,25 +24,25 @@ class AuthModel extends CommonModel
{
return self::TITLE;
}
public function getFieldRule(string $action, string $field, array $rules): array
public function getFieldRule(string $action, string $field): string
{
switch ($field) {
case self::TITLE:
$rules[$field] = "required|trim|valid_email";
$rules[$field] .= $action == "create" ? "|is_unique[{$this->table}.{$field}]" : "";
$rule = "required|trim|valid_email";
$rule .= $action == "create" ? "|is_unique[{$this->table}.{$field}]" : "";
break;
case "authkey":
$rules[$field] = "required|trim|string";
$rules[$field] .= $action == "create" ? "|is_unique[{$this->table}.{$field}]" : "";
$rule = "required|trim|string";
$rule .= $action == "create" ? "|is_unique[{$this->table}.{$field}]" : "";
break;
case "oldkey":
$rules[$field] = "if_exist|trim|string";
$rule = "if_exist|trim|string";
break;
default:
$rules = parent::getFieldRule($action, $field, $rules);
$rule = parent::getFieldRule($action, $field);
break;
}
return $rules;
return $rule;
}
public function getFormFieldOption(string $field, array $options = []): array
{

View File

@ -27,33 +27,33 @@ class RecordModel extends CommonModel
{
return self::TITLE;
}
public function getFieldRule(string $action, string $field, array $rules): array
public function getFieldRule(string $action, string $field): string
{
switch ($field) {
case self::PARENT:
$rules[$field] = "required|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]";
$rule = "required|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]";
break;
case self::TITLE:
case "content":
$rules[$field] = "required|trim|string";
$rule = "required|trim|string";
break;
case "type":
$rules[$field] = "required|in_list[A,AAAA,CNAME,NS,MX,PTR,SPF,TXT,SRV,INFO]";
$rule = "required|in_list[A,AAAA,CNAME,NS,MX,PTR,SPF,TXT,SRV,INFO]";
break;
case "ttl":
$rules[$field] = "if_exist|numeric";
$rule = "if_exist|numeric";
break;
case "proxiable":
case "proxied":
case "fixed":
case "locked":
$rules[$field] = "if_exist|in_list[on,off]";
$rule = "if_exist|in_list[on,off]";
break;
default:
$rules = parent::getFieldRule($action, $field, $rules);
$rule = parent::getFieldRule($action, $field);
break;
}
return $rules;
return $rule;
}
public function getFormFieldInputOption(string $field, array $options = []): array
{

View File

@ -26,29 +26,29 @@ class ZoneModel extends CommonModel
{
return self::TITLE;
}
public function getFieldRule(string $action, string $field, array $rules): array
public function getFieldRule(string $action, string $field): string
{
switch ($field) {
case self::PARENT:
$rules[$field] = "required|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]";
$rule = "required|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]";
break;
case self::TITLE:
case "plan":
$rules[$field] = "required|trim|string";
$rule = "required|trim|string";
break;
case "name_servers":
case "security_level":
$rules[$field] = "if_exist|trim|string";
$rule = "if_exist|trim|string";
break;
case "development_mode":
case "ipv6":
$rules[$field] = "if_exist|in_list[on,off]";
$rule = "if_exist|in_list[on,off]";
break;
default:
$rules = parent::getFieldRule($action, $field, $rules);
$rule = parent::getFieldRule($action, $field);
break;
}
return $rules;
return $rule;
}
public function getFormFieldOption(string $field, array $options = []): array
{

View File

@ -62,7 +62,7 @@ abstract class CommonModel extends Model
// {
// return array_diff($this->allowedFields, $except_fields); //제외한 fields
// }
public function getFieldRule(string $action, string $field, array $rules): array
public function getFieldRule(string $action, string $field): string
{
if (is_array($field)) {
throw new \Exception(__FUNCTION__ . "=> field가 array 입니다.\n" . var_export($field, true));
@ -71,48 +71,45 @@ abstract class CommonModel extends Model
case $this->getPKField():
//수동입력인경우
if (!$this->useAutoIncrement) {
$rules[$field] = "required|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]";
$rules[$field] .= $action == "create" ? "|is_unique[{$this->table}.{$field}]" : "";
$rule = "required|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]";
$rule .= $action == "create" ? "|is_unique[{$this->table}.{$field}]" : "";
} else {
$rules[$field] = "required|numeric";
$rule = "required|numeric";
};
break;
case $this->getTitleField():
$rules[$field] = "required|string";
$rule = "required|string";
break;
case "passwd":
$rules[$field] = $action == "create" ? "required" : "if_exist" . "|trim|string";
$rule = $action == "create" ? "required" : "if_exist" . "|trim|string";
break;
case "confirmpassword":
$rules["confirmpassword"] = $action == "create" ? "required" : "if_exist" . "|trim|string|matches[passwd]";
break;
case "email":
$rules[$field] = "if_exist|trim|valid_email";
$rule = "if_exist|trim|valid_email";
break;
case 'image':
$rules[$field] = "is_image[{$field}]|mime_in[{$field},image/jpg,image/jpeg,image/gif,image/png,image/webp]|max_size[{$field},300]|max_dims[{$field},2048,768]";
$rule = "is_image[{$field}]|mime_in[{$field},image/jpg,image/jpeg,image/gif,image/png,image/webp]|max_size[{$field},300]|max_dims[{$field},2048,768]";
break;
case "status":
$rules[$field] = "if_exist|in_list[use,unuse]";
$rule = "if_exist|in_list[use,unuse]";
break;
case "updated_at":
case "created_at":
case "deleted_at":
$rules[$field] = "if_exist|valid_date";
$rule = "if_exist|valid_date";
break;
default:
$rules[$field] = "if_exist|string";
$rule = "if_exist|string";
break;
}
return $rules;
return $rule;
}
final public function getFieldRules(string $action, array $fields, array $rules = []): array
final public function getFieldRules(string $action, array $fields, $rules = []): array
{
foreach ($fields as $field) {
if (is_array($field)) {
throw new \Exception(__FUNCTION__ . "에서 field array 입니다.\n" . var_export($field, true));
}
$rules = $this->getFieldRule($action, $field, $rules);
$rules[$field] = $this->getFieldRule($action, $field);
}
return $rules;
}

View File

@ -26,24 +26,24 @@ class MapurlModel extends CommonModel
{
return self::TITLE;
}
public function getFieldRule(string $action, string $field, array $rules): array
public function getFieldRule(string $action, string $field): string
{
if (is_array($field)) {
throw new \Exception(__FUNCTION__ . "=> field가 array 입니다.\n" . var_export($field, true));
}
switch ($field) {
case "oldurl":
$rules[$field] = "required|valid_url_strict";
$rules[$field] .= $action == "create" ? "|is_unique[{$this->table}.{$field}]" : "";
$rule = "required|valid_url_strict";
$rule .= $action == "create" ? "|is_unique[{$this->table}.{$field}]" : "";
break;
case "newurl":
$rules[$field] = "required|valid_url_strict";
$rule = "required|valid_url_strict";
break;
default:
$rules = parent::getFieldRule($action, $field, $rules);
$rule = parent::getFieldRule($action, $field);
break;
}
return $rules;
return $rule;
}
public function getEntityByPK(int $uid): null|MapurlEntity
{

View File

@ -28,23 +28,23 @@ class SNSUserModel extends CommonModel
{
return self::TITLE;
}
public function getFieldRule(string $action, string $field, array $rules): array
public function getFieldRule(string $action, string $field): string
{
switch ($field) {
case "id":
$rules[$field] = "required|trim|min_length[4]|max_length[20]|is_unique[{$this->table}.{$field}]";
$rule = "required|trim|min_length[4]|max_length[20]|is_unique[{$this->table}.{$field}]";
break;
case $this->getTitleField():
$rules[$field] = "required|trim|string";
$rule = "required|trim|string";
break;
case "email":
$rules[$field] = "if_exist|trim|valid_email";
$rule = "if_exist|trim|valid_email";
break;
default:
$rules = parent::getFieldRule($action, $field, $rules);
$rule = parent::getFieldRule($action, $field);
break;
}
return $rules;
return $rule;
}
public function getEntityByPK(int $uid): null|SNSUSerEntity
{

View File

@ -30,35 +30,28 @@ class UserModel extends CommonModel
{
return self::TITLE;
}
public function getFieldRule(string $action, string $field, array $rules): array
public function getFieldRule(string $action, string $field): string
{
if (is_array($field)) {
throw new \Exception(__FUNCTION__ . "=> field가 array 입니다.\n" . var_export($field, true));
}
switch ($field) {
case "id":
$rules[$field] = "required|trim|min_length[4]|max_length[20]|is_unique[{$this->table}.{$field}]";
$rules[$field] .= $action == "create" ? "|is_unique[{$this->table}.{$field}]" : "";
$rule = "required|trim|min_length[4]|max_length[20]|is_unique[{$this->table}.{$field}]";
$rule .= $action == "create" ? "|is_unique[{$this->table}.{$field}]" : "";
break;
case "email":
$rules[$field] = "if_exist|trim|valid_email";
$rule = "if_exist|trim|valid_email";
break;
case "role":
//아래 Rule은 입력시에는 되는데 수정시에는 않됨 이유를 ?
// $rules[$field] = "required|in_list[master,director,cloudflare,manager,gold,silver,brone,vip,user]";
//아래 Rule은 checkbox를 사용시에는 required만 우선 써야 수정시 validate문제없음
$rules[$field] = "required|trim|string";
break;
case "role[]":
case "roles[]":
$rules[$field] = "if_exist|trim|string";
$rule = "required|trim|string";
break;
case "passwd":
default:
$rules = parent::getFieldRule($action, $field, $rules);
$rule = parent::getFieldRule($action, $field);
break;
}
return $rules;
return $rule;
}
public function getEntityByPK(int $uid): null|UserEntity