set('title', 'تسجيل الدخول'); $this->render('auth/login'); } /** * Handle login submission */ public function authenticate() { if ($_SERVER['REQUEST_METHOD'] !== 'POST') { $this->redirect('/auth/login'); return; } $email = $_POST['email'] ?? ''; $password = $_POST['password'] ?? ''; $token = $_POST['_token'] ?? ''; if (!$this->validateCsrf($token)) { $this->session->flash('error', 'رمز الأمان غير صالح'); $this->redirect('/auth/login'); return; } if ($this->auth->attempt($email, $password)) { $this->session->flash('success', 'تم تسجيل الدخول بنجاح'); $this->redirect('/'); } else { $this->session->flash('error', 'البريد الإلكتروني أو كلمة المرور غير صحيحة'); $this->redirect('/auth/login'); } } /** * Handle logout */ public function logout() { if ($_SERVER['REQUEST_METHOD'] !== 'POST') { $this->redirect('/'); return; } $token = $_POST['_token'] ?? ''; if (!$this->validateCsrf($token)) { $this->session->flash('error', 'رمز الأمان غير صالح'); $this->redirect('/'); return; } $this->auth->logout(); $this->session->flash('success', 'تم تسجيل الخروج بنجاح'); $this->redirect('/'); }}