getRequestData(); $password = $data['password'] ?? ''; if (empty($password)) { $this->errorResponse('Password is required'); return; } try { if ($this->security->authenticate($password)) { $this->successResponse([ 'authenticated' => true, 'csrf_token' => $this->security->generateCSRFToken(), 'redirect' => '/dashboard' ]); } else { $this->errorResponse('Invalid password', 401); } } catch (\Exception $e) { $this->errorResponse($e->getMessage(), 401); } } public function logout(): void { $this->security->logout(); $this->successResponse(['logged_out' => true]); } public function status(): void { // Use the working direct output but with proper API structure $token = $this->security->generateCSRFToken(); $data = [ 'authenticated' => $this->security->isAuthenticated(), 'csrf_token' => $token ]; $response = ['success' => true, 'data' => $data]; header('Content-Type: application/json'); echo json_encode($response); exit; } }