| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- <?php
- // Αρχείο: /var/www/html/hockey-cms/register.php
- if (session_status() === PHP_SESSION_NONE) { session_start(); }
- require_once __DIR__ . '/vendor/autoload.php';
- require_once __DIR__ . '/config/database.php';
- // Αν είναι ήδη συνδεδεμένος, πάει αρχική
- if (isset($_SESSION['user_id'])) {
- header("Location: index.php");
- exit;
- }
- // --- Μηχανισμός Αλλαγής Γλώσσας ---
- if (isset($_GET['lang']) && in_array($_GET['lang'], ['el', 'en'])) {
- $_SESSION['lang'] = $_GET['lang'];
- }
- $current_lang = $_SESSION['lang'] ?? 'el';
- // --- Εύρεση Ενεργού Theme ---
- $active_theme = 'default';
- try {
- $stmt = $pdo->query("SELECT * FROM settings");
- while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
- if (isset($row['key']) && $row['key'] === 'active_theme' && !empty($row['value'])) {
- $active_theme = trim($row['value']);
- }
- }
- } catch (Exception $e) {}
- $theme_dir = __DIR__ . '/themes/' . $active_theme;
- if (!is_dir($theme_dir)) {
- $active_theme = 'default';
- $theme_dir = __DIR__ . '/themes/default';
- }
- // --- Αρχικοποίηση Twig ---
- $loader = new \Twig\Loader\FilesystemLoader($theme_dir);
- $twig = new \Twig\Environment($loader, ['cache' => false]);
- $twig->addGlobal('session', $_SESSION);
- $twig->addGlobal('current_lang', $current_lang);
- // --- Φόρτωση Δυναμικών Κειμένων Site ---
- $siteTexts = [];
- try {
- $text_column = ($current_lang === 'en') ? 'text_value_en' : 'text_value_el';
- $textsStmt = $pdo->query("SELECT text_key, {$text_column} as text_value FROM site_texts");
- while ($row = $textsStmt->fetch(PDO::FETCH_ASSOC)) {
- $siteTexts[$row['text_key']] = $row['text_value'];
- }
- } catch (Exception $e) {}
- $twig->addGlobal('text', $siteTexts);
- // --- Φόρτωση Logo Site ---
- $site_logo = '';
- try {
- $stmtSettings = $pdo->query("SELECT * FROM settings");
- while ($row = $stmtSettings->fetch(PDO::FETCH_ASSOC)) {
- if (isset($row['key']) && $row['key'] === 'site_logo') {
- $site_logo = $row['value'];
- }
- }
- } catch (Exception $e) {}
- $twig->addGlobal('site_logo', $site_logo);
- // --- Μεταφράσεις ---
- $translations = [
- 'el' => [
- 'title' => 'Νέα Εγγραφή',
- 'fname' => 'Όνομα *',
- 'lname' => 'Επίθετο *',
- 'username' => 'Διάλεξε Username *',
- 'email' => 'Το Email σου *',
- 'phone' => 'Τηλέφωνο (Προαιρετικό)',
- 'password' => 'Κωδικός *',
- 'btn_register' => 'Δημιουργία Λογαριασμού',
- 'btn_google' => 'Εγγραφή με Google',
- 'already_have' => 'Έχετε ήδη λογαριασμό;',
- 'login' => 'Σύνδεση',
- 'err_exists' => 'Το Όνομα Χρήστη ή το Email υπάρχει ήδη!',
- 'err_general' => 'Σφάλμα κατά την εγγραφή. Δοκιμάστε ξανά.',
- 'err_req_fields' => 'Παρακαλώ συμπληρώστε όλα τα υποχρεωτικά πεδία!',
- 'err_captcha' => 'Λάθος αποτέλεσμα στην επαλήθευση (CAPTCHA)!',
- 'success' => 'Η εγγραφή ολοκληρώθηκε! Μπορείτε να συνδεθείτε.',
- 'captcha_label' => 'Επαλήθευση: Πόσο κάνει ',
- 'captcha_ph' => 'Αποτέλεσμα...'
- ],
- 'en' => [
- 'title' => 'Create Account',
- 'fname' => 'First Name *',
- 'lname' => 'Last Name *',
- 'username' => 'Choose Username *',
- 'email' => 'Email Address *',
- 'phone' => 'Phone (Optional)',
- 'password' => 'Password *',
- 'btn_register' => 'Register',
- 'btn_google' => 'Sign up with Google',
- 'already_have' => 'Already have an account?',
- 'login' => 'Login',
- 'err_exists' => 'Username or Email already exists!',
- 'err_general' => 'Registration error. Please try again.',
- 'err_req_fields' => 'Please fill in all required fields!',
- 'err_captcha' => 'Incorrect verification result (CAPTCHA)!',
- 'success' => 'Registration complete! You can now login.',
- 'captcha_label' => 'Verification: How much is ',
- 'captcha_ph' => 'Result...'
- ]
- ];
- $t = $translations[$current_lang];
- $message = '';
- if ($_SERVER['REQUEST_METHOD'] === 'POST') {
- $first_name = trim($_POST['reg_first_name'] ?? '');
- $last_name = trim($_POST['reg_last_name'] ?? '');
- $username = trim($_POST['reg_username'] ?? '');
- $email = trim($_POST['reg_email'] ?? '');
- $phone = trim($_POST['reg_phone'] ?? '');
- $password = $_POST['reg_password'] ?? '';
- $captcha_answer = isset($_POST['reg_captcha']) ? (int)$_POST['reg_captcha'] : -1;
- $expected_captcha = $_SESSION['captcha_result'] ?? -2;
-
- if (empty($first_name) || empty($last_name) || empty($username) || empty($email) || empty($password)) {
- $message = "<div style='padding: 12px; border-radius: 6px; margin-bottom: 15px; font-size: 13px; text-align: center; font-weight: 600; background: rgba(239, 68, 68, 0.1); color: #ef4444; border: 1px solid rgba(239, 68, 68, 0.2);'>" . $t['err_req_fields'] . "</div>";
- } elseif ($captcha_answer !== $expected_captcha) {
- $message = "<div style='padding: 12px; border-radius: 6px; margin-bottom: 15px; font-size: 13px; text-align: center; font-weight: 600; background: rgba(239, 68, 68, 0.1); color: #ef4444; border: 1px solid rgba(239, 68, 68, 0.2);'>" . $t['err_captcha'] . "</div>";
- } else {
- $check = $pdo->prepare("SELECT id FROM users WHERE username = ? OR email = ?");
- $check->execute([$username, $email]);
-
- if ($check->fetch()) {
- $message = "<div style='padding: 12px; border-radius: 6px; margin-bottom: 15px; font-size: 13px; text-align: center; font-weight: 600; background: rgba(239, 68, 68, 0.1); color: #ef4444; border: 1px solid rgba(239, 68, 68, 0.2);'>" . $t['err_exists'] . "</div>";
- } else {
- $hashed = password_hash($password, PASSWORD_DEFAULT);
- $stmt = $pdo->prepare("INSERT INTO users (first_name, last_name, username, email, phone, password, role_id, is_seller) VALUES (?, ?, ?, ?, ?, ?, 3, 0)");
-
- if ($stmt->execute([$first_name, $last_name, $username, $email, $phone, $hashed])) {
- $message = "<div style='padding: 12px; border-radius: 6px; margin-bottom: 15px; font-size: 13px; text-align: center; font-weight: 600; background: rgba(16, 185, 129, 0.1); color: #10b981; border: 1px solid rgba(16, 185, 129, 0.2);'>" . $t['success'] . "</div>";
- } else {
- $message = "<div style='padding: 12px; border-radius: 6px; margin-bottom: 15px; font-size: 13px; text-align: center; font-weight: 600; background: rgba(239, 68, 68, 0.1); color: #ef4444; border: 1px solid rgba(239, 68, 68, 0.2);'>" . $t['err_general'] . "</div>";
- }
- }
- }
- }
- // CAPTCHA
- $num1 = rand(1, 10);
- $num2 = rand(1, 10);
- $_SESSION['captcha_result'] = $num1 + $num2;
- $captcha_text = $num1 . " + " . $num2;
- echo $twig->render('register.html.twig', [
- 't' => $t,
- 'current_lang' => $current_lang,
- 'message' => $message,
- 'captcha_text' => $captcha_text
- ]);
|