Password Reset + Bugfixes
This commit is contained in:
@@ -7,15 +7,83 @@ namespace Views\Account;
|
||||
use Elements\Document;
|
||||
use Elements\View;
|
||||
|
||||
class AcceptInvite extends View {
|
||||
class AcceptInvite extends AccountView {
|
||||
|
||||
private bool $success;
|
||||
private string $message;
|
||||
private array $invitedUser;
|
||||
|
||||
public function __construct(Document $document, $loadView = true) {
|
||||
parent::__construct($document, $loadView);
|
||||
$this->title = "Invitation";
|
||||
$this->description = "Finnish your account registration by choosing a password.";
|
||||
$this->icon = "user-check";
|
||||
$this->success = false;
|
||||
$this->message = "No content";
|
||||
$this->invitedUser = array();
|
||||
}
|
||||
|
||||
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\CheckToken($this->getDocument()->getUser());
|
||||
$this->success = $req->execute(array("token" => $_GET["token"]));
|
||||
if ($this->success) {
|
||||
if (strcmp($req->getResult()["token"]["type"], "invite") !== 0) {
|
||||
$this->success = false;
|
||||
$this->message = "The given token has a wrong type.";
|
||||
} else {
|
||||
$this->invitedUser = $req->getResult()["user"];
|
||||
}
|
||||
} 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->createErrorText($this->message);
|
||||
}
|
||||
|
||||
$token = htmlspecialchars($_GET["token"], ENT_QUOTES);
|
||||
$username = $this->invitedUser["name"];
|
||||
$emailAddress = $this->invitedUser["email"];
|
||||
|
||||
return "<h4 class=\"pb-4\">Please fill with your details</h4>
|
||||
<form>
|
||||
<input name='token' id='token' type='hidden' value='$token'/>
|
||||
<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\" value='$username' disabled>
|
||||
</div>
|
||||
<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\" value='$emailAddress' disabled>
|
||||
</div>
|
||||
<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=\"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=\"input-group mt-3\">
|
||||
<button type=\"button\" class=\"btn btn-success\" id='btnAcceptInvite'>Submit</button>
|
||||
</div>
|
||||
</form>";
|
||||
}
|
||||
}
|
||||
@@ -3,9 +3,7 @@
|
||||
|
||||
namespace Views\Account;
|
||||
|
||||
|
||||
use Elements\Document;
|
||||
use Elements\View;
|
||||
|
||||
class Register extends AccountView {
|
||||
|
||||
|
||||
@@ -5,17 +5,83 @@ namespace Views\Account;
|
||||
|
||||
|
||||
use Elements\Document;
|
||||
use Elements\View;
|
||||
|
||||
class ResetPassword extends View {
|
||||
class ResetPassword extends AccountView {
|
||||
|
||||
private bool $success;
|
||||
private string $message;
|
||||
private ?string $token;
|
||||
|
||||
public function __construct(Document $document, $loadView = true) {
|
||||
parent::__construct($document, $loadView);
|
||||
$this->title = "Reset Password";
|
||||
$this->description = "Request a password reset, once you got the e-mail address, you can choose a new password";
|
||||
$this->icon = "user-lock";
|
||||
$this->success = true;
|
||||
$this->message = "";
|
||||
$this->token = NULL;
|
||||
}
|
||||
|
||||
public function getCode() {
|
||||
$html = parent::getCode();
|
||||
public function loadView() {
|
||||
parent::loadView();
|
||||
|
||||
return $html;
|
||||
if (isset($_GET["token"]) && is_string($_GET["token"]) && !empty($_GET["token"])) {
|
||||
$this->token = $_GET["token"];
|
||||
$req = new \Api\User\CheckToken($this->getDocument()->getUser());
|
||||
$this->success = $req->execute(array("token" => $_GET["token"]));
|
||||
if ($this->success) {
|
||||
if (strcmp($req->getResult()["token"]["type"], "password_reset") !== 0) {
|
||||
$this->success = false;
|
||||
$this->message = "The given token has a wrong type.";
|
||||
}
|
||||
} else {
|
||||
$this->message = "Error requesting password reset: " . $req->getLastError();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function getAccountContent() {
|
||||
if (!$this->success) {
|
||||
$html = $this->createErrorText($this->message);
|
||||
if ($this->token !== null) {
|
||||
$html .= "<a href='/resetPassword' class='btn btn-primary'>Go back</a>";
|
||||
}
|
||||
return $html;
|
||||
}
|
||||
|
||||
if ($this->token === null) {
|
||||
return "<p class='lead'>Enter your E-Mail address, to receive a password reset token.</p>
|
||||
<form>
|
||||
<div class=\"input-group\">
|
||||
<div class=\"input-group-append\">
|
||||
<span class=\"input-group-text\"><i class=\"fas fa-at\"></i></span>
|
||||
</div>
|
||||
<input id=\"email\" name=\"email\" placeholder=\"E-Mail address\" class=\"form-control\" type=\"email\" maxlength=\"64\" />
|
||||
</div>
|
||||
<div class=\"input-group mt-2\">
|
||||
<button id='btnRequestPasswordReset' class='btn btn-primary'>Request</button>
|
||||
</div>
|
||||
";
|
||||
} else {
|
||||
return "<h4 class=\"pb-4\">Choose a new password</h4>
|
||||
<form>
|
||||
<input name='token' id='token' type='hidden' value='$this->token'/>
|
||||
<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=\"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=\"input-group mt-3\">
|
||||
<button type=\"button\" class=\"btn btn-success\" id='btnResetPassword'>Submit</button>
|
||||
</div>
|
||||
</form>";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user