togethere.cloud/private_html/account/settings/delete_account.php

93 lines
3.4 KiB
PHP

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/session_bootstrap.php';
if (empty($_SESSION['logged_in'])) {
header('Location: /login/');
exit();
}
$host = "localhost";
$db = "togethere_cloud";
$user = "root";
$pass = "HasloDoSQL";
try {
$pdo->exec("SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci");
} catch (PDOException $e) {
die("Błąd połączenia z bazą danych: " . $e->getMessage());
}
$user_id = $_SESSION['user_id'];
// Pobranie danych użytkownika przed usunięciem (do wysłania potwierdzenia na email)
$stmt = $pdo->prepare("SELECT email, username, first_name, last_name FROM users WHERE id = ?");
$stmt->execute([$user_id]);
$userData = $stmt->fetch(PDO::FETCH_ASSOC);
if (!$userData) {
die("Nie znaleziono użytkownika");
}
try {
// Dezaktywuj konto użytkownika (ustawienie disabled = 1)
// Konto pozostaje w bazie danych, ale użytkownik nie może się zalogować
$stmt = $pdo->prepare("UPDATE users SET disabled = 1, account_suspended = 0 WHERE id = ?");
$stmt->execute([$user_id]);
// Wyślij email potwierdzający usunięcie konta
require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/smtp_helper.php';
$subject = "Konto zostało usunięte - Wspólnie";
$message = "
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<style>
body { font-family: 'Lato', Arial, sans-serif; background: #f0f8ff; padding: 20px; }
.container { max-width: 600px; margin: 0 auto; background: white; padding: 40px; border-radius: 15px; box-shadow: 0 4px 6px rgba(0,0,0,0.1); }
h1 { color: #c62828; text-align: center; }
p { color: #2c3e50; line-height: 1.6; }
.info { background: #ffebee; padding: 15px; border-radius: 8px; margin: 20px 0; border-left: 4px solid #c62828; }
.footer { margin-top: 30px; padding-top: 20px; border-top: 2px solid #e3f2fd; text-align: center; color: #7f8c8d; font-size: 14px; }
</style>
</head>
<body>
<div class='container'>
<h1>👋 Konto zostało usunięte</h1>
<p>Twoje konto w serwisie Wspólnie zostało trwale usunięte.</p>
<div class='info'>
<strong>Usunięte konto:</strong><br>
<strong>Imię i nazwisko:</strong> " . htmlspecialchars($userData['first_name'] . ' ' . $userData['last_name']) . "<br>
<strong>Nazwa użytkownika:</strong> " . htmlspecialchars($userData['username']) . "<br>
<strong>Email:</strong> " . htmlspecialchars($userData['email']) . "
</div>
<p>Wszystkie Twoje dane zostały trwale usunięte z naszej bazy danych.</p>
<p>Jeśli kiedykolwiek zechcesz wrócić, możesz założyć nowe konto.</p>
<p><strong>Jeśli to nie Ty usunąłeś konto, skontaktuj się z nami natychmiast!</strong></p>
<div class='footer'>
<p>&copy; 2026 Wspólnie. Wszelkie prawa zastrzeżone.</p>
</div>
</div>
</body>
</html>
";
sendEmailSMTP($userData['email'], $subject, $message);
// Wyloguj użytkownika
session_unset();
session_destroy();
// Przekieruj na stronę główną z komunikatem
header('Location: /?deleted=1');
exit();
} catch (Exception $e) {
die("Błąd podczas dezaktywacji konta: " . $e->getMessage());
}