This commit is contained in:
Roman 2022-02-20 18:31:54 +01:00
parent bd1f302433
commit 16a46dd88a
9 changed files with 88 additions and 27 deletions

1
core/.gitignore vendored Normal file

@ -0,0 +1 @@
TemplateCache

@ -104,11 +104,11 @@ class Parameter {
return Parameter::TYPE_BOOLEAN; return Parameter::TYPE_BOOLEAN;
else if(is_a($value, 'DateTime')) else if(is_a($value, 'DateTime'))
return Parameter::TYPE_DATE_TIME; return Parameter::TYPE_DATE_TIME;
else if(($d = DateTime::createFromFormat(self::DATE_FORMAT, $value)) && $d->format(self::DATE_FORMAT) === $value) else if($value !== null && ($d = DateTime::createFromFormat(self::DATE_FORMAT, $value)) && $d->format(self::DATE_FORMAT) === $value)
return Parameter::TYPE_DATE; return Parameter::TYPE_DATE;
else if(($d = DateTime::createFromFormat(self::TIME_FORMAT, $value)) && $d->format(self::TIME_FORMAT) === $value) else if($value !== null && ($d = DateTime::createFromFormat(self::TIME_FORMAT, $value)) && $d->format(self::TIME_FORMAT) === $value)
return Parameter::TYPE_TIME; return Parameter::TYPE_TIME;
else if(($d = DateTime::createFromFormat(self::DATE_TIME_FORMAT, $value)) && $d->format(self::DATE_TIME_FORMAT) === $value) else if($value !== null && ($d = DateTime::createFromFormat(self::DATE_TIME_FORMAT, $value)) && $d->format(self::DATE_TIME_FORMAT) === $value)
return Parameter::TYPE_DATE_TIME; return Parameter::TYPE_DATE_TIME;
else if (filter_var($value, FILTER_VALIDATE_EMAIL)) else if (filter_var($value, FILTER_VALIDATE_EMAIL))
return Parameter::TYPE_EMAIL; return Parameter::TYPE_EMAIL;

@ -67,11 +67,11 @@ namespace Api {
$this->checkPasswordRequirements($password, $confirmPassword); $this->checkPasswordRequirements($password, $confirmPassword);
} }
protected function insertUser($username, $email, $password, $confirmed, $fullName = null) { protected function insertUser($username, $email, $password, $confirmed, $fullName = "") {
$sql = $this->user->getSQL(); $sql = $this->user->getSQL();
$hash = $this->hashPassword($password); $hash = $this->hashPassword($password);
$res = $sql->insert("User", array("name", "password", "email", "confirmed", "fullName")) $res = $sql->insert("User", array("name", "password", "email", "confirmed", "fullName"))
->addRow($username, $hash, $email, $confirmed, $fullName) ->addRow($username, $hash, $email, $confirmed, $fullName ?? "")
->returning("uid") ->returning("uid")
->execute(); ->execute();

@ -27,6 +27,24 @@ class CreateDatabase extends DatabaseScript {
->addRow("en_US", 'American English') ->addRow("en_US", 'American English')
->addRow("de_DE", 'Deutsch Standard'); ->addRow("de_DE", 'Deutsch Standard');
$queries[] = $sql->createTable("GpgKey")
->addSerial("uid")
->addString("fingerprint", 64)
->addDateTime("added", false, $sql->now())
->addDateTime("expires")
->addBool("confirmed")
->addString("algorithm", 32)
->primaryKey("uid");
$queries[] = $sql->createTable("2FA")
->addSerial("uid")
->addEnum("type", ["totp","fido"])
->addString("data", 512) // either totp secret, fido challenge or fido public key information
->addBool("confirmed", false)
->addDateTime("added", false, $sql->now())
->primaryKey("uid");
$queries[] = $sql->createTable("User") $queries[] = $sql->createTable("User")
->addSerial("uid") ->addSerial("uid")
->addString("email", 64, true) ->addString("email", 64, true)
@ -210,23 +228,6 @@ class CreateDatabase extends DatabaseScript {
->primaryKey("uid"); ->primaryKey("uid");
$queries = array_merge($queries, \Configuration\Patch\log::createTableLog($sql, "MailQueue", 30)); $queries = array_merge($queries, \Configuration\Patch\log::createTableLog($sql, "MailQueue", 30));
$queries[] = $sql->createTable("GpgKey")
->addSerial("uid")
->addString("fingerprint", 64)
->addDateTime("added", false, $sql->now())
->addDateTime("expires")
->addBool("confirmed")
->addString("algorithm", 32)
->primaryKey("uid");
$queries[] = $sql->createTable("2FA")
->addSerial("uid")
->addEnum("type", ["totp","fido"])
->addString("data", 512) // either totp secret, fido challenge or fido public key information
->addBool("confirmed", false)
->addDateTime("added", false, $sql->now())
->primaryKey("uid");
$queries[] = $sql->createTable("News") $queries[] = $sql->createTable("News")
->addSerial("uid") ->addSerial("uid")
->addInt("publishedBy") ->addInt("publishedBy")

@ -17,6 +17,9 @@ namespace Documents {
namespace Documents\Install { namespace Documents\Install {
use Configuration\CreateDatabase; use Configuration\CreateDatabase;
use Driver\SQL\Query\Commit;
use Driver\SQL\Query\RollBack;
use Driver\SQL\Query\StartTransaction;
use Driver\SQL\SQL; use Driver\SQL\SQL;
use Elements\Body; use Elements\Body;
use Elements\Head; use Elements\Head;
@ -271,10 +274,21 @@ namespace Documents\Install {
$msg = ""; $msg = "";
$success = true; $success = true;
$queries = CreateDatabase::createQueries($sql); $queries = CreateDatabase::createQueries($sql);
array_unshift($queries, new StartTransaction($sql));
$queries[] = new Commit($sql);
foreach ($queries as $query) { foreach ($queries as $query) {
if (!($res = $query->execute())) { try {
if (!$query->execute()) {
$msg = "Error creating tables: " . $sql->getLastError(); $msg = "Error creating tables: " . $sql->getLastError();
$success = false; $success = false;
}
} finally {
if (!$success) {
(new RollBack($sql))->execute();
}
}
if (!$success) {
break; break;
} }
} }
@ -619,7 +633,7 @@ namespace Documents\Install {
)), )),
array( array(
"title" => "Encoding", "name" => "encoding", "type" => "text", "required" => false, "title" => "Encoding", "name" => "encoding", "type" => "text", "required" => false,
"value" => "UTF-8" "value" => "UTF8"
), ),
) )
), ),

@ -0,0 +1,15 @@
<?php
namespace Driver\SQL\Query;
use Driver\SQL\SQL;
class Commit extends Query {
public function __construct(SQL $sql) {
parent::__construct($sql);
}
public function build(array &$params): ?string {
return "COMMIT";
}
}

@ -0,0 +1,15 @@
<?php
namespace Driver\SQL\Query;
use Driver\SQL\SQL;
class RollBack extends Query {
public function __construct(SQL $sql) {
parent::__construct($sql);
}
public function build(array &$params): ?string {
return "ROLLBACK";
}
}

@ -0,0 +1,15 @@
<?php
namespace Driver\SQL\Query;
use Driver\SQL\SQL;
class StartTransaction extends Query {
public function __construct(SQL $sql) {
parent::__construct($sql);
}
public function build(array &$params): ?string {
return "START TRANSACTION";
}
}

@ -2,7 +2,7 @@
require_once "External/vendor/autoload.php"; require_once "External/vendor/autoload.php";
define("WEBBASE_VERSION", "1.4.0"); define("WEBBASE_VERSION", "1.4.1");
spl_autoload_extensions(".php"); spl_autoload_extensions(".php");
spl_autoload_register(function($class) { spl_autoload_register(function($class) {