Skip to content

Commit b16682d

Browse files
committed
Refactor ERROR_INTERNAL/ACL_NOT_SET/NOT_LOGGED_IN
1 parent 3a688d0 commit b16682d

34 files changed

+88
-135
lines changed

src/Controllers/Document/View.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use \BNETDocs\Libraries\Comment;
66
use \BNETDocs\Libraries\Core\HttpCode;
7+
use \BNETDocs\Models\Document\View as ViewModel;
78

89
class View extends \BNETDocs\Controllers\Base
910
{
@@ -12,7 +13,7 @@ class View extends \BNETDocs\Controllers\Base
1213
*/
1314
public function __construct()
1415
{
15-
$this->model = new \BNETDocs\Models\Document\View();
16+
$this->model = new ViewModel();
1617
}
1718

1819
/**
@@ -32,6 +33,7 @@ public function invoke(?array $args): bool
3233
&& !($this->model->active_user && $this->model->active_user->isStaff()))
3334
{
3435
$this->model->_responseCode = HttpCode::HTTP_FORBIDDEN;
36+
$this->model->error = $this->model->active_user ? ViewModel::ERROR_ACL_NOT_SET : ViewModel::ERROR_NOT_LOGGED_IN;
3537
$this->model->document = null;
3638
return true;
3739
}

src/Controllers/EventLog/Index.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use \BNETDocs\Libraries\Core\HttpCode;
66
use \BNETDocs\Libraries\EventLog\Event;
7+
use \BNETDocs\Models\EventLog\Index as IndexModel;
78

89
class Index extends \BNETDocs\Controllers\Base
910
{
@@ -13,7 +14,7 @@ class Index extends \BNETDocs\Controllers\Base
1314

1415
public function __construct()
1516
{
16-
$this->model = new \BNETDocs\Models\EventLog\Index();
17+
$this->model = new IndexModel();
1718
}
1819

1920
public function invoke(?array $args): bool
@@ -24,6 +25,7 @@ public function invoke(?array $args): bool
2425
if (!$this->model->acl_allowed)
2526
{
2627
$this->model->_responseCode = HttpCode::HTTP_FORBIDDEN;
28+
$this->model->error = $this->model->active_user ? IndexModel::ERROR_ACL_NOT_SET : IndexModel::ERROR_NOT_LOGGED_IN;
2729
return true;
2830
}
2931

src/Controllers/EventLog/View.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
namespace BNETDocs\Controllers\EventLog;
44

55
use \BNETDocs\Libraries\Core\HttpCode;
6+
use \BNETDocs\Models\EventLog\View as ViewModel;
67

78
class View extends \BNETDocs\Controllers\Base
89
{
910
public function __construct()
1011
{
11-
$this->model = new \BNETDocs\Models\EventLog\View();
12+
$this->model = new ViewModel();
1213
}
1314

1415
public function invoke(?array $args): bool
@@ -19,6 +20,7 @@ public function invoke(?array $args): bool
1920
if (!$this->model->acl_allowed)
2021
{
2122
$this->model->_responseCode = HttpCode::HTTP_FORBIDDEN;
23+
$this->model->error = $this->model->active_user ? ViewModel::ERROR_ACL_NOT_SET : ViewModel::ERROR_NOT_LOGGED_IN;
2224
return true;
2325
}
2426

src/Controllers/Packet/View.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33

44
use \BNETDocs\Libraries\Comment;
55
use \BNETDocs\Libraries\Core\HttpCode;
6+
use BNETDocs\Models\Packet\View as ViewModel;
67

78
class View extends \BNETDocs\Controllers\Base
89
{
910
public function __construct()
1011
{
11-
$this->model = new \BNETDocs\Models\Packet\View();
12+
$this->model = new ViewModel();
1213
}
1314

1415
public function invoke(?array $args): bool
@@ -21,6 +22,7 @@ public function invoke(?array $args): bool
2122
if (!$this->model->packet)
2223
{
2324
$this->model->_responseCode = HttpCode::HTTP_NOT_FOUND;
25+
$this->model->error = ViewModel::ERROR_NOT_FOUND;
2426
return true;
2527
}
2628

src/Controllers/Server/Create.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,10 @@ public function __construct()
2121

2222
public function invoke(?array $args): bool
2323
{
24-
$this->model->server_edit = false;
25-
2624
if (!($this->model->active_user && $this->model->active_user->getOption(\BNETDocs\Libraries\User\User::OPTION_ACL_SERVER_CREATE)))
2725
{
2826
$this->model->_responseCode = HttpCode::HTTP_FORBIDDEN;
29-
$this->model->error = FormModel::ERROR_ACCESS_DENIED;
27+
$this->model->error = $this->model->active_user ? FormModel::ERROR_ACL_NOT_SET : FormModel::ERROR_NOT_LOGGED_IN;
3028
return true;
3129
}
3230

src/Controllers/Server/Delete.php

+8-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use \BNETDocs\Libraries\Core\HttpCode;
66
use \BNETDocs\Libraries\Core\Router;
77
use \BNETDocs\Libraries\EventLog\Logger;
8-
use \BNETDocs\Models\Server\Delete as DeleteModel;
8+
use \BNETDocs\Models\Server\Form as FormModel;
99

1010
class Delete extends \BNETDocs\Controllers\Base
1111
{
@@ -15,23 +15,25 @@ class Delete extends \BNETDocs\Controllers\Base
1515

1616
public function __construct()
1717
{
18-
$this->model = new DeleteModel();
18+
$this->model = new FormModel();
1919
}
2020

2121
public function invoke(?array $args): bool
2222
{
23+
$this->model->server_delete = true;
24+
2325
if (!($this->model->active_user && $this->model->active_user->getOption(\BNETDocs\Libraries\User\User::OPTION_ACL_SERVER_DELETE)))
2426
{
2527
$this->model->_responseCode = HttpCode::HTTP_FORBIDDEN;
26-
$this->model->error = $this->model->active_user ? DeleteModel::ERROR_ACL_NOT_SET : DeleteModel::ERROR_NOT_LOGGED_IN;
28+
$this->model->error = $this->model->active_user ? FormModel::ERROR_ACL_NOT_SET : FormModel::ERROR_NOT_LOGGED_IN;
2729
return true;
2830
}
2931

3032
$id = Router::query()['id'] ?? null;
3133
if (!is_numeric($id))
3234
{
3335
$this->model->_responseCode = HttpCode::HTTP_BAD_REQUEST;
34-
$this->model->error = DeleteModel::ERROR_NOT_FOUND;
36+
$this->model->error = FormModel::ERROR_NOT_FOUND;
3537
return true;
3638
}
3739
$id = (int) $id;
@@ -42,7 +44,7 @@ public function invoke(?array $args): bool
4244
if (!$this->model->server)
4345
{
4446
$this->model->_responseCode = HttpCode::HTTP_NOT_FOUND;
45-
$this->model->error = DeleteModel::ERROR_NOT_FOUND;
47+
$this->model->error = FormModel::ERROR_NOT_FOUND;
4648
return true;
4749
}
4850

@@ -53,7 +55,7 @@ public function invoke(?array $args): bool
5355

5456
protected function handlePost(): void
5557
{
56-
$this->model->error = $this->model->server->deallocate() ? false : DeleteModel::ERROR_INTERNAL;
58+
$this->model->error = $this->model->server->deallocate() ? false : FormModel::ERROR_INTERNAL;
5759
if ($this->model->error === false)
5860
{
5961
$event = Logger::initEvent(

src/Controllers/Server/Edit.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function invoke(?array $args): bool
2626
if (!($this->model->active_user && $this->model->active_user->getOption(\BNETDocs\Libraries\User\User::OPTION_ACL_SERVER_MODIFY)))
2727
{
2828
$this->model->_responseCode = HttpCode::HTTP_FORBIDDEN;
29-
$this->model->error = FormModel::ERROR_ACCESS_DENIED;
29+
$this->model->error = $this->model->active_user ? FormModel::ERROR_ACL_NOT_SET : FormModel::ERROR_NOT_LOGGED_IN;
3030
return true;
3131
}
3232

@@ -74,9 +74,9 @@ protected function handlePost(): void
7474
$this->model->server->setDisabled((bool) ($this->model->form_fields['disabled'] ?? null));
7575
$this->model->server->setOnline((bool) ($this->model->form_fields['online'] ?? null));
7676

77-
$this->model->error = $this->model->server->commit() ? FormModel::ERROR_SUCCESS : FormModel::ERROR_INTERNAL;
77+
$this->model->error = $this->model->server->commit() ? false : FormModel::ERROR_INTERNAL;
7878

79-
if ($this->model->error === FormModel::ERROR_SUCCESS)
79+
if ($this->model->error === false)
8080
{
8181
$event = Logger::initEvent(
8282
\BNETDocs\Libraries\EventLog\EventTypes::SERVER_EDITED,

src/Controllers/User/ResetPassword.php

+14-14
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function invoke(?array $args): bool
5656

5757
protected function doPasswordReset(): mixed
5858
{
59-
if (empty($this->model->email)) return ResetPasswordModel::E_EMPTY_EMAIL;
59+
if (empty($this->model->email)) return ResetPasswordModel::ERROR_EMPTY_EMAIL;
6060

6161
try
6262
{
@@ -65,10 +65,10 @@ protected function doPasswordReset(): mixed
6565
}
6666
catch (UnexpectedValueException)
6767
{
68-
return ResetPasswordModel::E_BAD_EMAIL;
68+
return ResetPasswordModel::ERROR_BAD_EMAIL;
6969
}
7070

71-
if (!$this->model->user) return ResetPasswordModel::E_USER_NOT_FOUND;
71+
if (!$this->model->user) return ResetPasswordModel::ERROR_USER_NOT_FOUND;
7272

7373
if (empty($this->model->token))
7474
{
@@ -79,35 +79,35 @@ protected function doPasswordReset(): mixed
7979
)
8080
);
8181

82-
return $this->model->user->commit() ? self::sendEmail() : ResetPasswordModel::E_INTERNAL_ERROR;
82+
return $this->model->user->commit() ? self::sendEmail() : ResetPasswordModel::ERROR_INTERNAL;
8383
}
8484

8585
if ($this->model->token !== $this->model->user->getVerifierToken())
86-
return ResetPasswordModel::E_BAD_TOKEN;
86+
return ResetPasswordModel::ERROR_BAD_TOKEN;
8787

8888
if ($this->model->pw1 !== $this->model->pw2)
89-
return ResetPasswordModel::E_PASSWORD_MISMATCH;
89+
return ResetPasswordModel::ERROR_PASSWORD_MISMATCH;
9090

9191
$req = Config::get('bnetdocs.user_register_requirements') ?? [];
9292
$pwlen = strlen($this->model->pw1);
9393

9494
if (is_numeric($req->password_length_max) && $pwlen > $req->password_length_max)
95-
return ResetPasswordModel::E_PASSWORD_TOO_LONG;
95+
return ResetPasswordModel::ERROR_PASSWORD_TOO_LONG;
9696

9797
if (is_numeric($req->password_length_min) && $pwlen < $req->password_length_min)
98-
return ResetPasswordModel::E_PASSWORD_TOO_SHORT;
98+
return ResetPasswordModel::ERROR_PASSWORD_TOO_SHORT;
9999

100100
if (!$req->password_allow_email && stripos($this->model->pw1, $this->model->user->getEmail()))
101-
return ResetPasswordModel::E_PASSWORD_CONTAINS_EMAIL;
101+
return ResetPasswordModel::ERROR_PASSWORD_CONTAINS_EMAIL;
102102

103103
if (!$req->password_allow_username && stripos($this->model->pw1, $this->model->user->getUsername()))
104-
return ResetPasswordModel::E_PASSWORD_CONTAINS_USERNAME;
104+
return ResetPasswordModel::ERROR_PASSWORD_CONTAINS_USERNAME;
105105

106-
if ($this->model->user->isDisabled()) return ResetPasswordModel::E_USER_DISABLED;
106+
if ($this->model->user->isDisabled()) return ResetPasswordModel::ERROR_USER_DISABLED;
107107

108108
$this->model->user->setPassword($this->model->pw1);
109109
$this->model->user->setVerified(true);
110-
return $this->model->user->commit() ? ResetPasswordModel::E_SUCCESS : ResetPasswordModel::E_INTERNAL_ERROR;
110+
return $this->model->user->commit() ? false : ResetPasswordModel::ERROR_INTERNAL;
111111
}
112112

113113
protected function sendEmail(): mixed
@@ -186,9 +186,9 @@ protected function sendEmail(): mixed
186186
}
187187
catch (\PHPMailer\PHPMailer\Exception)
188188
{
189-
return ResetPasswordModel::E_INTERNAL_ERROR;
189+
return ResetPasswordModel::ERROR_INTERNAL;
190190
}
191191

192-
return ResetPasswordModel::E_SUCCESS;
192+
return false;
193193
}
194194
}

src/Models/Comment/Create.php

-3
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44

55
class Create extends \BNETDocs\Models\Core\AccessControl implements \JsonSerializable
66
{
7-
public const ERROR_ACL_NOT_SET = 'ACL_NOT_SET';
87
public const ERROR_EMPTY_CONTENT = 'EMPTY_CONTENT';
9-
public const ERROR_INTERNAL = 'INTERNAL_ERROR';
10-
public const ERROR_NOT_LOGGED_IN = 'NOT_LOGGED_IN';
118

129
public ?\BNETDocs\Libraries\Comment $comment = null;
1310
public ?string $origin = null;

src/Models/Comment/Delete.php

-3
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44

55
class Delete extends \BNETDocs\Models\Core\AccessControl implements \JsonSerializable
66
{
7-
public const ERROR_ACL_NOT_SET = 'ACL_NOT_SET';
8-
public const ERROR_INTERNAL = 'INTERNAL_ERROR';
97
public const ERROR_NOT_FOUND = 'NOT_FOUND';
10-
public const ERROR_NOT_LOGGED_IN = 'NOT_LOGGED_IN';
118

129
public ?\BNETDocs\Libraries\Comment $comment = null;
1310
public ?string $content = null;

src/Models/Comment/Edit.php

-3
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,8 @@
44

55
class Edit extends \BNETDocs\Models\Core\AccessControl implements \JsonSerializable
66
{
7-
public const ERROR_ACL_NOT_SET = 'ACL_NOT_SET';
87
public const ERROR_EMPTY_CONTENT = 'EMPTY_CONTENT';
9-
public const ERROR_INTERNAL = 'INTERNAL_ERROR';
108
public const ERROR_NOT_FOUND = 'NOT_FOUND';
11-
public const ERROR_NOT_LOGGED_IN = 'NOT_LOGGED_IN';
129

1310
public ?\BNETDocs\Libraries\Comment $comment = null;
1411
public ?string $content = null;

src/Models/Core/AccessControl.php

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
class AccessControl extends \BNETDocs\Models\ActiveUser implements \JsonSerializable
66
{
7+
public const ERROR_ACL_NOT_SET = 'ACL_NOT_SET';
8+
public const ERROR_NOT_LOGGED_IN = 'NOT_LOGGED_IN';
9+
710
/**
811
* Stores whether $this->active_user is permitted to access this controller.
912
*

src/Models/Core/Errorable.php

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
class Errorable extends \BNETDocs\Models\Base implements \JsonSerializable
66
{
7+
public const ERROR_INTERNAL = 'INTERNAL_ERROR';
8+
79
/**
810
* Stores error state information between Controller and downstream handlers, useful for Template rendering.
911
*

src/Models/Document/Create.php

-3
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,8 @@
44

55
class Create extends \BNETDocs\Models\Core\AccessControl implements \JsonSerializable
66
{
7-
public const ERROR_ACL_NOT_SET = 'ACL_NOT_SET';
87
public const ERROR_EMPTY_CONTENT = 'EMPTY_CONTENT';
98
public const ERROR_EMPTY_TITLE = 'EMPTY_TITLE';
10-
public const ERROR_INTERNAL = 'INTERNAL_ERROR';
11-
public const ERROR_NOT_LOGGED_IN = 'NOT_LOGGED_IN';
129

1310
public ?string $brief = null;
1411
public ?string $content = null;

src/Models/Document/Delete.php

-3
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44

55
class Delete extends \BNETDocs\Models\Core\AccessControl implements \JsonSerializable
66
{
7-
public const ERROR_ACL_NOT_SET = 'ACL_NOT_SET';
8-
public const ERROR_INTERNAL = 'INTERNAL_ERROR';
97
public const ERROR_NOT_FOUND = 'NOT_FOUND';
10-
public const ERROR_NOT_LOGGED_IN = 'NOT_LOGGED_IN';
118

129
public ?\BNETDocs\Libraries\Document $document = null;
1310
public ?int $id = null;

src/Models/Document/Edit.php

-3
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,9 @@
44

55
class Edit extends \BNETDocs\Models\Core\AccessControl implements \JsonSerializable
66
{
7-
public const ERROR_ACL_NOT_SET = 'ACL_NOT_SET';
87
public const ERROR_EMPTY_CONTENT = 'EMPTY_CONTENT';
98
public const ERROR_EMPTY_TITLE = 'EMPTY_TITLE';
10-
public const ERROR_INTERNAL = 'INTERNAL_ERROR';
119
public const ERROR_NOT_FOUND = 'NOT_FOUND';
12-
public const ERROR_NOT_LOGGED_IN = 'NOT_LOGGED_IN';
1310

1411
public ?string $brief = null;
1512
public ?string $category = null;

src/Models/News/Create.php

-3
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,8 @@
44

55
class Create extends \BNETDocs\Models\Core\AccessControl implements \JsonSerializable
66
{
7-
public const ERROR_ACL_NOT_SET = 'ACL_NOT_SET';
87
public const ERROR_EMPTY_CONTENT = 'EMPTY_CONTENT';
98
public const ERROR_EMPTY_TITLE = 'EMPTY_TITLE';
10-
public const ERROR_INTERNAL = 'INTERNAL_ERROR';
11-
public const ERROR_NOT_LOGGED_IN = 'NOT_LOGGED_IN';
129

1310
public ?int $category_id = null;
1411
public string $content = '';

src/Models/News/Delete.php

-3
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44

55
class Delete extends \BNETDocs\Models\Core\AccessControl implements \JsonSerializable
66
{
7-
public const ERROR_ACL_NOT_SET = 'ACL_NOT_SET';
8-
public const ERROR_INTERNAL = 'INTERNAL_ERROR';
97
public const ERROR_NOT_FOUND = 'NOT_FOUND';
10-
public const ERROR_NOT_LOGGED_IN = 'NOT_LOGGED_IN';
118

129
public ?int $id = null;
1310
public ?\BNETDocs\Libraries\News\Post $news_post = null;

src/Models/News/Edit.php

-3
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,9 @@
44

55
class Edit extends \BNETDocs\Models\Core\AccessControl implements \JsonSerializable
66
{
7-
public const ERROR_ACL_NOT_SET = 'ACL_NOT_SET';
87
public const ERROR_EMPTY_CONTENT = 'EMPTY_CONTENT';
98
public const ERROR_EMPTY_TITLE = 'EMPTY_TITLE';
10-
public const ERROR_INTERNAL = 'INTERNAL_ERROR';
119
public const ERROR_NOT_FOUND = 'NOT_FOUND';
12-
public const ERROR_NOT_LOGGED_IN = 'NOT_LOGGED_IN';
1310

1411
public ?int $category = null;
1512
public ?array $comments = null;

0 commit comments

Comments
 (0)