mirror of
https://github.com/NamelessMC/Nameless
synced 2026-08-18 06:29:04 -04:00
40 lines
1.2 KiB
PHP
40 lines
1.2 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @param int $id The NamelessMC user's ID
|
|
* @param string $code The NamelessMC user's reset code, used to verify they own the account
|
|
*
|
|
* @return string JSON Array
|
|
*/
|
|
class VerifyEndpoint extends KeyAuthEndpoint {
|
|
|
|
public function __construct() {
|
|
$this->_route = 'users/{user}/verify';
|
|
$this->_module = 'Core';
|
|
$this->_description = 'Validate/Activate a NamelessMC account by confirming their reset code';
|
|
$this->_method = 'POST';
|
|
}
|
|
|
|
public function execute(Nameless2API $api, User $user): void {
|
|
$api->validateParams($_POST, ['code']);
|
|
|
|
if ($user->data()->active || $user->data()->reset_code == '') {
|
|
$api->throwError(CoreApiErrors::ERROR_USER_ALREADY_ACTIVE);
|
|
}
|
|
|
|
if ($user->data()->reset_code != $_POST['code']) {
|
|
$api->throwError(CoreApiErrors::ERROR_INVALID_CODE);
|
|
}
|
|
|
|
$user->update([
|
|
'active' => true,
|
|
'reset_code' => null,
|
|
]);
|
|
|
|
EventHandler::executeEvent(new UserValidatedEvent(
|
|
$user,
|
|
));
|
|
|
|
$api->returnArray(['message' => $api->getLanguage()->get('api', 'account_validated')]);
|
|
}
|
|
}
|