上传文件至 /
This commit is contained in:
20
generate-api-key.php
Normal file
20
generate-api-key.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
require_once 'config.php';
|
||||
|
||||
if (!isset($_SESSION['user_id'])) {
|
||||
header('Location: login.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$api_key = bin2hex(random_bytes(API_KEY_LENGTH / 2));
|
||||
$stmt = $pdo->prepare("UPDATE users SET api_key = ? WHERE id = ?");
|
||||
|
||||
if ($stmt->execute([$api_key, $_SESSION['user_id']])) {
|
||||
$_SESSION['success'] = t('api_key_generated');
|
||||
} else {
|
||||
$_SESSION['error'] = t('api_key_generation_failed');
|
||||
}
|
||||
|
||||
header('Location: ' . ($_SERVER['HTTP_REFERER'] ?? 'dashboard.php'));
|
||||
exit;
|
||||
?>
|
||||
Reference in New Issue
Block a user