php 7.4 dev branch
This commit is contained in:
@@ -3,10 +3,11 @@
|
||||
namespace Api\ApiKey;
|
||||
|
||||
use \Api\Request;
|
||||
|
||||
class Create extends Request {
|
||||
|
||||
public function __construct($user, $externCall = false) {
|
||||
parent::__construct($user, $externCall, array());
|
||||
public function __construct($user, $externalCall = false) {
|
||||
parent::__construct($user, $externalCall, array());
|
||||
$this->apiKeyAllowed = false;
|
||||
$this->loginRequired = true;
|
||||
}
|
||||
@@ -39,6 +40,4 @@ class Create extends Request {
|
||||
}
|
||||
return $this->success;
|
||||
}
|
||||
};
|
||||
|
||||
?>
|
||||
}
|
||||
@@ -3,12 +3,13 @@
|
||||
namespace Api\ApiKey;
|
||||
|
||||
use \Api\Request;
|
||||
use DateTime;
|
||||
use \Driver\SQL\Condition\Compare;
|
||||
|
||||
class Fetch extends Request {
|
||||
|
||||
public function __construct($user, $externCall = false) {
|
||||
parent::__construct($user, $externCall, array());
|
||||
public function __construct($user, $externalCall = false) {
|
||||
parent::__construct($user, $externalCall, array());
|
||||
$this->loginRequired = true;
|
||||
}
|
||||
|
||||
@@ -31,16 +32,20 @@ class Fetch extends Request {
|
||||
if($this->success) {
|
||||
$this->result["api_keys"] = array();
|
||||
foreach($res as $row) {
|
||||
try {
|
||||
$validUntil = (new DateTime($row["valid_until"]))->getTimestamp();
|
||||
} catch (\Exception $e) {
|
||||
$validUntil = $row["valid_until"];
|
||||
}
|
||||
|
||||
$this->result["api_keys"][] = array(
|
||||
"uid" => $row["uid"],
|
||||
"api_key" => $row["api_key"],
|
||||
"valid_until" => (new \DateTime($row["valid_until"]))->getTimestamp(),
|
||||
);
|
||||
"uid" => $row["uid"],
|
||||
"api_key" => $row["api_key"],
|
||||
"valid_until" => $validUntil,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->success;
|
||||
}
|
||||
};
|
||||
|
||||
?>
|
||||
}
|
||||
@@ -8,8 +8,8 @@ use \Driver\SQL\Condition\Compare;
|
||||
|
||||
class Refresh extends Request {
|
||||
|
||||
public function __construct($user, $externCall = false) {
|
||||
parent::__construct($user, $externCall, array(
|
||||
public function __construct($user, $externalCall = false) {
|
||||
parent::__construct($user, $externalCall, array(
|
||||
"id" => new Parameter("id", Parameter::TYPE_INT),
|
||||
));
|
||||
$this->loginRequired = true;
|
||||
@@ -62,6 +62,4 @@ class Refresh extends Request {
|
||||
|
||||
return $this->success;
|
||||
}
|
||||
};
|
||||
|
||||
?>
|
||||
}
|
||||
@@ -8,8 +8,8 @@ use \Driver\SQL\Condition\Compare;
|
||||
|
||||
class Revoke extends Request {
|
||||
|
||||
public function __construct($user, $externCall = false) {
|
||||
parent::__construct($user, $externCall, array(
|
||||
public function __construct($user, $externalCall = false) {
|
||||
parent::__construct($user, $externalCall, array(
|
||||
"id" => new Parameter("id", Parameter::TYPE_INT),
|
||||
));
|
||||
$this->loginRequired = true;
|
||||
@@ -57,6 +57,4 @@ class Revoke extends Request {
|
||||
|
||||
return $this->success;
|
||||
}
|
||||
};
|
||||
|
||||
?>
|
||||
}
|
||||
|
||||
@@ -4,8 +4,8 @@ namespace Api;
|
||||
|
||||
class GetLanguages extends Request {
|
||||
|
||||
public function __construct($user, $externCall = false) {
|
||||
parent::__construct($user, $externCall, array());
|
||||
public function __construct($user, $externalCall = false) {
|
||||
parent::__construct($user, $externalCall, array());
|
||||
}
|
||||
|
||||
public function execute($values = array()) {
|
||||
@@ -34,6 +34,4 @@ class GetLanguages extends Request {
|
||||
|
||||
return $this->success;
|
||||
}
|
||||
};
|
||||
|
||||
?>
|
||||
}
|
||||
@@ -9,8 +9,8 @@ use \Driver\SQL\Condition\Compare;
|
||||
|
||||
class Create extends Request {
|
||||
|
||||
public function __construct($user, $externCall = false) {
|
||||
parent::__construct($user, $externCall, array(
|
||||
public function __construct($user, $externalCall = false) {
|
||||
parent::__construct($user, $externalCall, array(
|
||||
'groupId' => new Parameter('groupId', Parameter::TYPE_INT, true),
|
||||
'userId' => new Parameter('userId', Parameter::TYPE_INT, true),
|
||||
'title' => new StringType('title', 32),
|
||||
@@ -130,6 +130,4 @@ class Create extends Request {
|
||||
|
||||
return $this->success;
|
||||
}
|
||||
};
|
||||
|
||||
?>
|
||||
}
|
||||
@@ -7,10 +7,10 @@ use \Driver\SQL\Condition\Compare;
|
||||
|
||||
class Fetch extends Request {
|
||||
|
||||
private $notifications;
|
||||
private array $notifications;
|
||||
|
||||
public function __construct($user, $externCall = false) {
|
||||
parent::__construct($user, $externCall, array());
|
||||
public function __construct($user, $externalCall = false) {
|
||||
parent::__construct($user, $externalCall, array());
|
||||
$this->loginRequired = true;
|
||||
}
|
||||
|
||||
@@ -89,6 +89,4 @@ class Fetch extends Request {
|
||||
|
||||
return $this->success;
|
||||
}
|
||||
};
|
||||
|
||||
?>
|
||||
}
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace Api\Parameter;
|
||||
|
||||
use DateTime;
|
||||
|
||||
class Parameter {
|
||||
const TYPE_INT = 0;
|
||||
const TYPE_FLOAT = 1;
|
||||
@@ -18,11 +20,11 @@ class Parameter {
|
||||
|
||||
const names = array('Integer', 'Float', 'Boolean', 'String', 'Date', 'Time', 'DateTime', 'E-Mail', 'Raw', 'Array');
|
||||
|
||||
public $name;
|
||||
public string $name;
|
||||
public $value;
|
||||
public $optional;
|
||||
public $type;
|
||||
public $typeName;
|
||||
public int $type;
|
||||
public string $typeName;
|
||||
|
||||
public function __construct($name, $type, $optional = FALSE, $defaultValue = NULL) {
|
||||
$this->name = $name;
|
||||
@@ -59,11 +61,11 @@ class Parameter {
|
||||
return Parameter::TYPE_BOOLEAN;
|
||||
else if(is_a($value, 'DateTime'))
|
||||
return Parameter::TYPE_DATE_TIME;
|
||||
else if(($d = \DateTime::createFromFormat('Y-m-d', $value)) && $d->format('Y-m-d') === $value)
|
||||
else if(($d = DateTime::createFromFormat('Y-m-d', $value)) && $d->format('Y-m-d') === $value)
|
||||
return Parameter::TYPE_DATE;
|
||||
else if(($d = \DateTime::createFromFormat('H:i:s', $value)) && $d->format('H:i:s') === $value)
|
||||
else if(($d = DateTime::createFromFormat('H:i:s', $value)) && $d->format('H:i:s') === $value)
|
||||
return Parameter::TYPE_TIME;
|
||||
else if(($d = \DateTime::createFromFormat('Y-m-d H:i:s', $value)) && $d->format('Y-m-d H:i:s') === $value)
|
||||
else if(($d = DateTime::createFromFormat('Y-m-d H:i:s', $value)) && $d->format('Y-m-d H:i:s') === $value)
|
||||
return Parameter::TYPE_DATE_TIME;
|
||||
else if (filter_var($value, FILTER_VALIDATE_EMAIL))
|
||||
return Parameter::TYPE_EMAIL;
|
||||
@@ -156,6 +158,4 @@ class Parameter {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
}
|
||||
@@ -4,10 +4,10 @@ namespace Api\Parameter;
|
||||
|
||||
class StringType extends Parameter {
|
||||
|
||||
public $maxLength;
|
||||
public int $maxLength;
|
||||
public function __construct($name, $maxLength = -1, $optional = FALSE, $defaultValue = NULL) {
|
||||
parent::__construct($name, Parameter::TYPE_STRING, $optional, $defaultValue);
|
||||
$this->maxLength = $maxLength;
|
||||
parent::__construct($name, Parameter::TYPE_STRING, $optional, $defaultValue);
|
||||
}
|
||||
|
||||
public function parseParam($value) {
|
||||
@@ -38,6 +38,4 @@ class StringType extends Parameter {
|
||||
|
||||
return $str;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
}
|
||||
@@ -2,30 +2,32 @@
|
||||
|
||||
namespace Api;
|
||||
|
||||
use Objects\User;
|
||||
|
||||
class Request {
|
||||
|
||||
protected $user;
|
||||
protected $params;
|
||||
protected $lastError;
|
||||
protected $result;
|
||||
protected $success;
|
||||
protected $isPublic;
|
||||
protected $loginRequired;
|
||||
protected $variableParamCount;
|
||||
protected $isDisabled;
|
||||
protected $apiKeyAllowed;
|
||||
protected User $user;
|
||||
protected array $params;
|
||||
protected string $lastError;
|
||||
protected array $result;
|
||||
protected bool $success;
|
||||
protected bool $isPublic;
|
||||
protected bool $loginRequired;
|
||||
protected bool $variableParamCount;
|
||||
protected bool $isDisabled;
|
||||
protected bool $apiKeyAllowed;
|
||||
|
||||
private $aDefaultParams;
|
||||
private $allowedMethods;
|
||||
private $externCall;
|
||||
private array $aDefaultParams;
|
||||
private array $allowedMethods;
|
||||
private bool $externCall;
|
||||
|
||||
public function __construct($user, $externCall = false, $params = array()) {
|
||||
public function __construct(User $user, bool $externalCall = false, array $params = array()) {
|
||||
$this->user = $user;
|
||||
$this->aDefaultParams = $params;
|
||||
$this->lastError = '';
|
||||
$this->success = false;
|
||||
$this->result = array();
|
||||
$this->externCall = $externCall;
|
||||
$this->externCall = $externalCall;
|
||||
$this->isPublic = true;
|
||||
$this->isDisabled = false;
|
||||
$this->loginRequired = false;
|
||||
@@ -40,19 +42,6 @@ class Request {
|
||||
}
|
||||
}
|
||||
|
||||
public function getParamsString() {
|
||||
$str = "";
|
||||
$count = count($this->params);
|
||||
$i = 0;
|
||||
foreach($this->params as $param) {
|
||||
$str .= $param->toString();
|
||||
if($i < $count - 1) $str .= ", ";
|
||||
$i++;
|
||||
}
|
||||
|
||||
return "($str)";
|
||||
}
|
||||
|
||||
public function parseParams($values) {
|
||||
foreach($this->params as $name => $param) {
|
||||
$value = (isset($values[$name]) ? $values[$name] : NULL);
|
||||
@@ -149,47 +138,24 @@ class Request {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function isValidString($str, $regex) {
|
||||
return preg_replace($regex, "", $str) === $str;
|
||||
}
|
||||
|
||||
protected function createError($err) {
|
||||
$this->success = false;
|
||||
$this->lastError = $err;
|
||||
return false;
|
||||
}
|
||||
//
|
||||
// public static function callDirectly($class, $db) {
|
||||
// header('Content-Type: application/json');
|
||||
// require_once realpath($_SERVER['DOCUMENT_ROOT']) . '/php/api/objects/User.php';
|
||||
// require_once realpath($_SERVER['DOCUMENT_ROOT']) . '/php/sql.php';
|
||||
// require_once realpath($_SERVER['DOCUMENT_ROOT']) . '/php/conf/sql.php';
|
||||
//
|
||||
// $sql = connectSQL(getSqlData($db));
|
||||
// $user = new CUser($sql);
|
||||
// $request = new $class($user, true);
|
||||
// $request->execute();
|
||||
// $sql->close();
|
||||
// $user->sendCookies();
|
||||
// return $request->getJsonResult();
|
||||
// }
|
||||
|
||||
protected function getParam($name) { return isset($this->params[$name]) ? $this->params[$name]->value : NULL; }
|
||||
|
||||
public function isPublic() { return $this->isPublic; }
|
||||
public function getDescription() { return ''; }
|
||||
public function getSection() { return 'Default'; }
|
||||
public function getLastError() { return $this->lastError; }
|
||||
public function getResult() { return $this->result; }
|
||||
public function success() { return $this->success; }
|
||||
public function loginRequired() { return $this->loginRequired; }
|
||||
public function isExternCall() { return $this->externCall; }
|
||||
public function isExternalCall() { return $this->externCall; }
|
||||
|
||||
public function getJsonResult() {
|
||||
$this->result['success'] = $this->success;
|
||||
$this->result['msg'] = $this->lastError;
|
||||
return json_encode($this->result);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
?>
|
||||
}
|
||||
@@ -3,11 +3,13 @@
|
||||
namespace Api;
|
||||
use Api\Parameter\Parameter;
|
||||
use Api\Parameter\StringType;
|
||||
use External\PHPMailer\Exception;
|
||||
use External\PHPMailer\PHPMailer;
|
||||
|
||||
class SendMail extends Request {
|
||||
|
||||
public function __construct($user, $externCall = false) {
|
||||
parent::__construct($user, $externCall, array(
|
||||
public function __construct($user, $externalCall = false) {
|
||||
parent::__construct($user, $externalCall, array(
|
||||
'from' => new Parameter('from', Parameter::TYPE_EMAIL),
|
||||
'to' => new Parameter('to', Parameter::TYPE_EMAIL),
|
||||
'subject' => new StringType('subject', -1),
|
||||
@@ -23,36 +25,39 @@ class SendMail extends Request {
|
||||
return false;
|
||||
}
|
||||
|
||||
$mailConfig = $this->user->getConfiguration()->getMail();
|
||||
$mail = new \External\PHPMailer\PHPMailer;
|
||||
$mail->IsSMTP();
|
||||
$mail->setFrom($this->getParam('from'), $this->getParam('fromName'));
|
||||
$mail->addAddress($this->getParam('to'));
|
||||
$mail->Subject = $this->getParam('subject');
|
||||
$mail->SMTPDebug = 0;
|
||||
$mail->Host = $mailConfig->getHost();
|
||||
$mail->Port = $mailConfig->getPort();
|
||||
$mail->SMTPAuth = true;
|
||||
$mail->Username = $mailConfig->getLogin();
|
||||
$mail->Password = $mailConfig->getPassword();
|
||||
$mail->SMTPSecure = 'tls';
|
||||
$mail->IsHTML(true);
|
||||
$mail->CharSet = 'UTF-8';
|
||||
$mail->Body = $this->getParam('body');
|
||||
try {
|
||||
$mailConfig = $this->user->getConfiguration()->getMail();
|
||||
$mail = new PHPMailer;
|
||||
$mail->IsSMTP();
|
||||
$mail->setFrom($this->getParam('from'), $this->getParam('fromName'));
|
||||
$mail->addAddress($this->getParam('to'));
|
||||
$mail->Subject = $this->getParam('subject');
|
||||
$mail->SMTPDebug = 0;
|
||||
$mail->Host = $mailConfig->getHost();
|
||||
$mail->Port = $mailConfig->getPort();
|
||||
$mail->SMTPAuth = true;
|
||||
$mail->Username = $mailConfig->getLogin();
|
||||
$mail->Password = $mailConfig->getPassword();
|
||||
$mail->SMTPSecure = 'tls';
|
||||
$mail->IsHTML(true);
|
||||
$mail->CharSet = 'UTF-8';
|
||||
$mail->Body = $this->getParam('body');
|
||||
|
||||
$replyTo = $this->getParam('replyTo');
|
||||
if(!is_null($replyTo) && !empty($replyTo)) {
|
||||
$mail->AddReplyTo($replyTo, $this->getParam('fromName'));
|
||||
}
|
||||
$replyTo = $this->getParam('replyTo');
|
||||
if(!is_null($replyTo) && !empty($replyTo)) {
|
||||
$mail->AddReplyTo($replyTo, $this->getParam('fromName'));
|
||||
}
|
||||
|
||||
$this->success = @$mail->Send();
|
||||
if (!$this->success) {
|
||||
$this->lastError = 'Error sending Mail: ' . $mail->ErrorInfo;
|
||||
error_log("sendMail() failed: " . $mail->ErrorInfo);
|
||||
$this->success = @$mail->Send();
|
||||
if (!$this->success) {
|
||||
$this->lastError = "Error sending Mail: $mail->ErrorInfo";
|
||||
error_log("sendMail() failed: $mail->ErrorInfo");
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$this->success = false;
|
||||
$this->lastError = "Error sending Mail: $e";
|
||||
}
|
||||
|
||||
return $this->success;
|
||||
}
|
||||
};
|
||||
|
||||
?>
|
||||
}
|
||||
@@ -6,13 +6,14 @@ use Api\Parameter\Parameter;
|
||||
use Api\Parameter\StringType;
|
||||
use Driver\SQL\Condition\CondOr;
|
||||
use Driver\SQL\Condition\Compare;
|
||||
use Objects\Language;
|
||||
|
||||
class SetLanguage extends Request {
|
||||
|
||||
private $language;
|
||||
private Language $language;
|
||||
|
||||
public function __construct($user, $externCall = false) {
|
||||
parent::__construct($user, $externCall, array(
|
||||
public function __construct($user, $externalCall = false) {
|
||||
parent::__construct($user, $externalCall, array(
|
||||
'langId' => new Parameter('langId', Parameter::TYPE_INT, true, NULL),
|
||||
'langCode' => new StringType('langCode', 5, true, NULL),
|
||||
));
|
||||
@@ -40,7 +41,7 @@ class SetLanguage extends Request {
|
||||
return $this->createError(L("This Language does not exist"));
|
||||
} else {
|
||||
$row = $res[0];
|
||||
$this->language = \Objects\Language::newInstance($row['uid'], $row['code'], $row['name']);
|
||||
$this->language = Language::newInstance($row['uid'], $row['code'], $row['name']);
|
||||
if(!$this->language) {
|
||||
return $this->createError(L("Error while loading language"));
|
||||
}
|
||||
@@ -75,9 +76,7 @@ class SetLanguage extends Request {
|
||||
$this->updateLanguage();
|
||||
}
|
||||
|
||||
$this->user->setLangauge($this->language);
|
||||
$this->user->setLanguage($this->language);
|
||||
return $this->success;
|
||||
}
|
||||
};
|
||||
|
||||
?>
|
||||
}
|
||||
@@ -9,10 +9,10 @@ use \Driver\SQL\Condition\Compare;
|
||||
|
||||
class Login extends Request {
|
||||
|
||||
private $startedAt;
|
||||
private int $startedAt;
|
||||
|
||||
public function __construct($user, $externCall = false) {
|
||||
parent::__construct($user, $externCall, array(
|
||||
public function __construct($user, $externalCall = false) {
|
||||
parent::__construct($user, $externalCall, array(
|
||||
'username' => new StringType('username', 32),
|
||||
'password' => new StringType('password'),
|
||||
'stayLoggedIn' => new Parameter('stayLoggedIn', Parameter::TYPE_BOOLEAN, true, true)
|
||||
@@ -77,6 +77,4 @@ class Login extends Request {
|
||||
|
||||
return $this->success;
|
||||
}
|
||||
};
|
||||
|
||||
?>
|
||||
}
|
||||
@@ -6,8 +6,8 @@ use \Api\Request;
|
||||
|
||||
class Logout extends Request {
|
||||
|
||||
public function __construct($user, $externCall = false) {
|
||||
parent::__construct($user, $externCall);
|
||||
public function __construct($user, $externalCall = false) {
|
||||
parent::__construct($user, $externalCall);
|
||||
$this->loginRequired = true;
|
||||
$this->apiKeyAllowed = false;
|
||||
}
|
||||
@@ -21,6 +21,4 @@ class Logout extends Request {
|
||||
$this->lastError = $this->user->getSQL()->getLastError();
|
||||
return $this->success;
|
||||
}
|
||||
};
|
||||
|
||||
?>
|
||||
}
|
||||
Reference in New Issue
Block a user