98 lines
3.7 KiB
PHP
98 lines
3.7 KiB
PHP
<?php /* Name: self-signup-process.php
|
|
Beschreibung: Verarbeitung der Selbstregistrierung
|
|
- Validierung der Eingaben
|
|
- Speicherung in pending_registrations
|
|
- Mail an Admin (samuel.bias@aol.de)
|
|
- Eintrag in admin_messages */
|
|
|
|
$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 (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"]);
|
|
|
|
// Prüfen ob E-Mail bereits existiert (in user_general_information oder pending_registrations)
|
|
$checkSql = "SELECT COUNT(*) FROM user_general_information WHERE mail = ?";
|
|
$stmt = $pdo->prepare($checkSql);
|
|
$stmt->execute([$email]);
|
|
$count1 = $stmt->fetchColumn();
|
|
|
|
$checkSql2 = "SELECT COUNT(*) FROM pending_registrations WHERE email = ? AND status = 'pending'";
|
|
$stmt2 = $pdo->prepare($checkSql2);
|
|
$stmt2->execute([$email]);
|
|
$count2 = $stmt2->fetchColumn();
|
|
|
|
if ($count1 > 0 || $count2 > 0) {
|
|
header("Location: self-signup.php?error=2");
|
|
exit;
|
|
}
|
|
|
|
// Passwort hashen und Token generieren
|
|
$password_hash = password_hash($_POST["password"], PASSWORD_DEFAULT);
|
|
$token = bin2hex(random_bytes(32));
|
|
|
|
// In pending_registrations speichern
|
|
$insertSql = "INSERT INTO pending_registrations (first_name, last_name, email, password_hash, token) VALUES (?, ?, ?, ?, ?)";
|
|
$stmt = $pdo->prepare($insertSql);
|
|
if (!$stmt) {
|
|
header("Location: self-signup.php?error=1");
|
|
exit;
|
|
}
|
|
|
|
if (!$stmt->execute([$first_name, $last_name, $email, $password_hash, $token])) {
|
|
header("Location: self-signup.php?error=1");
|
|
exit;
|
|
}
|
|
$pending_id = $pdo->lastInsertId();
|
|
|
|
// Admin-Nachricht in Inbox speichern
|
|
$subject = "Neue Registrierungsanfrage: {$first_name} {$last_name}";
|
|
$message_text = "Neue Selbstregistrierung:\n\nName: {$first_name} {$last_name}\nE-Mail: {$email}\n\nBitte im Adminpanel freischalten.";
|
|
$data_json = json_encode(['pending_id' => $pending_id, 'token' => $token]);
|
|
|
|
$inboxSql = "INSERT INTO admin_messages (type, sender_name, sender_email, subject, message, data_json) VALUES ('registration', ?, ?, ?, ?, ?)";
|
|
$stmt = $pdo->prepare($inboxSql);
|
|
$sender_name = "{$first_name} {$last_name}";
|
|
$stmt->execute([$sender_name, $email, $subject, $message_text, $data_json]);
|
|
|
|
// Mail an Admin-Team (Admin + Technik)
|
|
$admin_email = ADMIN_EMAIL;
|
|
$mail_betreff = "Intranet: Neue Registrierungsanfrage von {$first_name} {$last_name}";
|
|
$mail_nachricht = "Hallo Admin,\n\n";
|
|
$mail_nachricht .= "Es liegt eine neue Registrierungsanfrage vor:\n\n";
|
|
$mail_nachricht .= "Name: {$first_name} {$last_name}\n";
|
|
$mail_nachricht .= "E-Mail: {$email}\n\n";
|
|
$mail_nachricht .= "Bitte melden Sie sich im Adminpanel an, um die Anfrage zu bearbeiten.\n\n";
|
|
$mail_nachricht .= "-- Intranet NAK Reinickendorf";
|
|
|
|
send_admin_team_mail($pdo, $mail_betreff, $mail_nachricht);
|
|
|
|
// Erfolg
|
|
header("Location: self-signup.php?success=1");
|
|
exit;
|
|
?>
|