-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathDelete.php
More file actions
86 lines (74 loc) · 2.59 KB
/
Copy pathDelete.php
File metadata and controls
86 lines (74 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
namespace BNETDocs\Controllers\User;
use \BNETDocs\Libraries\Core\HttpCode;
use \BNETDocs\Libraries\Core\Router;
use \BNETDocs\Libraries\EventLog\EventTypes;
use \BNETDocs\Libraries\EventLog\Logger;
use \BNETDocs\Models\User\Delete as DeleteModel;
class Delete extends \BNETDocs\Controllers\Base
{
public function __construct()
{
$this->model = new DeleteModel();
}
public function invoke(?array $args): bool
{
$this->model->acl_allowed = $this->model->active_user
&& $this->model->active_user->getOption(\BNETDocs\Libraries\User\User::OPTION_ACL_USER_DELETE);
if (!$this->model->acl_allowed)
{
$this->model->_responseCode = HttpCode::HTTP_FORBIDDEN;
$this->model->error = DeleteModel::ERROR_ACL_NOT_SET;
return true;
}
$this->model->form_fields = Router::query();
$this->model->target_id = $this->model->form_fields['id'] ?? null;
try
{
if (!\is_null($this->model->target_id))
{
$this->model->target_user = new \BNETDocs\Libraries\User\User($this->model->target_id);
}
}
catch (\BNETDocs\Exceptions\UserNotFoundException)
{
$this->model->target_user = null;
}
finally
{
if (!$this->model->target_user)
{
$this->model->_responseCode = HttpCode::HTTP_NOT_FOUND;
$this->model->error = DeleteModel::ERROR_NOT_FOUND;
return true;
}
}
if (Router::requestMethod() == Router::METHOD_POST)
{
$this->model->deleted = $this->model->target_user->deallocate();
if (!$this->model->deleted)
{
$this->model->_responseCode = HttpCode::HTTP_INTERNAL_SERVER_ERROR;
$this->model->error = DeleteModel::ERROR_INTERNAL;
return true;
}
else
{
$this->model->error = false;
$event = Logger::initEvent(
EventTypes::USER_DELETED,
$this->model->active_user->getId(),
getenv('REMOTE_ADDR'),
$this->model
);
if ($event->commit())
{
$embed = Logger::initDiscordEmbed($event, $this->model->target_user->getURI());
Logger::logToDiscord($event, $embed);
}
}
}
$this->model->_responseCode = HttpCode::HTTP_OK;
return true;
}
}