// File: public/register.php declare(strict_types=1); require_once dirname(__DIR__) . '/app/Core/Init.php'; require_once dirname(__DIR__) . '/views/components/auth_layout.php'; use App\Core\Auth; use App\Core\Session; use App\Repositories\UserRepository; if (Auth::check()) { header('Location: /index.php'); exit; } $repo = new UserRepository(); $settings = $repo->getSystemSettings(); if ((int)$settings['register_closed'] === 1 && !isset($_GET['test'])) { Session::set('flash_success', 'التسجيل في المنصة مغلق حالياً حتى إشعار آخر.'); header('Location: /login.php'); exit; } $errorMsg = ''; $old = [ 'fullname' => '', 'username' => '', 'email' => '', 'phone' => '' ]; if ($_SERVER['REQUEST_METHOD'] === 'POST') { if (!Session::validateCsrf($_POST['csrf_token'] ?? null)) { $errorMsg = 'انتهت صلاحية الجلسة، يرجى تحديث الصفحة والمحاولة مجدداً.'; } else { $old['fullname'] = trim((string)($_POST['fullname'] ?? '')); $old['username'] = trim((string)($_POST['uname'] ?? '')); $old['email'] = trim((string)($_POST['email'] ?? '')); $old['phone'] = trim((string)($_POST['phone'] ?? '')); $result = Auth::register([ 'fullname' => $old['fullname'], 'username' => $old['username'], 'email' => $old['email'], 'phone' => $old['phone'], 'password' => (string)($_POST['pass'] ?? ''), 'confirm_password' => (string)($_POST['cpass'] ?? ''), 'browser_timezone' => (string)($_POST['browser_timezone'] ?? ''), 'website_url' => (string)($_POST['website_url'] ?? '') ]); if ($result['status'] === 'success') { header('Location: ' . ($result['redirect'] ?? '/verify.php')); exit; } $errorMsg = $result['message']; } } $extraHead = << HTML; render_auth_header('تسجيل حساب جديد', $extraHead); ?>