Twig, Tests, AES,
This commit is contained in:
@@ -1,74 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace Documents {
|
||||
|
||||
use Documents\Account\AccountBody;
|
||||
use Documents\Account\AccountHead;
|
||||
use Elements\Document;
|
||||
use Objects\User;
|
||||
namespace Documents;
|
||||
|
||||
class Account extends Document {
|
||||
public function __construct(User $user, ?string $view) {
|
||||
parent::__construct($user, AccountHead::class, AccountBody::class, $view);
|
||||
}
|
||||
}
|
||||
}
|
||||
use Elements\TemplateDocument;
|
||||
use Objects\User;
|
||||
|
||||
namespace Documents\Account {
|
||||
|
||||
use Elements\Head;
|
||||
use Elements\Link;
|
||||
use Elements\Script;
|
||||
use Elements\SimpleBody;
|
||||
|
||||
class AccountHead extends Head {
|
||||
|
||||
public function __construct($document) {
|
||||
parent::__construct($document);
|
||||
}
|
||||
|
||||
protected function initSources() {
|
||||
$this->loadJQuery();
|
||||
$this->addJS(Script::CORE);
|
||||
$this->addJS(Script::ACCOUNT);
|
||||
$this->loadBootstrap();
|
||||
$this->loadFontawesome();
|
||||
$this->addCSS(Link::CORE);
|
||||
}
|
||||
|
||||
protected function initMetas(): array {
|
||||
return array(
|
||||
array('name' => 'viewport', 'content' => 'width=device-width, initial-scale=1.0'),
|
||||
array('name' => 'format-detection', 'content' => 'telephone=yes'),
|
||||
array('charset' => 'utf-8'),
|
||||
array("http-equiv" => 'expires', 'content' => '0'),
|
||||
array("name" => 'robots', 'content' => 'noarchive'),
|
||||
);
|
||||
}
|
||||
|
||||
protected function initRawFields(): array {
|
||||
return array();
|
||||
}
|
||||
|
||||
protected function initTitle(): string {
|
||||
return "Account";
|
||||
}
|
||||
class Account extends TemplateDocument {
|
||||
public function __construct(User $user, ?string $template) {
|
||||
parent::__construct($user, $template);
|
||||
$this->enableCSP();
|
||||
}
|
||||
|
||||
class AccountBody extends SimpleBody {
|
||||
private function createError(string $message) {
|
||||
$this->parameters["view"]["success"] = false;
|
||||
$this->parameters["view"]["message"] = $message;
|
||||
}
|
||||
|
||||
public function __construct($document) {
|
||||
parent::__construct($document);
|
||||
}
|
||||
|
||||
protected function getContent(): string {
|
||||
|
||||
$view = $this->getDocument()->getView();
|
||||
if ($view === null) {
|
||||
return "The page you does not exist or is no longer valid. <a href='/'>Return to start page</a>";
|
||||
protected function loadParameters() {
|
||||
$this->parameters["view"] = ["success" => true];
|
||||
if ($this->getTemplateName() === "account/reset_password.twig") {
|
||||
if (isset($_GET["token"]) && is_string($_GET["token"]) && !empty($_GET["token"])) {
|
||||
$this->parameters["view"]["token"] = $_GET["token"];
|
||||
$req = new \Api\User\CheckToken($this->getUser());
|
||||
$this->parameters["view"]["success"] = $req->execute(array("token" => $_GET["token"]));
|
||||
if ($this->parameters["view"]["success"]) {
|
||||
if (strcmp($req->getResult()["token"]["type"], "password_reset") !== 0) {
|
||||
$this->createError("The given token has a wrong type.");
|
||||
}
|
||||
} else {
|
||||
$this->createError("Error requesting password reset: " . $req->getLastError());
|
||||
}
|
||||
}
|
||||
} else if ($this->getTemplateName() === "account/register.twig") {
|
||||
$settings = $this->user->getConfiguration()->getSettings();
|
||||
if ($this->user->isLoggedIn()) {
|
||||
$this->createError("You are already logged in.");
|
||||
} else if (!$settings->isRegistrationAllowed()) {
|
||||
$this->createError("Registration is not enabled on this website.");
|
||||
}
|
||||
} else if ($this->getTemplateName() === "account/accept_invite.twig") {
|
||||
if (isset($_GET["token"]) && is_string($_GET["token"]) && !empty($_GET["token"])) {
|
||||
$this->parameters["view"]["token"] = $_GET["token"];
|
||||
$req = new \Api\User\CheckToken($this->getUser());
|
||||
$this->parameters["view"]["success"] = $req->execute(array("token" => $_GET["token"]));
|
||||
if ($this->parameters["view"]["success"]) {
|
||||
if (strcmp($req->getResult()["token"]["type"], "invite") !== 0) {
|
||||
$this->createError("The given token has a wrong type.");
|
||||
} else {
|
||||
$this->parameters["view"]["invited_user"] = $req->getResult()["user"];
|
||||
}
|
||||
} else {
|
||||
$this->createError("Error confirming e-mail address: " . $req->getLastError());
|
||||
}
|
||||
} else {
|
||||
$this->createError("The link you visited is no longer valid");
|
||||
}
|
||||
|
||||
return $view->getCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,51 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace Documents {
|
||||
namespace Documents;
|
||||
|
||||
use Documents\Admin\AdminHead;
|
||||
use Elements\Document;
|
||||
use Objects\User;
|
||||
use Views\Admin\AdminDashboardBody;
|
||||
use Views\Admin\LoginBody;
|
||||
use Elements\TemplateDocument;
|
||||
use Objects\User;
|
||||
|
||||
class Admin extends Document {
|
||||
public function __construct(User $user, ?string $view = NULL) {
|
||||
$body = $user->isLoggedIn() ? AdminDashboardBody::class : LoginBody::class;
|
||||
parent::__construct($user, AdminHead::class, $body, $view);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace Documents\Admin {
|
||||
|
||||
use Elements\Head;
|
||||
|
||||
class AdminHead extends Head {
|
||||
|
||||
public function __construct($document) {
|
||||
parent::__construct($document);
|
||||
}
|
||||
|
||||
protected function initSources() {
|
||||
$this->loadFontawesome();
|
||||
}
|
||||
|
||||
protected function initMetas(): array {
|
||||
return array(
|
||||
array('name' => 'viewport', 'content' => 'width=device-width, initial-scale=1.0'),
|
||||
array('name' => 'format-detection', 'content' => 'telephone=yes'),
|
||||
array('charset' => 'utf-8'),
|
||||
array("http-equiv" => 'expires', 'content' => '0'),
|
||||
array("name" => 'robots', 'content' => 'noarchive'),
|
||||
);
|
||||
}
|
||||
|
||||
protected function initRawFields(): array {
|
||||
return array();
|
||||
}
|
||||
|
||||
protected function initTitle(): string {
|
||||
return $this->getSiteName() . " - Administration";
|
||||
}
|
||||
class Admin extends TemplateDocument {
|
||||
public function __construct(User $user) {
|
||||
$template = $user->isLoggedIn() ? "admin.twig" : "redirect.twig";
|
||||
$params = $user->isLoggedIn() ? [] : ["url" => "/login"];
|
||||
parent::__construct($user, $template, $params);
|
||||
$this->enableCSP();
|
||||
}
|
||||
}
|
||||
@@ -1,64 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Documents {
|
||||
namespace Documents;
|
||||
|
||||
use Documents\Document404\Body404;
|
||||
use Documents\Document404\Head404;
|
||||
use Elements\Document;
|
||||
use Elements\TemplateDocument;
|
||||
use Objects\User;
|
||||
|
||||
class Document404 extends Document {
|
||||
public function __construct($user, ?string $view = NULL) {
|
||||
parent::__construct($user, Head404::class, Body404::class, $view);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace Documents\Document404 {
|
||||
|
||||
use Elements\Head;
|
||||
use Elements\SimpleBody;
|
||||
use Views\View404;
|
||||
|
||||
class Head404 extends Head {
|
||||
|
||||
public function __construct($document) {
|
||||
parent::__construct($document);
|
||||
}
|
||||
|
||||
protected function initSources() {
|
||||
}
|
||||
|
||||
protected function initMetas(): array {
|
||||
return array(
|
||||
array('name' => 'viewport', 'content' => 'width=device-width, initial-scale=1.0'),
|
||||
array('name' => 'format-detection', 'content' => 'telephone=yes'),
|
||||
array('charset' => 'utf-8'),
|
||||
array("http-equiv" => 'expires', 'content' => '0'),
|
||||
array("name" => 'robots', 'content' => 'noarchive'),
|
||||
);
|
||||
}
|
||||
|
||||
protected function initRawFields(): array {
|
||||
return array();
|
||||
}
|
||||
|
||||
protected function initTitle(): string {
|
||||
return "WebBase - Not Found";
|
||||
}
|
||||
}
|
||||
|
||||
class Body404 extends SimpleBody {
|
||||
|
||||
public function __construct($document) {
|
||||
parent::__construct($document);
|
||||
}
|
||||
|
||||
public function loadView() {
|
||||
http_response_code(404);
|
||||
}
|
||||
|
||||
protected function getContent(): string {
|
||||
return $this->load(View404::class);
|
||||
}
|
||||
class Document404 extends TemplateDocument {
|
||||
|
||||
public function __construct(User $user) {
|
||||
parent::__construct($user, "404.twig");
|
||||
}
|
||||
|
||||
public function loadParameters() {
|
||||
parent::loadParameters();
|
||||
http_response_code(404);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,9 +4,9 @@ namespace Documents {
|
||||
|
||||
use Documents\Install\InstallBody;
|
||||
use Documents\Install\InstallHead;
|
||||
use Elements\Document;
|
||||
use Elements\HtmlDocument;
|
||||
|
||||
class Install extends Document {
|
||||
class Install extends HtmlDocument {
|
||||
public function __construct($user) {
|
||||
parent::__construct($user, InstallHead::class, InstallBody::class);
|
||||
$this->databaseRequired = false;
|
||||
|
||||
Reference in New Issue
Block a user