php 7.4 dev branch
This commit is contained in:
@@ -6,9 +6,6 @@ abstract class ApiObject implements \JsonSerializable {
|
||||
|
||||
public abstract function jsonSerialize();
|
||||
|
||||
public function __construct() { }
|
||||
public function __toString() { return json_encode($this); }
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@@ -4,11 +4,11 @@ namespace Objects;
|
||||
|
||||
class ConnectionData {
|
||||
|
||||
private $host;
|
||||
private $port;
|
||||
private $login;
|
||||
private $password;
|
||||
private $properties;
|
||||
private string $host;
|
||||
private int $port;
|
||||
private string $login;
|
||||
private string $password;
|
||||
private array $properties;
|
||||
|
||||
public function __construct($host, $port, $login, $password) {
|
||||
$this->host = $host;
|
||||
@@ -32,12 +32,11 @@ class ConnectionData {
|
||||
}
|
||||
|
||||
$this->properties[$key] = $val;
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getHost() { return $this->host; }
|
||||
public function getPort() { return $this->port; }
|
||||
public function getLogin() { return $this->login; }
|
||||
public function getPassword() { return $this->password; }
|
||||
}
|
||||
|
||||
?>
|
||||
}
|
||||
@@ -2,16 +2,18 @@
|
||||
|
||||
namespace Objects {
|
||||
|
||||
class Language extends ApiObject {
|
||||
use LanguageModule;
|
||||
|
||||
class Language extends ApiObject {
|
||||
|
||||
const LANG_CODE_PATTERN = "/^[a-zA-Z]+_[a-zA-Z]+$/";
|
||||
|
||||
private $languageId;
|
||||
private $langCode;
|
||||
private $langName;
|
||||
private $modules;
|
||||
private int $languageId;
|
||||
private string $langCode;
|
||||
private string $langName;
|
||||
private array $modules;
|
||||
|
||||
protected $entries;
|
||||
protected array $entries;
|
||||
|
||||
public function __construct($languageId, $langCode, $langName) {
|
||||
$this->languageId = $languageId;
|
||||
@@ -29,7 +31,7 @@ namespace Objects {
|
||||
public function getEntries() { return $this->entries; }
|
||||
public function getModules() { return $this->modules; }
|
||||
|
||||
public function loadModule($module) {
|
||||
public function loadModule(LanguageModule $module) {
|
||||
if(!is_object($module))
|
||||
$module = new $module;
|
||||
|
||||
@@ -100,7 +102,8 @@ namespace Objects {
|
||||
}
|
||||
|
||||
namespace {
|
||||
function L($key) {
|
||||
|
||||
function L($key) {
|
||||
if(!array_key_exists('LANGUAGE', $GLOBALS))
|
||||
return $key;
|
||||
|
||||
@@ -132,4 +135,3 @@ namespace {
|
||||
return $LANGUAGE->getShortCode();
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
@@ -2,21 +2,24 @@
|
||||
|
||||
namespace Objects;
|
||||
|
||||
use DateTime;
|
||||
use \Driver\SQL\Condition\Compare;
|
||||
use Exception;
|
||||
use External\JWT;
|
||||
|
||||
class Session extends ApiObject {
|
||||
|
||||
const DURATION = 120;
|
||||
|
||||
private $sessionId;
|
||||
private $user;
|
||||
private $expires;
|
||||
private $ipAddress;
|
||||
private $os;
|
||||
private $browser;
|
||||
private $stayLoggedIn;
|
||||
private ?int $sessionId;
|
||||
private User $user;
|
||||
private int $expires;
|
||||
private string $ipAddress;
|
||||
private ?string $os;
|
||||
private ?string $browser;
|
||||
private bool $stayLoggedIn;
|
||||
|
||||
public function __construct($user, $sessionId) {
|
||||
public function __construct(User $user, ?int $sessionId) {
|
||||
$this->user = $user;
|
||||
$this->sessionId = $sessionId;
|
||||
$this->stayLoggedIn = true;
|
||||
@@ -38,7 +41,7 @@ class Session extends ApiObject {
|
||||
$userAgent = @get_browser($_SERVER['HTTP_USER_AGENT'], true);
|
||||
$this->os = $userAgent['platform'] ?? "Unknown";
|
||||
$this->browser = $userAgent['parent'] ?? "Unknown";
|
||||
} catch(\Exception $ex) {
|
||||
} catch(Exception $ex) {
|
||||
$this->os = "Unknown";
|
||||
$this->browser = "Unknown";
|
||||
}
|
||||
@@ -59,7 +62,7 @@ class Session extends ApiObject {
|
||||
$jwt = $this->user->getConfiguration()->getJwt();
|
||||
if($jwt) {
|
||||
$token = array('userId' => $this->user->getId(), 'sessionId' => $this->sessionId);
|
||||
$sessionCookie = \External\JWT::encode($token, $jwt->getKey());
|
||||
$sessionCookie = JWT::encode($token, $jwt->getKey());
|
||||
$secure = strcmp(getProtocol(), "https") === 0;
|
||||
setcookie('session', $sessionCookie, $this->getExpiresTime(), "/", "", $secure);
|
||||
}
|
||||
@@ -94,7 +97,7 @@ class Session extends ApiObject {
|
||||
$success = $sql
|
||||
->insert("Session", $columns)
|
||||
->addRow(
|
||||
(new \DateTime)->modify("+$hours hour"),
|
||||
(new DateTime())->modify("+$hours hour"),
|
||||
$this->user->getId(),
|
||||
$this->ipAddress,
|
||||
$this->os,
|
||||
@@ -113,13 +116,11 @@ class Session extends ApiObject {
|
||||
}
|
||||
|
||||
public function destroy() {
|
||||
$success = $this->user->getSQL()->update("Session")
|
||||
return $this->user->getSQL()->update("Session")
|
||||
->set("active", false)
|
||||
->where(new Compare("Session.uid", $this->sessionId))
|
||||
->where(new Compare("Session.user_id", $this->user->getId()))
|
||||
->execute();
|
||||
|
||||
return $success;
|
||||
}
|
||||
|
||||
public function update() {
|
||||
@@ -127,8 +128,8 @@ class Session extends ApiObject {
|
||||
$hours = Session::DURATION;
|
||||
|
||||
$sql = $this->user->getSQL();
|
||||
$success = $sql->update("Session")
|
||||
->set("Session.expires", (new \DateTime)->modify("+$hours hour"))
|
||||
return $sql->update("Session")
|
||||
->set("Session.expires", (new DateTime())->modify("+$hours hour"))
|
||||
->set("Session.ipAddress", $this->ipAddress)
|
||||
->set("Session.os", $this->os)
|
||||
->set("Session.browser", $this->browser)
|
||||
@@ -136,9 +137,5 @@ class Session extends ApiObject {
|
||||
->where(new Compare("Session.uid", $this->sessionId))
|
||||
->where(new Compare("Session.user_id", $this->user->getId()))
|
||||
->execute();
|
||||
|
||||
return $success;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@@ -2,25 +2,28 @@
|
||||
|
||||
namespace Objects;
|
||||
|
||||
use \External\JWT;
|
||||
use Driver\SQL\Column\Column;
|
||||
use Api\SetLanguage;
|
||||
use Configuration\Configuration;
|
||||
use Exception;
|
||||
use External\JWT;
|
||||
use Driver\SQL\SQL;
|
||||
use Driver\SQL\Condition\Compare;
|
||||
use Driver\SQL\Condition\CondBool;
|
||||
|
||||
class User extends ApiObject {
|
||||
|
||||
private $sql;
|
||||
private $configuration;
|
||||
private $loggedIn;
|
||||
private $session;
|
||||
private $uid;
|
||||
private $username;
|
||||
private $language;
|
||||
private ?SQL $sql;
|
||||
private Configuration $configuration;
|
||||
private bool $loggedIn;
|
||||
private ?Session $session;
|
||||
private int $uid;
|
||||
private string $username;
|
||||
private Language $language;
|
||||
|
||||
public function __construct($configuration) {
|
||||
session_start();
|
||||
$this->configuration = $configuration;
|
||||
$this->setLangauge(Language::DEFAULT_LANGUAGE());
|
||||
$this->setLanguage(Language::DEFAULT_LANGUAGE());
|
||||
$this->reset();
|
||||
$this->connectDb();
|
||||
$this->parseCookies();
|
||||
@@ -35,7 +38,9 @@ class User extends ApiObject {
|
||||
private function connectDb() {
|
||||
$databaseConf = $this->configuration->getDatabase();
|
||||
if($databaseConf) {
|
||||
$this->sql = \Driver\SQL\SQL::createConnection($databaseConf);
|
||||
$this->sql = SQL::createConnection($databaseConf);
|
||||
} else {
|
||||
$this->sql = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +49,7 @@ class User extends ApiObject {
|
||||
public function getUsername() { return $this->username; }
|
||||
public function getSQL() { return $this->sql; }
|
||||
public function getLanguage() { return $this->language; }
|
||||
public function setLangauge($language) { $this->language = $language; $language->load(); }
|
||||
public function setLanguage(Language $language) { $this->language = $language; $language->load(); }
|
||||
public function getSession() { return $this->session; }
|
||||
public function getConfiguration() { return $this->configuration; }
|
||||
|
||||
@@ -75,7 +80,7 @@ class User extends ApiObject {
|
||||
$this->uid = 0;
|
||||
$this->username = '';
|
||||
$this->loggedIn = false;
|
||||
$this->session = false;
|
||||
$this->session = null;
|
||||
}
|
||||
|
||||
public function logout() {
|
||||
@@ -90,8 +95,10 @@ class User extends ApiObject {
|
||||
|
||||
public function updateLanguage($lang) {
|
||||
if($this->sql) {
|
||||
$request = new \Api\SetLanguage($this);
|
||||
$request = new SetLanguage($this);
|
||||
return $request->execute(array("langCode" => $lang));
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,7 +137,7 @@ class User extends ApiObject {
|
||||
if($sessionUpdate) $this->session->update();
|
||||
$this->loggedIn = true;
|
||||
if(!is_null($row['langId'])) {
|
||||
$this->setLangauge(Language::newInstance($row['langId'], $row['langCode'], $row['langName']));
|
||||
$this->setLanguage(Language::newInstance($row['langId'], $row['langCode'], $row['langName']));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -153,7 +160,7 @@ class User extends ApiObject {
|
||||
$this->readData($userId, $sessionId);
|
||||
}
|
||||
}
|
||||
} catch(\Exception $e) {
|
||||
} catch(Exception $e) {
|
||||
// ignored
|
||||
}
|
||||
}
|
||||
@@ -187,7 +194,7 @@ class User extends ApiObject {
|
||||
->leftJoin("Language", "User.language_id", "Language.uid")
|
||||
->where(new Compare("ApiKey.api_key", $apiKey))
|
||||
->where(new Compare("valid_until", $this->sql->currentTimestamp(), ">"))
|
||||
->where(new COmpare("ApiKey.active", 1))
|
||||
->where(new Compare("ApiKey.active", 1))
|
||||
->execute();
|
||||
|
||||
$success = ($res !== FALSE);
|
||||
@@ -200,7 +207,7 @@ class User extends ApiObject {
|
||||
$this->username = $row['username'];
|
||||
|
||||
if(!is_null($row['langId'])) {
|
||||
$this->setLangauge(Language::newInstance($row['langId'], $row['langCode'], $row['langName']));
|
||||
$this->setLanguage(Language::newInstance($row['langId'], $row['langCode'], $row['langName']));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -208,5 +215,3 @@ class User extends ApiObject {
|
||||
return $success;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
<?php
|
||||
|
||||
require_once './LanguageModule.php';
|
||||
|
||||
abstract class CLanguageModuleGeneral {
|
||||
|
||||
public static function getEntries($langCode) {
|
||||
switch($langCode) {
|
||||
case "de_DE":
|
||||
$this->entries[""] = "";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -1,9 +1,6 @@
|
||||
<?php
|
||||
|
||||
abstract class CLanguageModule {
|
||||
abstract class LanguageModule {
|
||||
|
||||
public abstract static function getEntries($langCode);
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
public abstract function getEntries(string $langCode);
|
||||
}
|
||||
Reference in New Issue
Block a user