Überarbeitete Version der 1. Version. Es bestehen noch grosse Feher in einzelnen Skripten.
This commit is contained in:
71
www/intern/scripts/logindata/ajax-create-otl.php
Normal file
71
www/intern/scripts/logindata/ajax-create-otl.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
|
||||
if (!isset($baseDir)) {
|
||||
$baseDir = $_SERVER['DOCUMENT_ROOT'];
|
||||
}
|
||||
|
||||
require_once $baseDir . '/../scripts/session_functions.php';
|
||||
|
||||
ini_wkvs_session();
|
||||
|
||||
check_user_permission('wk_leitung');
|
||||
|
||||
verify_csrf();
|
||||
|
||||
require $baseDir . '/../scripts/db/db-functions.php';
|
||||
require $baseDir . '/../scripts/db/db-tables.php';
|
||||
|
||||
|
||||
|
||||
$type = 'wkl';
|
||||
|
||||
$dbconnection = require $baseDir . '/../scripts/db/db-verbindung-script.php';
|
||||
|
||||
if ($dbconnection['success'] !== true){
|
||||
echo 'Critical DB Error.';
|
||||
exit;
|
||||
}
|
||||
|
||||
$id = intval($_POST['user_id'] ?? 0);
|
||||
$typeOp = trim($_POST['type'] ?? '');
|
||||
|
||||
$allowedTypesOp = ['login', 'pwreset'];
|
||||
|
||||
if (!in_array($typeOp, $allowedTypesOp)) {
|
||||
echo json_encode(['success' => false, 'message' => 'Operation nicht gestattet']);
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($id <= 0) {
|
||||
echo json_encode(['success' => false, 'message' => 'No valid ID']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Delete old OTL links for this user (recommended)
|
||||
db_delete($mysqli, $tableOTL, ['user_id' => $id]);
|
||||
|
||||
// Insert the row — url + timestamp are auto-generated by MySQL
|
||||
|
||||
$stmt = $mysqli->prepare("INSERT INTO {$tableOTL} (user_id, `type`) VALUES (?, ?)");
|
||||
$stmt->bind_param("is", $id, $typeOp);
|
||||
|
||||
|
||||
if (!$stmt->execute()) {
|
||||
echo json_encode(['success' => false, 'message' => 'Failed to create OTL record']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$row_id = $stmt->insert_id;
|
||||
|
||||
$stmt->close();
|
||||
|
||||
// Now fetch the auto-generated URL
|
||||
$url = db_get_var($mysqli, "SELECT url FROM $tableOTL WHERE id = ? LIMIT 1", [$row_id]);
|
||||
|
||||
if (!$url) {
|
||||
echo json_encode(['success' => false, 'message' => 'Could not fetch generated URL']);
|
||||
exit;
|
||||
}
|
||||
|
||||
echo json_encode(['success' => true, 'url' => $url]);
|
||||
Reference in New Issue
Block a user