Localization & stuff
This commit is contained in:
@@ -4,12 +4,14 @@
|
||||
namespace Core\Documents;
|
||||
|
||||
use Core\Elements\TemplateDocument;
|
||||
use Core\Objects\DatabaseEntity\UserToken;
|
||||
use Core\Objects\Router\Router;
|
||||
|
||||
|
||||
class Account extends TemplateDocument {
|
||||
public function __construct(Router $router, string $templateName) {
|
||||
parent::__construct($router, $templateName);
|
||||
$this->languageModules = ["general", "account"];
|
||||
$this->title = "Account";
|
||||
$this->searchable = false;
|
||||
$this->enableCSP();
|
||||
@@ -21,47 +23,67 @@ class Account extends TemplateDocument {
|
||||
}
|
||||
|
||||
protected function loadParameters() {
|
||||
$settings = $this->getSettings();
|
||||
$templateName = $this->getTemplateName();
|
||||
$language = $this->getContext()->getLanguage();
|
||||
$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 \Core\API\User\CheckToken($this->getContext());
|
||||
$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->getSettings();
|
||||
if ($this->getUser()) {
|
||||
$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/login.twig" && $this->getUser()) {
|
||||
header("Location: /admin");
|
||||
exit();
|
||||
} 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 \Core\API\User\CheckToken($this->getContext());
|
||||
$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.");
|
||||
switch ($templateName) {
|
||||
|
||||
case "account/reset_password.twig": {
|
||||
if (isset($_GET["token"]) && is_string($_GET["token"]) && !empty($_GET["token"])) {
|
||||
$this->parameters["view"]["token"] = $_GET["token"];
|
||||
$req = new \Core\API\User\CheckToken($this->getContext());
|
||||
$this->parameters["view"]["success"] = $req->execute(array("token" => $_GET["token"]));
|
||||
if ($this->parameters["view"]["success"]) {
|
||||
if (strcmp($req->getToken()->getType(), UserToken::TYPE_PASSWORD_RESET) !== 0) {
|
||||
$this->createError("The given token has a wrong type.");
|
||||
}
|
||||
} else {
|
||||
$this->parameters["view"]["invited_user"] = $req->getResult()["user"];
|
||||
$this->createError("Error requesting password reset: " . $req->getLastError());
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case "account/register.twig": {
|
||||
if ($this->getUser()) {
|
||||
$this->createError("You are already logged in.");
|
||||
} else if (!$settings->isRegistrationAllowed()) {
|
||||
$this->createError("Registration is not enabled on this website.");
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case "account/login.twig": {
|
||||
if ($this->getUser()) {
|
||||
header("Location: /admin");
|
||||
exit();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case "account/accept_invite.twig": {
|
||||
if (isset($_GET["token"]) && is_string($_GET["token"]) && !empty($_GET["token"])) {
|
||||
$this->parameters["view"]["token"] = $_GET["token"];
|
||||
$req = new \Core\API\User\CheckToken($this->getContext());
|
||||
$this->parameters["view"]["success"] = $req->execute(array("token" => $_GET["token"]));
|
||||
if ($this->parameters["view"]["success"]) {
|
||||
if (strcmp($req->getToken()->getType(), UserToken::TYPE_INVITE) !== 0) {
|
||||
$this->createError("The given token has a wrong type.");
|
||||
} else {
|
||||
$this->parameters["view"]["invited_user"] = $req->getToken()->getUser()->jsonSerialize();
|
||||
}
|
||||
} else {
|
||||
$this->createError("Error confirming e-mail address: " . $req->getLastError());
|
||||
}
|
||||
} else {
|
||||
$this->createError("Error confirming e-mail address: " . $req->getLastError());
|
||||
$this->createError("The link you visited is no longer valid");
|
||||
}
|
||||
} else {
|
||||
$this->createError("The link you visited is no longer valid");
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ namespace Core\Documents;
|
||||
use Core\Elements\EmptyHead;
|
||||
use Core\Elements\HtmlDocument;
|
||||
use Core\Elements\SimpleBody;
|
||||
use Core\Objects\DatabaseEntity\Group;
|
||||
use Core\Objects\Router\Router;
|
||||
|
||||
class Info extends HtmlDocument {
|
||||
@@ -16,7 +17,7 @@ class Info extends HtmlDocument {
|
||||
|
||||
class InfoBody extends SimpleBody {
|
||||
protected function getContent(): string {
|
||||
$user = $this->getDocument()->getUser();
|
||||
$user = $this->getContext()->getUser();
|
||||
if ($user && $user->hasGroup(Group::ADMIN)) {
|
||||
phpinfo();
|
||||
return "";
|
||||
|
||||
Reference in New Issue
Block a user