From b16682d37c9abe8c97c94363d540425272416050 Mon Sep 17 00:00:00 2001 From: Carl Bennett Date: Sat, 14 Dec 2024 01:30:09 -0600 Subject: [PATCH] Refactor ERROR_INTERNAL/ACL_NOT_SET/NOT_LOGGED_IN --- src/Controllers/Document/View.php | 4 +++- src/Controllers/EventLog/Index.php | 4 +++- src/Controllers/EventLog/View.php | 4 +++- src/Controllers/Packet/View.php | 4 +++- src/Controllers/Server/Create.php | 4 +--- src/Controllers/Server/Delete.php | 14 +++++++------ src/Controllers/Server/Edit.php | 6 +++--- src/Controllers/User/ResetPassword.php | 28 ++++++++++++------------- src/Models/Comment/Create.php | 3 --- src/Models/Comment/Delete.php | 3 --- src/Models/Comment/Edit.php | 3 --- src/Models/Core/AccessControl.php | 3 +++ src/Models/Core/Errorable.php | 2 ++ src/Models/Document/Create.php | 3 --- src/Models/Document/Delete.php | 3 --- src/Models/Document/Edit.php | 3 --- src/Models/News/Create.php | 3 --- src/Models/News/Delete.php | 3 --- src/Models/News/Edit.php | 3 --- src/Models/Packet/Delete.php | 3 --- src/Models/Packet/Form.php | 3 --- src/Models/Packet/View.php | 2 ++ src/Models/Server/Delete.php | 18 ---------------- src/Models/Server/Form.php | 6 +++--- src/Models/User/ChangePassword.php | 2 -- src/Models/User/Delete.php | 3 --- src/Models/User/Login.php | 1 - src/Models/User/Register.php | 1 - src/Models/User/ResetPassword.php | 22 +++++++++---------- src/Models/User/Verify.php | 1 - src/Templates/Server/Delete.phtml | 14 ++++++------- src/Templates/Server/Form.phtml | 16 +++++++------- src/Templates/User/ResetPassword.phtml | 29 +++++++++++++------------- src/Views/Server/DeleteHtml.php | 2 +- 34 files changed, 88 insertions(+), 135 deletions(-) delete mode 100644 src/Models/Server/Delete.php diff --git a/src/Controllers/Document/View.php b/src/Controllers/Document/View.php index 63ef3aa0..d7ffbf8d 100644 --- a/src/Controllers/Document/View.php +++ b/src/Controllers/Document/View.php @@ -4,6 +4,7 @@ use \BNETDocs\Libraries\Comment; use \BNETDocs\Libraries\Core\HttpCode; +use \BNETDocs\Models\Document\View as ViewModel; class View extends \BNETDocs\Controllers\Base { @@ -12,7 +13,7 @@ class View extends \BNETDocs\Controllers\Base */ public function __construct() { - $this->model = new \BNETDocs\Models\Document\View(); + $this->model = new ViewModel(); } /** @@ -32,6 +33,7 @@ public function invoke(?array $args): bool && !($this->model->active_user && $this->model->active_user->isStaff())) { $this->model->_responseCode = HttpCode::HTTP_FORBIDDEN; + $this->model->error = $this->model->active_user ? ViewModel::ERROR_ACL_NOT_SET : ViewModel::ERROR_NOT_LOGGED_IN; $this->model->document = null; return true; } diff --git a/src/Controllers/EventLog/Index.php b/src/Controllers/EventLog/Index.php index 05d1d269..a3f8fd67 100644 --- a/src/Controllers/EventLog/Index.php +++ b/src/Controllers/EventLog/Index.php @@ -4,6 +4,7 @@ use \BNETDocs\Libraries\Core\HttpCode; use \BNETDocs\Libraries\EventLog\Event; +use \BNETDocs\Models\EventLog\Index as IndexModel; class Index extends \BNETDocs\Controllers\Base { @@ -13,7 +14,7 @@ class Index extends \BNETDocs\Controllers\Base public function __construct() { - $this->model = new \BNETDocs\Models\EventLog\Index(); + $this->model = new IndexModel(); } public function invoke(?array $args): bool @@ -24,6 +25,7 @@ public function invoke(?array $args): bool if (!$this->model->acl_allowed) { $this->model->_responseCode = HttpCode::HTTP_FORBIDDEN; + $this->model->error = $this->model->active_user ? IndexModel::ERROR_ACL_NOT_SET : IndexModel::ERROR_NOT_LOGGED_IN; return true; } diff --git a/src/Controllers/EventLog/View.php b/src/Controllers/EventLog/View.php index 03b81697..d0eb969f 100644 --- a/src/Controllers/EventLog/View.php +++ b/src/Controllers/EventLog/View.php @@ -3,12 +3,13 @@ namespace BNETDocs\Controllers\EventLog; use \BNETDocs\Libraries\Core\HttpCode; +use \BNETDocs\Models\EventLog\View as ViewModel; class View extends \BNETDocs\Controllers\Base { public function __construct() { - $this->model = new \BNETDocs\Models\EventLog\View(); + $this->model = new ViewModel(); } public function invoke(?array $args): bool @@ -19,6 +20,7 @@ public function invoke(?array $args): bool if (!$this->model->acl_allowed) { $this->model->_responseCode = HttpCode::HTTP_FORBIDDEN; + $this->model->error = $this->model->active_user ? ViewModel::ERROR_ACL_NOT_SET : ViewModel::ERROR_NOT_LOGGED_IN; return true; } diff --git a/src/Controllers/Packet/View.php b/src/Controllers/Packet/View.php index 9c4a9eef..be0c002f 100644 --- a/src/Controllers/Packet/View.php +++ b/src/Controllers/Packet/View.php @@ -3,12 +3,13 @@ use \BNETDocs\Libraries\Comment; use \BNETDocs\Libraries\Core\HttpCode; +use BNETDocs\Models\Packet\View as ViewModel; class View extends \BNETDocs\Controllers\Base { public function __construct() { - $this->model = new \BNETDocs\Models\Packet\View(); + $this->model = new ViewModel(); } public function invoke(?array $args): bool @@ -21,6 +22,7 @@ public function invoke(?array $args): bool if (!$this->model->packet) { $this->model->_responseCode = HttpCode::HTTP_NOT_FOUND; + $this->model->error = ViewModel::ERROR_NOT_FOUND; return true; } diff --git a/src/Controllers/Server/Create.php b/src/Controllers/Server/Create.php index 0c8f5f1f..5b9e62a9 100644 --- a/src/Controllers/Server/Create.php +++ b/src/Controllers/Server/Create.php @@ -21,12 +21,10 @@ public function __construct() public function invoke(?array $args): bool { - $this->model->server_edit = false; - if (!($this->model->active_user && $this->model->active_user->getOption(\BNETDocs\Libraries\User\User::OPTION_ACL_SERVER_CREATE))) { $this->model->_responseCode = HttpCode::HTTP_FORBIDDEN; - $this->model->error = FormModel::ERROR_ACCESS_DENIED; + $this->model->error = $this->model->active_user ? FormModel::ERROR_ACL_NOT_SET : FormModel::ERROR_NOT_LOGGED_IN; return true; } diff --git a/src/Controllers/Server/Delete.php b/src/Controllers/Server/Delete.php index bb9299dc..97eda27c 100644 --- a/src/Controllers/Server/Delete.php +++ b/src/Controllers/Server/Delete.php @@ -5,7 +5,7 @@ use \BNETDocs\Libraries\Core\HttpCode; use \BNETDocs\Libraries\Core\Router; use \BNETDocs\Libraries\EventLog\Logger; -use \BNETDocs\Models\Server\Delete as DeleteModel; +use \BNETDocs\Models\Server\Form as FormModel; class Delete extends \BNETDocs\Controllers\Base { @@ -15,15 +15,17 @@ class Delete extends \BNETDocs\Controllers\Base public function __construct() { - $this->model = new DeleteModel(); + $this->model = new FormModel(); } public function invoke(?array $args): bool { + $this->model->server_delete = true; + if (!($this->model->active_user && $this->model->active_user->getOption(\BNETDocs\Libraries\User\User::OPTION_ACL_SERVER_DELETE))) { $this->model->_responseCode = HttpCode::HTTP_FORBIDDEN; - $this->model->error = $this->model->active_user ? DeleteModel::ERROR_ACL_NOT_SET : DeleteModel::ERROR_NOT_LOGGED_IN; + $this->model->error = $this->model->active_user ? FormModel::ERROR_ACL_NOT_SET : FormModel::ERROR_NOT_LOGGED_IN; return true; } @@ -31,7 +33,7 @@ public function invoke(?array $args): bool if (!is_numeric($id)) { $this->model->_responseCode = HttpCode::HTTP_BAD_REQUEST; - $this->model->error = DeleteModel::ERROR_NOT_FOUND; + $this->model->error = FormModel::ERROR_NOT_FOUND; return true; } $id = (int) $id; @@ -42,7 +44,7 @@ public function invoke(?array $args): bool if (!$this->model->server) { $this->model->_responseCode = HttpCode::HTTP_NOT_FOUND; - $this->model->error = DeleteModel::ERROR_NOT_FOUND; + $this->model->error = FormModel::ERROR_NOT_FOUND; return true; } @@ -53,7 +55,7 @@ public function invoke(?array $args): bool protected function handlePost(): void { - $this->model->error = $this->model->server->deallocate() ? false : DeleteModel::ERROR_INTERNAL; + $this->model->error = $this->model->server->deallocate() ? false : FormModel::ERROR_INTERNAL; if ($this->model->error === false) { $event = Logger::initEvent( diff --git a/src/Controllers/Server/Edit.php b/src/Controllers/Server/Edit.php index 09ad9698..a672c8ee 100644 --- a/src/Controllers/Server/Edit.php +++ b/src/Controllers/Server/Edit.php @@ -26,7 +26,7 @@ public function invoke(?array $args): bool if (!($this->model->active_user && $this->model->active_user->getOption(\BNETDocs\Libraries\User\User::OPTION_ACL_SERVER_MODIFY))) { $this->model->_responseCode = HttpCode::HTTP_FORBIDDEN; - $this->model->error = FormModel::ERROR_ACCESS_DENIED; + $this->model->error = $this->model->active_user ? FormModel::ERROR_ACL_NOT_SET : FormModel::ERROR_NOT_LOGGED_IN; return true; } @@ -74,9 +74,9 @@ protected function handlePost(): void $this->model->server->setDisabled((bool) ($this->model->form_fields['disabled'] ?? null)); $this->model->server->setOnline((bool) ($this->model->form_fields['online'] ?? null)); - $this->model->error = $this->model->server->commit() ? FormModel::ERROR_SUCCESS : FormModel::ERROR_INTERNAL; + $this->model->error = $this->model->server->commit() ? false : FormModel::ERROR_INTERNAL; - if ($this->model->error === FormModel::ERROR_SUCCESS) + if ($this->model->error === false) { $event = Logger::initEvent( \BNETDocs\Libraries\EventLog\EventTypes::SERVER_EDITED, diff --git a/src/Controllers/User/ResetPassword.php b/src/Controllers/User/ResetPassword.php index c9370ae2..841dd3cb 100644 --- a/src/Controllers/User/ResetPassword.php +++ b/src/Controllers/User/ResetPassword.php @@ -56,7 +56,7 @@ public function invoke(?array $args): bool protected function doPasswordReset(): mixed { - if (empty($this->model->email)) return ResetPasswordModel::E_EMPTY_EMAIL; + if (empty($this->model->email)) return ResetPasswordModel::ERROR_EMPTY_EMAIL; try { @@ -65,10 +65,10 @@ protected function doPasswordReset(): mixed } catch (UnexpectedValueException) { - return ResetPasswordModel::E_BAD_EMAIL; + return ResetPasswordModel::ERROR_BAD_EMAIL; } - if (!$this->model->user) return ResetPasswordModel::E_USER_NOT_FOUND; + if (!$this->model->user) return ResetPasswordModel::ERROR_USER_NOT_FOUND; if (empty($this->model->token)) { @@ -79,35 +79,35 @@ protected function doPasswordReset(): mixed ) ); - return $this->model->user->commit() ? self::sendEmail() : ResetPasswordModel::E_INTERNAL_ERROR; + return $this->model->user->commit() ? self::sendEmail() : ResetPasswordModel::ERROR_INTERNAL; } if ($this->model->token !== $this->model->user->getVerifierToken()) - return ResetPasswordModel::E_BAD_TOKEN; + return ResetPasswordModel::ERROR_BAD_TOKEN; if ($this->model->pw1 !== $this->model->pw2) - return ResetPasswordModel::E_PASSWORD_MISMATCH; + return ResetPasswordModel::ERROR_PASSWORD_MISMATCH; $req = Config::get('bnetdocs.user_register_requirements') ?? []; $pwlen = strlen($this->model->pw1); if (is_numeric($req->password_length_max) && $pwlen > $req->password_length_max) - return ResetPasswordModel::E_PASSWORD_TOO_LONG; + return ResetPasswordModel::ERROR_PASSWORD_TOO_LONG; if (is_numeric($req->password_length_min) && $pwlen < $req->password_length_min) - return ResetPasswordModel::E_PASSWORD_TOO_SHORT; + return ResetPasswordModel::ERROR_PASSWORD_TOO_SHORT; if (!$req->password_allow_email && stripos($this->model->pw1, $this->model->user->getEmail())) - return ResetPasswordModel::E_PASSWORD_CONTAINS_EMAIL; + return ResetPasswordModel::ERROR_PASSWORD_CONTAINS_EMAIL; if (!$req->password_allow_username && stripos($this->model->pw1, $this->model->user->getUsername())) - return ResetPasswordModel::E_PASSWORD_CONTAINS_USERNAME; + return ResetPasswordModel::ERROR_PASSWORD_CONTAINS_USERNAME; - if ($this->model->user->isDisabled()) return ResetPasswordModel::E_USER_DISABLED; + if ($this->model->user->isDisabled()) return ResetPasswordModel::ERROR_USER_DISABLED; $this->model->user->setPassword($this->model->pw1); $this->model->user->setVerified(true); - return $this->model->user->commit() ? ResetPasswordModel::E_SUCCESS : ResetPasswordModel::E_INTERNAL_ERROR; + return $this->model->user->commit() ? false : ResetPasswordModel::ERROR_INTERNAL; } protected function sendEmail(): mixed @@ -186,9 +186,9 @@ protected function sendEmail(): mixed } catch (\PHPMailer\PHPMailer\Exception) { - return ResetPasswordModel::E_INTERNAL_ERROR; + return ResetPasswordModel::ERROR_INTERNAL; } - return ResetPasswordModel::E_SUCCESS; + return false; } } diff --git a/src/Models/Comment/Create.php b/src/Models/Comment/Create.php index c9060229..63d3c3ba 100644 --- a/src/Models/Comment/Create.php +++ b/src/Models/Comment/Create.php @@ -4,10 +4,7 @@ class Create extends \BNETDocs\Models\Core\AccessControl implements \JsonSerializable { - public const ERROR_ACL_NOT_SET = 'ACL_NOT_SET'; public const ERROR_EMPTY_CONTENT = 'EMPTY_CONTENT'; - public const ERROR_INTERNAL = 'INTERNAL_ERROR'; - public const ERROR_NOT_LOGGED_IN = 'NOT_LOGGED_IN'; public ?\BNETDocs\Libraries\Comment $comment = null; public ?string $origin = null; diff --git a/src/Models/Comment/Delete.php b/src/Models/Comment/Delete.php index 0e42caac..1aeaa78d 100644 --- a/src/Models/Comment/Delete.php +++ b/src/Models/Comment/Delete.php @@ -4,10 +4,7 @@ class Delete extends \BNETDocs\Models\Core\AccessControl implements \JsonSerializable { - public const ERROR_ACL_NOT_SET = 'ACL_NOT_SET'; - public const ERROR_INTERNAL = 'INTERNAL_ERROR'; public const ERROR_NOT_FOUND = 'NOT_FOUND'; - public const ERROR_NOT_LOGGED_IN = 'NOT_LOGGED_IN'; public ?\BNETDocs\Libraries\Comment $comment = null; public ?string $content = null; diff --git a/src/Models/Comment/Edit.php b/src/Models/Comment/Edit.php index da3a0125..c16bb71c 100644 --- a/src/Models/Comment/Edit.php +++ b/src/Models/Comment/Edit.php @@ -4,11 +4,8 @@ class Edit extends \BNETDocs\Models\Core\AccessControl implements \JsonSerializable { - public const ERROR_ACL_NOT_SET = 'ACL_NOT_SET'; public const ERROR_EMPTY_CONTENT = 'EMPTY_CONTENT'; - public const ERROR_INTERNAL = 'INTERNAL_ERROR'; public const ERROR_NOT_FOUND = 'NOT_FOUND'; - public const ERROR_NOT_LOGGED_IN = 'NOT_LOGGED_IN'; public ?\BNETDocs\Libraries\Comment $comment = null; public ?string $content = null; diff --git a/src/Models/Core/AccessControl.php b/src/Models/Core/AccessControl.php index 047f11c4..8b0ff2b5 100644 --- a/src/Models/Core/AccessControl.php +++ b/src/Models/Core/AccessControl.php @@ -4,6 +4,9 @@ class AccessControl extends \BNETDocs\Models\ActiveUser implements \JsonSerializable { + public const ERROR_ACL_NOT_SET = 'ACL_NOT_SET'; + public const ERROR_NOT_LOGGED_IN = 'NOT_LOGGED_IN'; + /** * Stores whether $this->active_user is permitted to access this controller. * diff --git a/src/Models/Core/Errorable.php b/src/Models/Core/Errorable.php index 7f7879f1..ff2aff48 100644 --- a/src/Models/Core/Errorable.php +++ b/src/Models/Core/Errorable.php @@ -4,6 +4,8 @@ class Errorable extends \BNETDocs\Models\Base implements \JsonSerializable { + public const ERROR_INTERNAL = 'INTERNAL_ERROR'; + /** * Stores error state information between Controller and downstream handlers, useful for Template rendering. * diff --git a/src/Models/Document/Create.php b/src/Models/Document/Create.php index d1d02c49..4aedcd96 100644 --- a/src/Models/Document/Create.php +++ b/src/Models/Document/Create.php @@ -4,11 +4,8 @@ class Create extends \BNETDocs\Models\Core\AccessControl implements \JsonSerializable { - public const ERROR_ACL_NOT_SET = 'ACL_NOT_SET'; public const ERROR_EMPTY_CONTENT = 'EMPTY_CONTENT'; public const ERROR_EMPTY_TITLE = 'EMPTY_TITLE'; - public const ERROR_INTERNAL = 'INTERNAL_ERROR'; - public const ERROR_NOT_LOGGED_IN = 'NOT_LOGGED_IN'; public ?string $brief = null; public ?string $content = null; diff --git a/src/Models/Document/Delete.php b/src/Models/Document/Delete.php index d69b3a59..eaad8b43 100644 --- a/src/Models/Document/Delete.php +++ b/src/Models/Document/Delete.php @@ -4,10 +4,7 @@ class Delete extends \BNETDocs\Models\Core\AccessControl implements \JsonSerializable { - public const ERROR_ACL_NOT_SET = 'ACL_NOT_SET'; - public const ERROR_INTERNAL = 'INTERNAL_ERROR'; public const ERROR_NOT_FOUND = 'NOT_FOUND'; - public const ERROR_NOT_LOGGED_IN = 'NOT_LOGGED_IN'; public ?\BNETDocs\Libraries\Document $document = null; public ?int $id = null; diff --git a/src/Models/Document/Edit.php b/src/Models/Document/Edit.php index 80592cc7..dcec9ac6 100644 --- a/src/Models/Document/Edit.php +++ b/src/Models/Document/Edit.php @@ -4,12 +4,9 @@ class Edit extends \BNETDocs\Models\Core\AccessControl implements \JsonSerializable { - public const ERROR_ACL_NOT_SET = 'ACL_NOT_SET'; public const ERROR_EMPTY_CONTENT = 'EMPTY_CONTENT'; public const ERROR_EMPTY_TITLE = 'EMPTY_TITLE'; - public const ERROR_INTERNAL = 'INTERNAL_ERROR'; public const ERROR_NOT_FOUND = 'NOT_FOUND'; - public const ERROR_NOT_LOGGED_IN = 'NOT_LOGGED_IN'; public ?string $brief = null; public ?string $category = null; diff --git a/src/Models/News/Create.php b/src/Models/News/Create.php index aecc6a8a..8f907771 100644 --- a/src/Models/News/Create.php +++ b/src/Models/News/Create.php @@ -4,11 +4,8 @@ class Create extends \BNETDocs\Models\Core\AccessControl implements \JsonSerializable { - public const ERROR_ACL_NOT_SET = 'ACL_NOT_SET'; public const ERROR_EMPTY_CONTENT = 'EMPTY_CONTENT'; public const ERROR_EMPTY_TITLE = 'EMPTY_TITLE'; - public const ERROR_INTERNAL = 'INTERNAL_ERROR'; - public const ERROR_NOT_LOGGED_IN = 'NOT_LOGGED_IN'; public ?int $category_id = null; public string $content = ''; diff --git a/src/Models/News/Delete.php b/src/Models/News/Delete.php index 69ced645..688bee2b 100644 --- a/src/Models/News/Delete.php +++ b/src/Models/News/Delete.php @@ -4,10 +4,7 @@ class Delete extends \BNETDocs\Models\Core\AccessControl implements \JsonSerializable { - public const ERROR_ACL_NOT_SET = 'ACL_NOT_SET'; - public const ERROR_INTERNAL = 'INTERNAL_ERROR'; public const ERROR_NOT_FOUND = 'NOT_FOUND'; - public const ERROR_NOT_LOGGED_IN = 'NOT_LOGGED_IN'; public ?int $id = null; public ?\BNETDocs\Libraries\News\Post $news_post = null; diff --git a/src/Models/News/Edit.php b/src/Models/News/Edit.php index 59b7eb9a..e470d4de 100644 --- a/src/Models/News/Edit.php +++ b/src/Models/News/Edit.php @@ -4,12 +4,9 @@ class Edit extends \BNETDocs\Models\Core\AccessControl implements \JsonSerializable { - public const ERROR_ACL_NOT_SET = 'ACL_NOT_SET'; public const ERROR_EMPTY_CONTENT = 'EMPTY_CONTENT'; public const ERROR_EMPTY_TITLE = 'EMPTY_TITLE'; - public const ERROR_INTERNAL = 'INTERNAL_ERROR'; public const ERROR_NOT_FOUND = 'NOT_FOUND'; - public const ERROR_NOT_LOGGED_IN = 'NOT_LOGGED_IN'; public ?int $category = null; public ?array $comments = null; diff --git a/src/Models/Packet/Delete.php b/src/Models/Packet/Delete.php index 848d8b50..f6d1671a 100644 --- a/src/Models/Packet/Delete.php +++ b/src/Models/Packet/Delete.php @@ -4,10 +4,7 @@ class Delete extends \BNETDocs\Models\Core\AccessControl implements \JsonSerializable { - public const ERROR_ACL_NOT_SET = 'ACL_NOT_SET'; - public const ERROR_INTERNAL = 'INTERNAL_ERROR'; public const ERROR_NOT_FOUND = 'NOT_FOUND'; - public const ERROR_NOT_LOGGED_IN = 'NOT_LOGGED_IN'; public ?string $label = null; public ?\BNETDocs\Libraries\Packet\Packet $packet = null; diff --git a/src/Models/Packet/Form.php b/src/Models/Packet/Form.php index 00be6bac..0524dcf3 100644 --- a/src/Models/Packet/Form.php +++ b/src/Models/Packet/Form.php @@ -5,10 +5,7 @@ class Form extends \BNETDocs\Models\Core\HttpForm implements \JsonSerializable { // possible values for $error: - public const ERROR_ACL_NOT_SET = 'ERROR_ACL_NOT_SET'; - public const ERROR_INTERNAL = 'INTERNAL'; public const ERROR_NOT_FOUND = 'NOT_FOUND'; - public const ERROR_NOT_LOGGED_IN = 'NOT_LOGGED_IN'; public const ERROR_OUTOFBOUNDS_APPLICATION_LAYER_ID = 'OUTOFBOUNDS_APPLICATION_LAYER_ID'; public const ERROR_OUTOFBOUNDS_BRIEF = 'OUTOFBOUNDS_BRIEF'; public const ERROR_OUTOFBOUNDS_DIRECTION = 'OUTOFBOUNDS_DIRECTION'; diff --git a/src/Models/Packet/View.php b/src/Models/Packet/View.php index a0ea4cda..4160583c 100644 --- a/src/Models/Packet/View.php +++ b/src/Models/Packet/View.php @@ -4,6 +4,8 @@ class View extends \BNETDocs\Models\ActiveUser implements \JsonSerializable { + public const ERROR_NOT_FOUND = 'NOT_FOUND'; + public ?array $comments = null; public ?\BNETDocs\Libraries\Packet\Packet $packet = null; public ?int $packet_id = null; diff --git a/src/Models/Server/Delete.php b/src/Models/Server/Delete.php deleted file mode 100644 index 1cf49631..00000000 --- a/src/Models/Server/Delete.php +++ /dev/null @@ -1,18 +0,0 @@ - $this->server]); - } -} diff --git a/src/Models/Server/Form.php b/src/Models/Server/Form.php index f3521423..d8068457 100644 --- a/src/Models/Server/Form.php +++ b/src/Models/Server/Form.php @@ -4,16 +4,15 @@ class Form extends \BNETDocs\Models\Core\HttpForm implements \JsonSerializable { - public const ERROR_ACCESS_DENIED = 'ACCESS_DENIED'; - public const ERROR_INTERNAL = 'INTERNAL_ERROR'; public const ERROR_INVALID_ADDRESS = 'INVALID_ADDRESS'; public const ERROR_INVALID_ID = 'INVALID_ID'; public const ERROR_INVALID_LABEL = 'INVALID_LABEL'; public const ERROR_INVALID_PORT = 'INVALID_PORT'; public const ERROR_INVALID_TYPE = 'INVALID_TYPE'; - public const ERROR_SUCCESS = 'SUCCESS'; + public const ERROR_NOT_FOUND = 'NOT_FOUND'; public ?\BNETDocs\Libraries\Server\Server $server = null; + public bool $server_delete = false; public bool $server_edit = false; public ?array $server_types = null; @@ -21,6 +20,7 @@ public function jsonSerialize(): mixed { return \array_merge(parent::jsonSerialize(), [ 'server' => $this->server, + 'server_delete' => $this->server_delete, 'server_edit' => $this->server_edit, 'server_types' => $this->server_types, ]); diff --git a/src/Models/User/ChangePassword.php b/src/Models/User/ChangePassword.php index 729bf992..dc721aec 100644 --- a/src/Models/User/ChangePassword.php +++ b/src/Models/User/ChangePassword.php @@ -4,9 +4,7 @@ class ChangePassword extends \BNETDocs\Models\ActiveUser implements \JsonSerializable { - public const ERROR_INTERNAL = 'INTERNAL_ERROR'; public const ERROR_NONMATCHING_PASSWORD = 'NONMATCHING_PASSWORD'; - public const ERROR_NOT_LOGGED_IN = 'NOT_LOGGED_IN'; public const ERROR_PASSWORD_CONTAINS_EMAIL = 'PASSWORD_CONTAINS_EMAIL'; public const ERROR_PASSWORD_CONTAINS_USERNAME = 'PASSWORD_CONTAINS_USERNAME'; public const ERROR_PASSWORD_DENYLIST = 'PASSWORD_DENYLIST'; diff --git a/src/Models/User/Delete.php b/src/Models/User/Delete.php index f4d1af1e..d14d85be 100644 --- a/src/Models/User/Delete.php +++ b/src/Models/User/Delete.php @@ -4,10 +4,7 @@ class Delete extends \BNETDocs\Models\Core\HttpForm implements \JsonSerializable { - public const ERROR_ACL_NOT_SET = 'ACL_NOT_SET'; - public const ERROR_INTERNAL_ERROR = 'INTERNAL_ERROR'; public const ERROR_NOT_FOUND = 'NOT_FOUND'; - public const ERROR_NOT_LOGGED_IN = 'NOT_LOGGED_IN'; public bool $deleted = false; public ?int $target_id = null; diff --git a/src/Models/User/Login.php b/src/Models/User/Login.php index b757399b..62031ee2 100644 --- a/src/Models/User/Login.php +++ b/src/Models/User/Login.php @@ -8,7 +8,6 @@ class Login extends \BNETDocs\Models\ActiveUser implements \JsonSerializable public const ERROR_EMPTY_EMAIL = 'EMPTY_EMAIL'; public const ERROR_EMPTY_PASSWORD = 'EMPTY_PASSWORD'; public const ERROR_INCORRECT_PASSWORD = 'INCORRECT_PASSWORD'; - public const ERROR_INTERNAL = 'INTERNAL_ERROR'; public const ERROR_SYSTEM_DISABLED = 'SYSTEM_DISABLED'; public const ERROR_USER_DISABLED = 'USER_DISABLED'; public const ERROR_USER_NOT_FOUND = 'USER_NOT_FOUND'; diff --git a/src/Models/User/Register.php b/src/Models/User/Register.php index dc68715a..b018edc3 100644 --- a/src/Models/User/Register.php +++ b/src/Models/User/Register.php @@ -9,7 +9,6 @@ class Register extends \BNETDocs\Models\ActiveUser implements \JsonSerializable public const ERROR_EMAIL_ALREADY_USED = 'EMAIL_ALREADY_USED'; public const ERROR_EMAIL_FAILURE = 'EMAIL_FAILURE'; public const ERROR_EMAIL_NOT_ALLOWED = 'EMAIL_NOT_ALLOWED'; - public const ERROR_INTERNAL = 'INTERNAL_ERROR'; public const ERROR_INVALID_CAPTCHA = 'INVALID_CAPTCHA'; public const ERROR_INVALID_EMAIL = 'INVALID_EMAIL'; public const ERROR_NONMATCHING_PASSWORD = 'NONMATCHING_PASSWORD'; diff --git a/src/Models/User/ResetPassword.php b/src/Models/User/ResetPassword.php index 93622f88..fd705c2a 100644 --- a/src/Models/User/ResetPassword.php +++ b/src/Models/User/ResetPassword.php @@ -4,18 +4,16 @@ class ResetPassword extends \BNETDocs\Models\Core\HttpForm implements \JsonSerializable { - public const E_BAD_EMAIL = 'BAD_EMAIL'; - public const E_BAD_TOKEN = 'BAD_TOKEN'; - public const E_EMPTY_EMAIL = 'EMPTY_EMAIL'; - public const E_SUCCESS = 'SUCCESS'; - public const E_INTERNAL_ERROR = 'INTERNAL_ERROR'; - public const E_PASSWORD_CONTAINS_EMAIL = 'PASSWORD_CONTAINS_EMAIL'; - public const E_PASSWORD_CONTAINS_USERNAME = 'PASSWORD_CONTAINS_USERNAME'; - public const E_PASSWORD_MISMATCH = 'PASSWORD_MISMATCH'; - public const E_PASSWORD_TOO_LONG = 'PASSWORD_TOO_LONG'; - public const E_PASSWORD_TOO_SHORT = 'PASSWORD_TOO_SHORT'; - public const E_USER_DISABLED = 'USER_DISABLED'; - public const E_USER_NOT_FOUND = 'USER_NOT_FOUND'; + public const ERROR_BAD_EMAIL = 'BAD_EMAIL'; + public const ERROR_BAD_TOKEN = 'BAD_TOKEN'; + public const ERROR_EMPTY_EMAIL = 'EMPTY_EMAIL'; + public const ERROR_PASSWORD_CONTAINS_EMAIL = 'PASSWORD_CONTAINS_EMAIL'; + public const ERROR_PASSWORD_CONTAINS_USERNAME = 'PASSWORD_CONTAINS_USERNAME'; + public const ERROR_PASSWORD_MISMATCH = 'PASSWORD_MISMATCH'; + public const ERROR_PASSWORD_TOO_LONG = 'PASSWORD_TOO_LONG'; + public const ERROR_PASSWORD_TOO_SHORT = 'PASSWORD_TOO_SHORT'; + public const ERROR_USER_DISABLED = 'USER_DISABLED'; + public const ERROR_USER_NOT_FOUND = 'USER_NOT_FOUND'; public ?string $email = null; public ?string $pw1 = null; diff --git a/src/Models/User/Verify.php b/src/Models/User/Verify.php index 45d98621..2702830e 100644 --- a/src/Models/User/Verify.php +++ b/src/Models/User/Verify.php @@ -4,7 +4,6 @@ class Verify extends \BNETDocs\Models\ActiveUser implements \JsonSerializable { - public const ERROR_INTERNAL = 'INTERNAL_ERROR'; public const ERROR_INVALID_TOKEN = 'INVALID_TOKEN'; public ?string $token = null; diff --git a/src/Templates/Server/Delete.phtml b/src/Templates/Server/Delete.phtml index bda3b7fb..5fd994df 100644 --- a/src/Templates/Server/Delete.phtml +++ b/src/Templates/Server/Delete.phtml @@ -1,24 +1,24 @@ getContext(); switch ($model->error) { - case DeleteModel::ERROR_ACL_NOT_SET: $message = 'You do not have the privilege to delete servers.'; break; - case DeleteModel::ERROR_INTERNAL: $message = 'An internal error occurred while processing your request. Try again later.'; break; - case DeleteModel::ERROR_NOT_FOUND: $message = 'Cannot find server by that id.'; break; - case DeleteModel::ERROR_NOT_LOGGED_IN: $message = 'You must be logged in to delete servers.'; break; + case FormModel::ERROR_ACL_NOT_SET: $message = 'You do not have the privilege to delete servers.'; break; + case FormModel::ERROR_INTERNAL: $message = 'An internal error occurred while processing your request. Try again later.'; break; + case FormModel::ERROR_NOT_FOUND: $message = 'Cannot find server by that id.'; break; + case FormModel::ERROR_NOT_LOGGED_IN: $message = 'You must be logged in to delete servers.'; break; default: $message = $model->error; } $id = $model->server ? $model->server->getId() : null; $json = $model->server ? json_encode($model->server, \BNETDocs\Views\Server\ViewJson::jsonFlags()) : null; require('./Includes/header.inc.phtml'); echo '
'; -if ($model->error === DeleteModel::ERROR_ACL_NOT_SET) +if ($model->error === FormModel::ERROR_ACL_NOT_SET || $model->error === FormModel::ERROR_NOT_LOGGED_IN) { require('./Includes/LoginRequired.inc.phtml'); } @@ -35,7 +35,7 @@ else printf('

%s

', $title); printf('

%s

', $description); if (!empty($message)) printf('

%s

', $message); - if ($model->error !== DeleteModel::ERROR_NOT_FOUND) + if ($model->error !== FormModel::ERROR_NOT_FOUND) { printf('
', $id); echo '

Are you sure you wish to delete this server?

'; diff --git a/src/Templates/Server/Form.phtml b/src/Templates/Server/Form.phtml index 6579da3c..80fda704 100644 --- a/src/Templates/Server/Form.phtml +++ b/src/Templates/Server/Form.phtml @@ -2,31 +2,31 @@ namespace BNETDocs\Templates\Server; use \BNETDocs\Models\Server\Form as FormModel; $model = $this->getContext(); -$title = sprintf('%s Server', $model->server_edit ? 'Edit' : 'Create'); -$description = sprintf('This page enables a user to %s servers on the site.', $model->server_edit ? 'edit' : 'create'); -$url = sprintf('/server/%s%s', $model->server_edit ? 'edit' : 'create', $model->server && !is_null($model->server->getId()) ? sprintf('?id=%d', $model->server->getId()) : ''); +$title = sprintf('%s Server', $model->server_edit ? 'Edit' : ($model->server_delete ? 'Delete' : 'Create')); +$description = sprintf('This page enables a user to %s servers on the site.', $model->server_edit ? 'edit' : ($model->server_delete ? 'delete' : 'create')); +$url = sprintf('/server/%s%s', $model->server_edit ? 'edit' : ($model->server_delete ? 'delete' : 'create'), $model->server && !is_null($model->server->getId()) ? sprintf('?id=%d', $model->server->getId()) : ''); switch ($model->error) { - case FormModel::ERROR_ACCESS_DENIED: $message = sprintf('You do not have the privilege to %s servers.', $model->server_edit ? 'edit' : 'create'); break; + case FormModel::ERROR_ACL_NOT_SET: $message = sprintf('You do not have the privilege to %s servers.', $model->server_edit ? 'edit' : ($model->server_delete ? 'delete' : 'create')); break; + case FormModel::ERROR_NOT_LOGGED_IN: $message = sprintf('You must be logged in to %s servers.', $model->server_edit ? 'edit' : ($model->server_delete ? 'delete' : 'create')); break; case FormModel::ERROR_INTERNAL: $message = 'An internal error occurred while processing your request. Try again later.'; break; case FormModel::ERROR_INVALID_ADDRESS: $message = 'The address of the server is invalid or contains too many characters.'; break; case FormModel::ERROR_INVALID_ID: $message = 'The id of the server is invalid.'; break; case FormModel::ERROR_INVALID_LABEL: $message = 'The label of the server is invalid or contains too many characters.'; break; case FormModel::ERROR_INVALID_PORT: $message = 'The port of the server is invalid.'; break; case FormModel::ERROR_INVALID_TYPE: $message = 'The type of the server is invalid.'; break; - case FormModel::ERROR_SUCCESS: $message = sprintf('The server has been %s!', $model->server_edit ? 'edited' : 'created'); break; default: $message = $model->error; } require('./Includes/header.inc.phtml'); echo '
'; printf('

%s

%s

', $title, $description); -if ($model->error === FormModel::ERROR_ACCESS_DENIED) +if ($model->error === FormModel::ERROR_ACL_NOT_SET || $model->error === FormModel::ERROR_NOT_LOGGED_IN) { require('./Includes/LoginRequired.inc.phtml'); } -else if ($model->error === FormModel::ERROR_SUCCESS) +else if ($model->error === false) { - printf('

%s

', $message); + printf('

The server has been %s!

', $model->server_edit ? 'edited' : ($model->server_delete ? 'deleted' : 'created')); echo '
'; echo 'Back '; printf('Server List ', \BNETDocs\Libraries\Core\UrlFormatter::format('/servers')); diff --git a/src/Templates/User/ResetPassword.phtml b/src/Templates/User/ResetPassword.phtml index cf2cca77..489f2207 100644 --- a/src/Templates/User/ResetPassword.phtml +++ b/src/Templates/User/ResetPassword.phtml @@ -11,24 +11,23 @@ $token = $this->getContext()->token; $token_html = filter_var($token, FILTER_SANITIZE_FULL_SPECIAL_CHARS); switch ($error) { - case ResetPasswordModel::E_SUCCESS: $message = ''; break; - case ResetPasswordModel::E_BAD_EMAIL: $message = 'The email address is invalid.'; break; - case ResetPasswordModel::E_BAD_TOKEN: $message = 'The token is expired or invalid and therefore cannot be used.'; break; - case ResetPasswordModel::E_EMPTY_EMAIL: $message = 'The email address was left blank.'; break; - case ResetPasswordModel::E_INTERNAL_ERROR: $message = 'The server experienced an internal error.'; break; - case ResetPasswordModel::E_PASSWORD_CONTAINS_EMAIL: $message = 'The password contains the email address, use a better password.'; break; - case ResetPasswordModel::E_PASSWORD_CONTAINS_USERNAME: $message = 'The password contains the username, use a better password.'; break; - case ResetPasswordModel::E_PASSWORD_MISMATCH: $message = 'The passwords did not match, please try again.'; break; - case ResetPasswordModel::E_PASSWORD_TOO_LONG: $message = 'The password is too long, shorten it.'; break; - case ResetPasswordModel::E_PASSWORD_TOO_SHORT: $message = 'The password is too short, use a better password.'; break; - case ResetPasswordModel::E_USER_DISABLED: $message = 'The account has been administratively disabled.'; break; - case ResetPasswordModel::E_USER_NOT_FOUND: $message = 'The email address was not found in our system.'; break; + case ResetPasswordModel::ERROR_BAD_EMAIL: $message = 'The email address is invalid.'; break; + case ResetPasswordModel::ERROR_BAD_TOKEN: $message = 'The token is expired or invalid and therefore cannot be used.'; break; + case ResetPasswordModel::ERROR_EMPTY_EMAIL: $message = 'The email address was left blank.'; break; + case ResetPasswordModel::ERROR_INTERNAL: $message = 'The server experienced an internal error.'; break; + case ResetPasswordModel::ERROR_PASSWORD_CONTAINS_EMAIL: $message = 'The password contains the email address, use a better password.'; break; + case ResetPasswordModel::ERROR_PASSWORD_CONTAINS_USERNAME: $message = 'The password contains the username, use a better password.'; break; + case ResetPasswordModel::ERROR_PASSWORD_MISMATCH: $message = 'The passwords did not match, please try again.'; break; + case ResetPasswordModel::ERROR_PASSWORD_TOO_LONG: $message = 'The password is too long, shorten it.'; break; + case ResetPasswordModel::ERROR_PASSWORD_TOO_SHORT: $message = 'The password is too short, use a better password.'; break; + case ResetPasswordModel::ERROR_USER_DISABLED: $message = 'The account has been administratively disabled.'; break; + case ResetPasswordModel::ERROR_USER_NOT_FOUND: $message = 'The email address was not found in our system.'; break; default: $message = $error; } require('./Includes/header.inc.phtml'); ?>

%s

', $message) : '')?> - +

Reset Password

@@ -59,12 +58,12 @@ require('./Includes/header.inc.phtml'); ?>
- +

Email Sent

An email has been sent with a link to reset the password.

- +

Password Changed

Your password has been changed, you may now log in.

diff --git a/src/Views/Server/DeleteHtml.php b/src/Views/Server/DeleteHtml.php index 8f85fe5a..140ca536 100644 --- a/src/Views/Server/DeleteHtml.php +++ b/src/Views/Server/DeleteHtml.php @@ -6,7 +6,7 @@ class DeleteHtml extends \BNETDocs\Views\Base\Html { public static function invoke(\BNETDocs\Interfaces\Model $model): void { - if (!$model instanceof \BNETDocs\Models\Server\Delete) + if (!$model instanceof \BNETDocs\Models\Server\Form) { throw new \BNETDocs\Exceptions\InvalidModelException($model); }