Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ee01af4
commit 158fd22
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
upload/modules/OAuth2/includes/endpoints/Resources/OAuth2ResourcesLicensesEndpoint.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
class OAuth2ResourcesLicensesEndpoint extends AccessTokenAuthEndpoint { | ||
|
||
public function __construct() { | ||
$this->_route = 'oauth2/resources/licenses'; | ||
$this->_module = 'OAuth2'; | ||
$this->_description = 'Get user resource licenses'; | ||
$this->_method = 'GET'; | ||
} | ||
|
||
public function execute(Nameless2API $api, AccessToken $token): void { | ||
if (!$token->hasScope('resources.licenses')) { | ||
$api->throwError('oauth2:missing_scope'); | ||
} | ||
|
||
// Make sure user still exist | ||
$user = $token->user(); | ||
if (!$user->exists()) { | ||
$api->throwError(Nameless2API::ERROR_CANNOT_FIND_USER); | ||
} | ||
|
||
// Get user resource licenses | ||
$resources_list = []; | ||
$resources = DB::getInstance()->query('SELECT nl2_resources.id as id, nl2_resources.name as name FROM nl2_resources_payments LEFT JOIN nl2_resources ON nl2_resources.id = nl2_resources_payments.resource_id WHERE nl2_resources_payments.status = 1 AND nl2_resources_payments.user_id = ?', [$token->user()->data()->id]); | ||
foreach ($resources->results() as $resource) { | ||
$resources_list[] = [ | ||
'id' => $resource->id, | ||
'name' => $resource->name | ||
]; | ||
} | ||
|
||
$api->returnArray([ | ||
'resources' => $resources_list | ||
]); | ||
} | ||
} |