-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathVerify.php
More file actions
71 lines (61 loc) · 2.04 KB
/
Copy pathVerify.php
File metadata and controls
71 lines (61 loc) · 2.04 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
<?php
namespace BNETDocs\Controllers\User;
use \BNETDocs\Libraries\Core\HttpCode;
use \BNETDocs\Libraries\EventLog\Logger;
use \BNETDocs\Models\User\Verify as VerifyModel;
class Verify extends \BNETDocs\Controllers\Base
{
/**
* Constructs a Controller, typically to initialize properties.
*/
public function __construct()
{
$this->model = new VerifyModel();
}
/**
* Invoked by the Router class to handle the request.
*
* @param array|null $args The optional route arguments and any captured URI arguments.
* @return boolean Whether the Router should invoke the configured View.
*/
public function invoke(?array $args): bool
{
$q = \BNETDocs\Libraries\Core\Router::query();
$this->model->token = $q['t'] ?? null;
$this->model->user_id = $q['u'] ?? null;
if (is_numeric($this->model->user_id))
{
try { $this->model->user = new \BNETDocs\Libraries\User\User((int) $this->model->user_id); }
catch (\UnexpectedValueException) { $this->model->user = null; }
}
$user_token = $this->model->user ? $this->model->user->getVerifierToken() : null;
if (!$this->model->user || $user_token !== $this->model->token)
{
$this->model->error = VerifyModel::ERROR_INVALID_TOKEN;
$this->model->_responseCode = HttpCode::HTTP_BAD_REQUEST;
return true;
}
try
{
$this->model->user->setVerified(true, true);
$this->model->error = $this->model->user->commit() ? false : VerifyModel::ERROR_INTERNAL;
}
catch (\Throwable) { $this->model->error = VerifyModel::ERROR_INTERNAL; }
if (!$this->model->error)
{
$event = Logger::initEvent(
\BNETDocs\Libraries\EventLog\EventTypes::USER_VERIFIED,
$this->model->user_id,
getenv('REMOTE_ADDR'),
['error' => $this->model->error]
);
if ($event->commit())
{
$embed = Logger::initDiscordEmbed($event, $this->model->user->getURI());
Logger::logToDiscord($event, $embed);
}
}
$this->model->_responseCode = HttpCode::HTTP_OK;
return true;
}
}