Routing Fix + E-Mail Confirm frontend

This commit is contained in:
Roman Hergenreder 2020-07-01 23:07:00 +02:00
parent 86f9e12b87
commit db63b55a70
6 changed files with 73 additions and 22 deletions

@ -2,7 +2,6 @@
namespace Api;
use Driver\SQL\Condition\Compare;
use Driver\SQL\Condition\CondBool;
class Stats extends Request {

@ -544,8 +544,9 @@ namespace Api\User {
$this->success = $req->execute(array("token" => $token));
$this->lastError = $req->getLastError();
if ($this->success) {
$result = $req->getResult();
if (strcasecmp($result["token"]["type"], "invite") !== 0) {
if (strcasecmp($result["token"]["type"], "email_confirm") !== 0) {
return $this->createError("Invalid token type");
} else if($result["user"]["confirmed"]) {
return $this->createError("Your email address is already confirmed.");
@ -556,6 +557,9 @@ namespace Api\User {
return true;
}
}
return $this->success;
}
}
class Login extends UserAPI {

@ -8,17 +8,19 @@ use Elements\View;
abstract class AccountView extends View {
protected string $description;
protected string $icon;
public function __construct(Document $document, $loadView = true) {
parent::__construct($document, $loadView);
$this->description = "";
$this->icon = "image";
}
public function getCode() {
$html = parent::getCode();
$content = $this->getAccountContent();
$icon = $this->createIcon("user-plus", "fas", "fa-3x");
$icon = $this->createIcon($this->icon, "fas", "fa-3x");
$html .= "<div class=\"container mt-5\">
<div class=\"row\">

@ -5,17 +5,42 @@ namespace Views\Account;
use Elements\Document;
use Elements\View;
class ConfirmEmail extends View {
class ConfirmEmail extends AccountView {
private bool $success;
private string $message;
public function __construct(Document $document, $loadView = true) {
parent::__construct($document, $loadView);
$this->title = "Confirm Email";
$this->icon = "user-check";
$this->success = false;
$this->message = "No content";
}
public function getCode() {
$html = parent::getCode();
public function loadView() {
parent::loadView();
return $html;
if (isset($_GET["token"]) && is_string($_GET["token"]) && !empty($_GET["token"])) {
$req = new \Api\User\ConfirmEmail($this->getDocument()->getUser());
$this->success = $req->execute(array("token" => $_GET["token"]));
if ($this->success) {
$this->message = "Your e-mail address was successfully confirmed, you may now log in";
} else {
$this->message = "Error confirming e-mail address: " . $req->getLastError();
}
} else {
$this->success = false;
$this->message = "The link you visited is no longer valid";
}
}
protected function getAccountContent() {
if ($this->success) {
return $this->createSuccessText($this->message);
} else {
return $this->createErrorText($this->message);
}
}
}

@ -13,6 +13,7 @@ class Register extends AccountView {
parent::__construct($document, $loadView);
$this->title = "Registration";
$this->description = "Create a new account";
$this->icon = "user-plus";
}
public function loadView() {
@ -37,19 +38,31 @@ class Register extends AccountView {
return "<h4 class=\"pb-4\">Please fill with your details</h4>
<form>
<div class=\"form-group\">
<div class=\"input-group\">
<div class=\"input-group-append\">
<span class=\"input-group-text\"><i class=\"fas fa-hashtag\"></i></span>
</div>
<input id=\"username\" name=\"username\" placeholder=\"Username\" class=\"form-control\" type=\"text\" maxlength=\"32\">
</div>
<div class=\"form-group\">
<div class=\"input-group mt-3\">
<div class=\"input-group-append\">
<span class=\"input-group-text\"><i class=\"fas fa-at\"></i></span>
</div>
<input type=\"email\" name='email' id='email' class=\"form-control\" placeholder=\"Email\" maxlength=\"64\">
</div>
<div class=\"form-group\">
<div class=\"input-group mt-3\">
<div class=\"input-group-append\">
<span class=\"input-group-text\"><i class=\"fas fa-key\"></i></span>
</div>
<input type=\"password\" name='password' id='password' class=\"form-control\" placeholder=\"Password\">
</div>
<div class=\"form-group\">
<div class=\"input-group mt-3\">
<div class=\"input-group-append\">
<span class=\"input-group-text\"><i class=\"fas fa-key\"></i></span>
</div>
<input type=\"password\" name='confirmPassword' id='confirmPassword' class=\"form-control\" placeholder=\"Confirm Password\">
</div>
<div class=\"form-group\">
<div class=\"input-group mt-3\">
<button type=\"button\" class=\"btn btn-success\" id='btnRegister'>Submit</button>
</div>
</form>";

@ -77,6 +77,14 @@ if(isset($_GET["api"]) && is_string($_GET["api"])) {
}
} else {
$requestedUri = $_GET["site"] ?? $_SERVER["REQUEST_URI"];
if (($index = strpos($requestedUri, "?")) !== false) {
$requestedUri = substr($requestedUri, 0, $index);
}
if (($index = strpos($requestedUri, "#")) !== false) {
$requestedUri = substr($requestedUri, 0, $index);
}
if (startsWith($requestedUri, "/")) {
$requestedUri = substr($requestedUri, 1);
}