Automation init...3
This commit is contained in:
parent
e97147a057
commit
ff17626b53
@ -17,23 +17,21 @@ $routes->addPlaceholder('uuid', '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}
|
||||
$routes->get('/', 'Home::index');
|
||||
$routes->group('crawler', ['namespace' => 'App\Controllers\Crawler'], function ($routes) {
|
||||
$routes->cli('yamap', 'YamapController::crawling');
|
||||
$routes->cli('yamap/(:segment)', 'YamapController::crawling::/$1');
|
||||
$routes->cli('yamap/debug', 'YamapController::crawling/debug');
|
||||
});
|
||||
|
||||
$routes->group('admin', ['namespace' => 'App\Controllers\Admin', 'filter' => 'authFilter:manager'], function ($routes) {
|
||||
$routes->get('/', 'Home::index');
|
||||
$routes->group('user', function ($routes) {
|
||||
$routes->get('', 'UserController::index');
|
||||
});
|
||||
});
|
||||
|
||||
$routes->group('mangboard', ['namespace' => 'App\Controllers\Mangboard'], function ($routes) {
|
||||
$routes->group('/user', function ($routes) {
|
||||
$routes->group('user', function ($routes) {
|
||||
$routes->get('/', 'UserController::index');
|
||||
});
|
||||
$routes->group('admin', ['namespace' => 'App\Controllers\Mangboard\Admin', 'filter' => 'authFilter:manager'], function ($routes) {
|
||||
$routes->group('/user', function ($routes) {
|
||||
$routes->get('/', 'UserController::index');
|
||||
$routes->get('point', 'UserController::form_point', ['filter' => 'authFilter:master']);
|
||||
$routes->post('point', 'UserController::point', ['filter' => 'authFilter:master']);
|
||||
$routes->post('level', 'UserController::level', ['filter' => 'authFilter:master']);
|
||||
});
|
||||
$routes->cli('point/(:alpha)/(:num)', 'UserController::point/$1/$2');
|
||||
$routes->cli('point/(:alpha)/(:num)/(:any)', 'UserController::point/$1/$2/$3');
|
||||
$routes->cli('level', 'UserController::level');
|
||||
});
|
||||
});
|
||||
|
||||
13
app/Controllers/Admin/Home.php
Normal file
13
app/Controllers/Admin/Home.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Admin;
|
||||
|
||||
use App\Controllers\CommonController;
|
||||
|
||||
class Home extends CommonController
|
||||
{
|
||||
public function index(): string
|
||||
{
|
||||
return view('welcome_message');
|
||||
}
|
||||
}
|
||||
29
app/Controllers/Admin/UserController.php
Normal file
29
app/Controllers/Admin/UserController.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Admin;
|
||||
|
||||
use CodeIgniter\HTTP\RequestInterface;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
use App\Traits\AuthTrait;
|
||||
use App\Controllers\CommonController;
|
||||
use App\Models\UserModel;
|
||||
|
||||
class UserController extends CommonController
|
||||
{
|
||||
use AuthTrait;
|
||||
private $_model = null;
|
||||
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
||||
{
|
||||
parent::initController($request, $response, $logger);
|
||||
$this->session = $this->login_check();
|
||||
}
|
||||
private function getModel(): UserModel
|
||||
{
|
||||
if ($this->_model === null) {
|
||||
$this->_model = new UserModel();
|
||||
}
|
||||
return $this->_model;
|
||||
}
|
||||
}
|
||||
@ -7,12 +7,13 @@ use App\Libraries\MyCrawler\YamapLibrary as MyCrawler;
|
||||
|
||||
class YamapController extends CommonController
|
||||
{
|
||||
public function crawling(...$params)
|
||||
public function crawling(string $option = ""): string
|
||||
{
|
||||
try {
|
||||
$isDebug = in_array("debug", $params);
|
||||
$crawler = new MyCrawler();
|
||||
$crawler->setDebug($isDebug);
|
||||
if ($option === "debug") {
|
||||
$crawler->setDebug(true);
|
||||
}
|
||||
|
||||
//1. 사이트 로그인 처리
|
||||
$user = $crawler->login();
|
||||
@ -40,10 +41,10 @@ class YamapController extends CommonController
|
||||
//4.망보드 일반게시판에 게시물 등록 처리
|
||||
$crawler->createBoard($item, $fileEntitys);
|
||||
log_message("notice", "Crawler->" . __FUNCTION__ . " 작업이 완료되었습니다.");
|
||||
return true;
|
||||
return "완료되었습니다.";
|
||||
} catch (\Exception $e) {
|
||||
log_message("error", $e->getMessage());
|
||||
return false;
|
||||
return $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,56 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Mangboard\Admin;
|
||||
|
||||
use CodeIgniter\HTTP\RequestInterface;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
use App\Traits\AuthTrait;
|
||||
use App\Controllers\CommonController;
|
||||
use App\Models\Mangboard\UserModel;
|
||||
|
||||
class UserController extends CommonController
|
||||
{
|
||||
use AuthTrait;
|
||||
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
||||
{
|
||||
parent::initController($request, $response, $logger);
|
||||
$this->session = $this->login_check();
|
||||
}
|
||||
|
||||
public function index(): string
|
||||
{
|
||||
return __METHOD__;
|
||||
}
|
||||
|
||||
public function point(): string
|
||||
{
|
||||
try {
|
||||
$id = $this->request->getPost("id");
|
||||
$point = intval($this->request->getPost("point"));
|
||||
$sign = $this->request->getPost("point") ?? "+";
|
||||
|
||||
$userModel = new UserModel();
|
||||
$userModel->setPoint($id, $point, $sign);
|
||||
return "완료되었습니다.";
|
||||
} catch (\Exception $e) {
|
||||
log_message("error", $e->getMessage());
|
||||
return $e->getMessage();
|
||||
}
|
||||
}
|
||||
public function level(...$params): bool
|
||||
{
|
||||
try {
|
||||
$isDebug = in_array("debug", $params);
|
||||
$userModel = new UserModel();
|
||||
$userModel->setDebug($isDebug);
|
||||
$userModel->setLevel();
|
||||
log_message("notice", "Mangboard->level 작업이 완료되었습니다.");
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
log_message("error", $e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,14 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Mangboard;
|
||||
namespace App\Controllers\Mangboard\Admin;
|
||||
|
||||
use CodeIgniter\HTTP\RequestInterface;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
use App\Controllers\CommonController;
|
||||
|
||||
use App\Models\Mangboard\UserModel;
|
||||
|
||||
class UserController extends CommonController
|
||||
{
|
||||
public function index()
|
||||
private $_model = null;
|
||||
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
||||
{
|
||||
return __METHOD__;
|
||||
parent::initController($request, $response, $logger);
|
||||
}
|
||||
|
||||
private function getModel(): UserModel
|
||||
{
|
||||
if ($this->_model === null) {
|
||||
$this->_model = new UserModel();
|
||||
}
|
||||
return $this->_model;
|
||||
}
|
||||
|
||||
public function point(string $id, string $point, string $sign = "+"): string
|
||||
{
|
||||
try {
|
||||
$entity = $this->getModel()->getEntityByID($id);
|
||||
if ($entity === null) {
|
||||
throw new \Exception("해당 ID{$id}는 사용자가 존재하지 않습니다.");
|
||||
}
|
||||
$this->getModel()->setPoint($id, intval($point), $sign);
|
||||
return "완료되었습니다.";
|
||||
} catch (\Exception $e) {
|
||||
log_message("error", $e->getMessage());
|
||||
return $e->getMessage();
|
||||
}
|
||||
}
|
||||
public function level(): string
|
||||
{
|
||||
try {
|
||||
$userModel = new UserModel();
|
||||
$userModel->setLevel();
|
||||
log_message("notice", "Mangboard->level 작업이 완료되었습니다.");
|
||||
return "완료되었습니다.";
|
||||
} catch (\Exception $e) {
|
||||
log_message("error", $e->getMessage());
|
||||
return $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -70,25 +70,27 @@ abstract class CommonModel extends Model
|
||||
$this->allowedFields = $fields;
|
||||
$this->setRules($this->allowedFields);
|
||||
}
|
||||
|
||||
final public function getRules(array $options): array //options=>except or only
|
||||
{
|
||||
return $this->getValidationRules($options);
|
||||
}
|
||||
final public function setRules(array $fields, $rules = []): void
|
||||
final public function setRules(array $fields, $rules = [], $isCreate = true): void
|
||||
{
|
||||
foreach ($fields as $field) {
|
||||
$rules = $this->getFieldRule($field, $rules);
|
||||
$rules = $this->getFieldRule($field, $rules, $isCreate);
|
||||
}
|
||||
$this->setValidationRules($rules);
|
||||
}
|
||||
|
||||
protected function getFieldRule(string $field, array $rules): array
|
||||
protected function getFieldRule(string $field, array $rules, $isCreate = true): array
|
||||
{
|
||||
switch ($field) {
|
||||
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}/]|is_unique[{$this->table}.{$field}]";
|
||||
$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] = $isCreate ? "|is_unique[{$this->table}.{$field}]" : "";
|
||||
} else {
|
||||
$rules[$field] = "required|numeric";
|
||||
};
|
||||
@ -97,10 +99,8 @@ abstract class CommonModel extends Model
|
||||
$rules[$field] = "required|string";
|
||||
break;
|
||||
case "passwd":
|
||||
$rules[$field] = "required|trim|string";
|
||||
break;
|
||||
case "confirmpassword":
|
||||
$rules["confirmpassword"] = "required|trim|string|matches[passwd]";
|
||||
$rules[$field] = $isCreate ? "required|trim|string" : "if_exist|trim|string";
|
||||
$rules["confirmpassword"] = $isCreate ? "required|trim|string|matches[passwd]" : "if_exist|trim|string|matches[passwd]";
|
||||
break;
|
||||
case "email":
|
||||
$rules[$field] = "if_exist|trim|valid_email";
|
||||
@ -182,6 +182,8 @@ abstract class CommonModel extends Model
|
||||
//PrimayKey Field를 allowedFields의 맨앞에 넣기 -> array_unshif
|
||||
array_unshift($this->allowedFields, $this->getPKField());
|
||||
$entity = $this->setEntityData($entity, $this->getPKField());
|
||||
//Create용 Rule다시적용
|
||||
$this->setRules($this->getFields(), [], true);
|
||||
}
|
||||
$entity = $this->save_process($entity);
|
||||
//primaryKey가 자동입력이면
|
||||
@ -192,6 +194,8 @@ abstract class CommonModel extends Model
|
||||
}
|
||||
final protected function modify_process($entity): mixed
|
||||
{
|
||||
//Create용 Rule다시적용
|
||||
$this->setRules($this->getFields(), [], false);
|
||||
return $this->save_process($entity);
|
||||
}
|
||||
}
|
||||
|
||||
@ -94,7 +94,7 @@ class BoardModel extends CommonModel
|
||||
{
|
||||
return 'title';
|
||||
}
|
||||
public function getFieldRule(string $field, array $rules): array
|
||||
public function getFieldRule(string $field, array $rules, $isCreate = true): array
|
||||
{
|
||||
switch ($field) {
|
||||
case 'gid':
|
||||
@ -118,7 +118,7 @@ class BoardModel extends CommonModel
|
||||
$rules[$field] = "if_exist|numeric";
|
||||
break;
|
||||
default:
|
||||
$rules = parent::getFieldRule($field, $rules);
|
||||
$rules = parent::getFieldRule($field, $rules, $isCreate);
|
||||
break;
|
||||
}
|
||||
return $rules;
|
||||
|
||||
@ -58,7 +58,7 @@ class FileModel extends CommonModel
|
||||
{
|
||||
return 'file_name';
|
||||
}
|
||||
public function getFieldRule(string $field, array $rules): array
|
||||
public function getFieldRule(string $field, array $rules, $isCreate = true): array
|
||||
{
|
||||
switch ($field) {
|
||||
case "board_pid":
|
||||
@ -81,7 +81,7 @@ class FileModel extends CommonModel
|
||||
$rules[$field] = "if_exist|valid_date";
|
||||
break;
|
||||
default:
|
||||
$rules = parent::getFieldRule($field, $rules);
|
||||
$rules = parent::getFieldRule($field, $rules, $isCreate);
|
||||
break;
|
||||
}
|
||||
return $rules;
|
||||
|
||||
@ -109,7 +109,7 @@ class UserModel extends CommonModel
|
||||
{
|
||||
return 'user_name';
|
||||
}
|
||||
public function getFieldRule(string $field, array $rules): array
|
||||
public function getFieldRule(string $field, array $rules, $isCreate = true): array
|
||||
{
|
||||
switch ($field) {
|
||||
case "user_id":
|
||||
@ -127,7 +127,7 @@ class UserModel extends CommonModel
|
||||
$rules[$field] = "if_exist|numeric";
|
||||
break;
|
||||
default:
|
||||
$rules = parent::getFieldRule($field, $rules);
|
||||
$rules = parent::getFieldRule($field, $rules, $isCreate);
|
||||
break;
|
||||
}
|
||||
return $rules;
|
||||
|
||||
@ -13,38 +13,31 @@ class SNSUserModel extends CommonModel
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$fields = ["id", "passwd", "name", "email", "level", "point", "status"];
|
||||
$fields = ["id", "passwd", "name", "email", "detail", "status"];
|
||||
parent::__construct($fields);
|
||||
}
|
||||
public function getTitleField(): string
|
||||
{
|
||||
return 'name';
|
||||
}
|
||||
public function getFieldRule(string $field, array $rules): array
|
||||
public function getFieldRule(string $field, array $rules, $isCreate = true): array
|
||||
{
|
||||
switch ($field) {
|
||||
case "id":
|
||||
case "passwd":
|
||||
case $this->getTitleField():
|
||||
$rules[$field] = "required|trim|string";
|
||||
$rules[$field] = "required|trim|min_length[4]|max_length[20]|is_unique[{$this->table}.{$field}]";
|
||||
break;
|
||||
case "status":
|
||||
$rules[$field] = "if_exist|trim|string";
|
||||
case $this->getTitleField():
|
||||
$rules[$field] = "required|trim|string";
|
||||
break;
|
||||
case "email":
|
||||
$rules[$field] = "if_exist|trim|valid_email";
|
||||
break;
|
||||
case "level":
|
||||
case "point":
|
||||
$rules[$field] = "if_exist|numeric";
|
||||
$rules[$field] = "if_exist|trim|valid_email";
|
||||
break;
|
||||
default:
|
||||
$rules = parent::getFieldRule($field, $rules);
|
||||
$rules = parent::getFieldRule($field, $rules, $isCreate);
|
||||
break;
|
||||
}
|
||||
return $rules;
|
||||
}
|
||||
|
||||
public function getEntityByPK(int $uid): null|SNSUSerEntity
|
||||
{
|
||||
$this->where($this->getPKField(), $uid);
|
||||
@ -52,18 +45,14 @@ class SNSUserModel extends CommonModel
|
||||
}
|
||||
public function getEntityByID(string $id): null|SNSUSerEntity
|
||||
{
|
||||
$this->where('user_id', $id);
|
||||
$this->where('id', $id);
|
||||
return $this->getEntity();
|
||||
}
|
||||
|
||||
//create용
|
||||
public function create(SNSUSerEntity $entity): SNSUSerEntity
|
||||
{
|
||||
$entity = $this->create_process($entity);
|
||||
//GID값이 PK랑 같은 값 전달 후 Entity 수정
|
||||
$entity->gid = $entity->getPK();
|
||||
$this->setFields(["gid"]);
|
||||
return $this->modify_process($entity);
|
||||
return $this->create_process($entity);
|
||||
}
|
||||
|
||||
//modify용
|
||||
|
||||
@ -13,33 +13,38 @@ class UserModel extends CommonModel
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$fields = ["id", "passwd", "name", "email", "level", "point", "status"];
|
||||
$fields = ["id", "passwd", "name", "email", "pohne", "mobild", "role", "status"];
|
||||
parent::__construct($fields);
|
||||
}
|
||||
public function getTitleField(): string
|
||||
{
|
||||
return 'name';
|
||||
}
|
||||
public function getFieldRule(string $field, array $rules): array
|
||||
public function getFieldRule(string $field, array $rules, $isCreate = true): array
|
||||
{
|
||||
switch ($field) {
|
||||
case "id":
|
||||
case "passwd":
|
||||
case $this->getTitleField():
|
||||
$rules[$field] = "required|trim|string";
|
||||
if ($isCreate) {
|
||||
$rules[$field] = "required|trim|min_length[4]|max_length[20]|is_unique[{$this->table}.{$field}]";
|
||||
} else {
|
||||
$rules[$field] = "required|trim|min_length[4]|max_length[20]";
|
||||
}
|
||||
break;
|
||||
case "status":
|
||||
$rules[$field] = "if_exist|trim|string";
|
||||
case $this->getTitleField():
|
||||
$rules[$field] = "required|trim|string";
|
||||
break;
|
||||
case "email":
|
||||
$rules[$field] = "if_exist|trim|valid_email";
|
||||
$rules[$field] = "if_exist|trim|valid_email";
|
||||
break;
|
||||
case "level":
|
||||
case "point":
|
||||
$rules[$field] = "if_exist|numeric";
|
||||
case "role":
|
||||
//아래 Rule은 입력시에는 되는데 수정시에는 않됨 이유를 ?
|
||||
// $rules[$field] = "required|in_list[master,director,cloudflare,manager,gold,silver,brone,vip,user]";
|
||||
//아래 Rule은 checkbox를 사용시에는 required만 우선 써야 수정시 validate문제없음
|
||||
$rules[$field] = "if_exist|trim|string";
|
||||
break;
|
||||
case "passwd":
|
||||
default:
|
||||
$rules = parent::getFieldRule($field, $rules);
|
||||
$rules = parent::getFieldRule($field, $rules, $isCreate);
|
||||
break;
|
||||
}
|
||||
return $rules;
|
||||
@ -52,18 +57,14 @@ class UserModel extends CommonModel
|
||||
}
|
||||
public function getEntityByID(string $id): null|UserEntity
|
||||
{
|
||||
$this->where('user_id', $id);
|
||||
$this->where('id', $id);
|
||||
return $this->getEntity();
|
||||
}
|
||||
|
||||
//create용
|
||||
public function create(UserEntity $entity): UserEntity
|
||||
{
|
||||
$entity = $this->create_process($entity);
|
||||
//GID값이 PK랑 같은 값 전달 후 Entity 수정
|
||||
$entity->gid = $entity->getPK();
|
||||
$this->setFields(["gid"]);
|
||||
return $this->modify_process($entity);
|
||||
return $this->create_process($entity);
|
||||
}
|
||||
|
||||
//modify용
|
||||
|
||||
Loading…
Reference in New Issue
Block a user