87 lines
2.8 KiB
PHP
87 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers\Cloudflare;
|
|
|
|
use App\Controllers\MVController;
|
|
use Psr\Log\LoggerInterface;
|
|
use CodeIgniter\HTTP\ResponseInterface;
|
|
use CodeIgniter\HTTP\RequestInterface;
|
|
use CodeIgniter\HTTP\RedirectResponse;
|
|
|
|
use App\Traits\AuthTrait;
|
|
use App\Models\Cloudflare\AccountModel;
|
|
use App\Libraries\MySocket\CloudflareSocket;
|
|
use App\Entities\Cloudflare\AccountEntity;
|
|
|
|
class AccountController extends MVController
|
|
{
|
|
use AuthTrait;
|
|
private $_model = null;
|
|
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
|
{
|
|
parent::initController($request, $response, $logger);
|
|
$this->session = $this->session_AuthTrait();
|
|
$this->class_name = 'Account';
|
|
helper($this->class_name);
|
|
}
|
|
|
|
final protected function getMySocket(): CloudflareSocket
|
|
{
|
|
if ($this->_mySocket === null) {
|
|
$this->_mySocket = new CloudflareSocket();
|
|
}
|
|
return $this->_mySocket;
|
|
}
|
|
|
|
final protected function getModel(): AccountModel
|
|
{
|
|
if ($this->_model === null) {
|
|
$this->_model = new AccountModel();
|
|
}
|
|
return $this->_model;
|
|
}
|
|
|
|
protected function create_init(): void
|
|
{
|
|
$this->fields = ['id', 'apikey'];
|
|
$this->filter_fields = ['status'];
|
|
$this->action = DB_ACTION["CREATE"];
|
|
$this->getModel()->setAction($this->action);
|
|
}
|
|
public function create_form(): RedirectResponse|string
|
|
{
|
|
return $this->create_form_process();
|
|
}
|
|
|
|
//Result 형태
|
|
// [
|
|
// {"id":"078e88a7735965b661715af13031ecb0",
|
|
// "name":"Cloudwin002@idcjp.jp's Auth",
|
|
// "type":"standard",
|
|
// "settings":{
|
|
// "enforce_twofactor":false,
|
|
// "api_access_enabled":null,
|
|
// "access_approval_expiry":null,
|
|
// "use_account_custom_ns_by_default":false
|
|
// },
|
|
// "legacy_flags":{"enterprise_zone_quota":{"maximum":0,"current":0,"available":0}},
|
|
// "created_on":"2017-06-26T05:44:49.470184Z"}
|
|
// ]
|
|
protected function create_process_submit(): AccountEntity
|
|
{
|
|
$this->getMySocket()->setAPIKey($this->formDatas['apikey']);
|
|
$result = $this->getMySocket()->getAccount()->addAccount($this->formDatas['id']);
|
|
$this->formDatas[$this->getModel()->PK()] = $result->id;
|
|
$this->formDatas[$this->getModel()->getTitleField()] = $result->name;
|
|
$this->formDatas['type'] = $result->type;
|
|
$this->formDatas['status'] = 'use';
|
|
$this->formDatas['updated_at'] = $result->created_on;
|
|
$this->formDatas['created_at'] = $result->created_on;
|
|
return $this->getModel()->create($this->formDatas);
|
|
}
|
|
public function create(): RedirectResponse
|
|
{
|
|
return parent::create_process();
|
|
}
|
|
}
|