20 lines
495 B
PHP
20 lines
495 B
PHP
<?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;
|
|
?>
|