+ Add create method in gitfox module.
This commit is contained in:
@@ -28,7 +28,7 @@ class gitfox extends control
|
||||
|
||||
if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
|
||||
$this->loadModel('action');
|
||||
$this->action->create('gitlab', $gitfoxID, 'created');
|
||||
$this->action->create('gitfox', $gitfoxID, 'created');
|
||||
return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => $this->createLink('space', 'browse')));
|
||||
}
|
||||
|
||||
@@ -36,5 +36,28 @@ class gitfox extends control
|
||||
|
||||
$this->display();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查post的token是否有管理员权限。
|
||||
* Check post token has admin permissions.
|
||||
*
|
||||
* @param object $gitfox
|
||||
* @param int $gitfoxID
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function checkToken(object $gitfox, int $gitfoxID = 0)
|
||||
{
|
||||
$this->dao->update('gitfox')->data($gitfox)->batchCheck($gitfoxID ? $this->config->gitfox->edit->requiredFields : $this->config->gitfox->create->requiredFields, 'notempty');
|
||||
if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
|
||||
|
||||
if(strpos($gitfox->url, 'http') !== 0) return $this->send(array('result' => 'fail', 'message' => array('url' => array(sprintf($this->lang->gitfox->hostError, $this->config->gitfox->minCompatibleVersion)))));
|
||||
if(!$gitfox->token) return $this->send(array('result' => 'fail', 'message' => array('token' => array($this->lang->gitfox->tokenError))));
|
||||
|
||||
$user = $this->gitfox->checkTokenAccess($gitfox->url, $gitfox->token);
|
||||
|
||||
if(is_bool($user)) return $this->send(array('result' => 'fail', 'message' => array('url' => array(sprintf($this->lang->gitfox->hostError, $this->config->gitfox->minCompatibleVersion)))));
|
||||
if(!isset($user->id)) return $this->send(array('result' => 'fail', 'message' => array('token' => array($this->lang->gitfox->tokenError))));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+22
-1
@@ -9,7 +9,28 @@ declare(strict_types=1);
|
||||
* @package gitfox
|
||||
* @link https://www.zentao.net
|
||||
*/
|
||||
class xxxModel extends model
|
||||
class gitfoxModel extends model
|
||||
{
|
||||
/**
|
||||
* 检查token。
|
||||
* Check token access.
|
||||
*
|
||||
* @param string $url
|
||||
* @param string $token
|
||||
* @access public
|
||||
* @return object|array|null|false
|
||||
*/
|
||||
public function checkTokenAccess(string $url = '', string $token = ''): object|array|null|false
|
||||
{
|
||||
$apiRoot = rtrim($url, '/') . '/api/v4%s' . "?private_token={$token}";
|
||||
$url = sprintf($apiRoot, "/users") . "&per_page=5&active=true";
|
||||
$response = commonModel::http($url);
|
||||
$users = json_decode($response);
|
||||
if(empty($users)) return false;
|
||||
if(isset($users->message) or isset($users->error)) return null;
|
||||
|
||||
$apiRoot .= '&sudo=' . $users[0]->id;
|
||||
return $this->apiGet($apiRoot, '/user');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user