prepare intranet for first Dokploy deployment
This commit is contained in:
@@ -0,0 +1,118 @@
|
||||
<?php /* Name: signup-process.php
|
||||
Beschreibung: Vereinte Registrierungs-Verarbeitung
|
||||
- Prüft ob Nutzer vorregistriert ist → direkte Registrierung
|
||||
- Wenn nicht → automatisch Antrag in pending_registrations + Mail an Admin */
|
||||
|
||||
$pdo = require_once($_SERVER['DOCUMENT_ROOT']."/intranet_repo/general_files/ini/database.php");
|
||||
require_once $_SERVER['DOCUMENT_ROOT'].'/intranet_repo/general_files/ini/send_mail.php';
|
||||
|
||||
// === Validierung ===
|
||||
if (empty($_POST["first_name"])) {
|
||||
die("Vorname ist erforderlich.");
|
||||
}
|
||||
if (empty($_POST["last_name"])) {
|
||||
die("Nachname ist erforderlich.");
|
||||
}
|
||||
if (!filter_var($_POST["email"], FILTER_VALIDATE_EMAIL)) {
|
||||
die("Gültige E-Mail-Adresse erforderlich.");
|
||||
}
|
||||
if (empty($_POST["phone"])) {
|
||||
die("Telefonnummer ist erforderlich.");
|
||||
}
|
||||
if (strlen($_POST["password"]) < 8) {
|
||||
die("Passwort muss mindestens 8 Zeichen lang sein.");
|
||||
}
|
||||
if (!preg_match("/[a-z]/i", $_POST["password"])) {
|
||||
die("Passwort muss mindestens einen Buchstaben enthalten.");
|
||||
}
|
||||
if (!preg_match("/[0-9]/", $_POST["password"])) {
|
||||
die("Passwort muss mindestens eine Zahl enthalten.");
|
||||
}
|
||||
if ($_POST["password"] !== $_POST["password_confirmation"]) {
|
||||
die("Passwörter stimmen nicht überein.");
|
||||
}
|
||||
|
||||
$email = trim($_POST["email"]);
|
||||
$first_name = trim($_POST["first_name"]);
|
||||
$last_name = trim($_POST["last_name"]);
|
||||
$phone = preg_replace('/[^0-9]/', '', trim($_POST["phone"]));
|
||||
$password_hash = password_hash($_POST["password"], PASSWORD_DEFAULT);
|
||||
|
||||
// === Prüfung 1: Ist der Nutzer vom Admin vorregistriert? ===
|
||||
$stmt = $pdo->prepare("SELECT user_id FROM user_general_information WHERE mail = ?");
|
||||
$stmt->execute([$email]);
|
||||
$user_id = $stmt->fetchColumn();
|
||||
|
||||
if ($user_id) {
|
||||
// Nutzer ist vorregistriert – prüfen ob bereits Login existiert
|
||||
$stmt = $pdo->prepare("SELECT COUNT(*) FROM user_login WHERE user_id = ?");
|
||||
$stmt->execute([$user_id]);
|
||||
$loginExists = $stmt->fetchColumn();
|
||||
|
||||
if ($loginExists > 0) {
|
||||
// Bereits vollständig registriert
|
||||
header("Location: signup.php?error=2");
|
||||
exit;
|
||||
}
|
||||
|
||||
// Direkte Registrierung durchführen
|
||||
$stmt = $pdo->prepare("INSERT INTO user_login (user_id, password_hash) VALUES (?, ?)");
|
||||
|
||||
if ($stmt->execute([$user_id, $password_hash])) {
|
||||
|
||||
// Namen und Telefonnummer aktualisieren
|
||||
$stmt = $pdo->prepare("UPDATE user_general_information SET first_name=?, last_name=?, phone=? WHERE user_id=?");
|
||||
$stmt->execute([$first_name, $last_name, $phone, $user_id]);
|
||||
|
||||
header("Location: login.php");
|
||||
exit;
|
||||
} else {
|
||||
header("Location: signup.php?error=1");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
// === Prüfung 2: Liegt bereits ein Antrag vor? ===
|
||||
$stmt = $pdo->prepare("SELECT COUNT(*) FROM pending_registrations WHERE email = ? AND status = 'pending'");
|
||||
$stmt->execute([$email]);
|
||||
$pendingCount = $stmt->fetchColumn();
|
||||
|
||||
if ($pendingCount > 0) {
|
||||
header("Location: signup.php?error=2");
|
||||
exit;
|
||||
}
|
||||
|
||||
// === Antrag stellen (Nutzer nicht vorregistriert) ===
|
||||
$token = bin2hex(random_bytes(32));
|
||||
|
||||
$stmt = $pdo->prepare("INSERT INTO pending_registrations (first_name, last_name, email, phone, password_hash, token) VALUES (?, ?, ?, ?, ?, ?)");
|
||||
|
||||
if (!$stmt->execute([$first_name, $last_name, $email, $phone, $password_hash, $token])) {
|
||||
header("Location: signup.php?error=1");
|
||||
exit;
|
||||
}
|
||||
$pending_id = $pdo->lastInsertId();
|
||||
|
||||
// Admin-Nachricht in Inbox speichern
|
||||
$subject = "Neue Registrierungsanfrage: {$first_name} {$last_name}";
|
||||
$message_text = "Neue Registrierungsanfrage:\n\nName: {$first_name} {$last_name}\nE-Mail: {$email}\n\nBitte im Adminpanel freischalten.";
|
||||
$data_json = json_encode(['pending_id' => $pending_id, 'token' => $token]);
|
||||
|
||||
$stmt = $pdo->prepare("INSERT INTO admin_messages (type, sender_name, sender_email, subject, message, data_json) VALUES ('registration', ?, ?, ?, ?, ?)");
|
||||
$sender_name = "{$first_name} {$last_name}";
|
||||
$stmt->execute([$sender_name, $email, $subject, $message_text, $data_json]);
|
||||
|
||||
// Mail an Admin-Team (Admin + Technik)
|
||||
$mail_betreff = "Neue Registrierungsanfrage von {$first_name} {$last_name}";
|
||||
$mail_nachricht = "Es liegt eine neue Registrierungsanfrage vor:\n\n";
|
||||
$mail_nachricht .= "Name: {$first_name} {$last_name}\n";
|
||||
$mail_nachricht .= "E-Mail: {$email}\n";
|
||||
$mail_nachricht .= "Telefon: {$phone}\n\n";
|
||||
$mail_nachricht .= "Bitte melden Sie sich im Adminpanel an, um die Anfrage zu bearbeiten.";
|
||||
|
||||
send_admin_team_mail($pdo, $mail_betreff, $mail_nachricht, "Im Adminpanel bearbeiten", "https://" . ($_SERVER['HTTP_HOST'] ?? intranet_env('INTRANET_FQDN')) . "/intranet_repo/projects/adminpanel/admin_inbox.php");
|
||||
|
||||
// Erfolg – gleiche Meldung wie bei direkter Registrierung (Nutzer merkt keinen Unterschied)
|
||||
header("Location: signup.php?success=1");
|
||||
exit;
|
||||
?>
|
||||
Reference in New Issue
Block a user