Add names to API tokens.
This commit is contained in:
@@ -37,9 +37,14 @@ if ($API_apitoken->request_method === 'GET') {
|
||||
# Creates a new API Token. First check if the uuid is correct and then check the permission
|
||||
# After that create a new token, retrieve the newly created api_token and give a response.
|
||||
$requiredFields = [
|
||||
'user_uuid' => ['type' => 'uuid'],
|
||||
'user_uuid' => ['type' => 'uuid']
|
||||
];
|
||||
$API_apitoken->validateData($requiredFields);
|
||||
|
||||
$optionalFields = [
|
||||
'api_token_name' => ['type' => 'string']
|
||||
];
|
||||
|
||||
$API_apitoken->validateData($requiredFields, $optionalFields);
|
||||
|
||||
# First retrieve the user_uuid from the post and lookup the user
|
||||
require_once $_SERVER['DOCUMENT_ROOT'] . '/api/classes/API_users.php';
|
||||
@@ -48,8 +53,6 @@ if ($API_apitoken->request_method === 'GET') {
|
||||
$_GET['builder'] = [1 => ['where' => [0 => 'user_uuid', 1 => $API_apitoken->data['user_uuid']]]];
|
||||
$user_data = $API_users->getUser()[0];
|
||||
|
||||
$API_apitoken->validateData($requiredFields);
|
||||
|
||||
if ($API_apitoken->getUserUuid() === $API_apitoken->data['user_uuid']) {
|
||||
$API_apitoken->checkPermissions('user-apitoken-self', 'RW');
|
||||
|
||||
@@ -57,6 +60,7 @@ if ($API_apitoken->request_method === 'GET') {
|
||||
if ($user_data['user_email'] === 'superuser') {
|
||||
$API_apitoken->apiOutput(401, ['error' => 'You are not authorized to access this resource.']);
|
||||
}
|
||||
|
||||
$API_apitoken->checkPermissions('user-apitoken-others', 'RW');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user