Add admin_update_user API endpoint
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
19
api.php
19
api.php
@@ -889,6 +889,25 @@ switch ($action) {
|
|||||||
}
|
}
|
||||||
ok(['users' => $result]);
|
ok(['users' => $result]);
|
||||||
|
|
||||||
|
case 'admin_update_user':
|
||||||
|
if (!isAdmin()) err('Unauthorized', 403);
|
||||||
|
$userId = $body['userId'] ?? '';
|
||||||
|
if (!$userId) err('Missing userId');
|
||||||
|
$users = readData('users.json', []);
|
||||||
|
$found = false;
|
||||||
|
foreach ($users as &$u) {
|
||||||
|
if ($u['id'] === $userId) {
|
||||||
|
if (isset($body['email'])) $u['email'] = htmlspecialchars(trim($body['email']), ENT_QUOTES | ENT_HTML5, 'UTF-8');
|
||||||
|
if (isset($body['nickname'])) $u['nickname'] = htmlspecialchars(trim($body['nickname']), ENT_QUOTES | ENT_HTML5, 'UTF-8');
|
||||||
|
$found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
unset($u);
|
||||||
|
if (!$found) err('User not found');
|
||||||
|
writeData('users.json', $users);
|
||||||
|
ok();
|
||||||
|
|
||||||
// ─── Käyttäjätunnukset ─────────────────────────────────────
|
// ─── Käyttäjätunnukset ─────────────────────────────────────
|
||||||
case 'user_register':
|
case 'user_register':
|
||||||
$nickname = trim($body['nickname'] ?? '');
|
$nickname = trim($body['nickname'] ?? '');
|
||||||
|
|||||||
Reference in New Issue
Block a user