107 lines
3.9 KiB
PHP
107 lines
3.9 KiB
PHP
<?php
|
|
|
|
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\AuthModel;
|
|
use App\Libraries\MySocket\Cloudflare\AccountSocket;
|
|
|
|
class AuthController extends CloudflareController
|
|
{
|
|
private $_model = null;
|
|
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
|
{
|
|
parent::initController($request, $response, $logger);
|
|
$this->class_name = "Auth";
|
|
$this->class_path .= $this->class_name;
|
|
$this->title = lang("{$this->class_path}.title");
|
|
helper($this->class_path);
|
|
}
|
|
final protected function getModel(): AuthModel
|
|
{
|
|
if ($this->_model === null) {
|
|
$this->_model = new AuthModel();
|
|
}
|
|
return $this->_model;
|
|
}
|
|
private function init(string $action): void
|
|
{
|
|
$this->fields = [$this->getModel()::TITLE, 'authkey', 'status'];
|
|
$this->field_rules = $this->getModel()->getFieldRules($action, $this->fields);
|
|
$this->filter_fields = ['status'];
|
|
$this->field_options = $this->getFormFieldOptions($this->filter_fields);
|
|
}
|
|
//생성
|
|
public function create_form(): RedirectResponse|string
|
|
{
|
|
$this->init('create');
|
|
return $this->create_form_procedure();
|
|
}
|
|
protected function create_process(): void
|
|
{
|
|
parent::create_process();
|
|
$entity = $this->getModel()->create($this->formDatas);
|
|
}
|
|
public function create(): RedirectResponse
|
|
{
|
|
$this->init(__FUNCTION__);
|
|
$this->create_validate($this->_fields);
|
|
$this->formDatas = $this->getFormDatas();
|
|
return $this->create_procedure();
|
|
}
|
|
//수정
|
|
public function modify_form(): RedirectResponse|string
|
|
{
|
|
$this->init('modify');
|
|
return $this->create_form_procedure();
|
|
}
|
|
protected function modify_process(): void
|
|
{
|
|
parent::modify_process();
|
|
$this->entity = $this->getModel()->modify($this->entity, $this->formDatas);
|
|
}
|
|
public function modify(string $uid): RedirectResponse
|
|
{
|
|
$this->entity = $this->getModel()->getEntityByPK($uid);
|
|
if ($this->entity === null) {
|
|
throw new \Exception("해당 정보를 찾을수 없습니다.");
|
|
}
|
|
$this->init(__FUNCTION__);;
|
|
$this->modify_validate($this->_fields);
|
|
$this->formDatas = $this->getFormDatas();
|
|
return $this->create_procedure();
|
|
}
|
|
// 리스트
|
|
public function index(): string
|
|
{
|
|
$this->fields = [$this->getModel()::TITLE, 'oldkey', 'status', 'updated_at', 'created_at'];
|
|
$this->field_rules = $this->getModel()->getFieldRules(__FUNCTION__, $this->fields);
|
|
$this->filter_fields = ['status'];
|
|
$this->batchjob_fields = ['status'];
|
|
$this->field_options = $this->getFormFieldOptions($this->filter_fields);
|
|
return $this->list_procedure();
|
|
}
|
|
|
|
public function reload(): RedirectResponse
|
|
{
|
|
try {
|
|
//Transaction Start
|
|
$this->getModel()->transStart();
|
|
foreach ($this->getModel()->getEntitys as $entity) {
|
|
$account_socket = new AccountSocket($entity);
|
|
$account_socket->reload();
|
|
}
|
|
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']) ?: "/");
|
|
}
|
|
}
|
|
}
|