Overview
Zoo Arcadia implements a secure authentication system with session-based login, CSRF protection, and automatic session expiration. All authentication is handled through theAuthPagesController.
Login Flow
The authentication process follows these steps:User submits credentials
Users enter their username/email and password on the login page at
/auth/pages/login.CSRF token verification
The system verifies the CSRF token to prevent cross-site request forgery attacks.
Session Management
Session Timeout
Zoo Arcadia implements automatic session expiration for security:- Timeout Duration: 11 hours (39,600 seconds)
- Check Location:
App/router.php:92-99 - Behavior: Sessions are automatically expired after 11 hours of inactivity
Session Data Structure
When a user logs in, the session stores:Authentication status (always
true when logged in)User information including:
id_user: User IDusername: Usernamerole_name: Role name (Admin, Veterinary, Employee)employee_id: Associated employee IDpermissions: Array of permission strings
Unix timestamp of the last activity (updated on each request)
Security Features
CSRF Protection
All forms use CSRF tokens to prevent cross-site request forgery:CSRF tokens are unique per form and prevent unauthorized form submissions from external sites.
Input Validation
The system validates and sanitizes all inputs:Secure Session Cookies
Session cookies are configured with security flags:httponly: Prevents JavaScript access to cookiessecure: Ensures cookies are only sent over HTTPS (in production)pathanddomain: Restricts cookie scope
Logout Process
The logout process (/auth/pages/logout) thoroughly cleans up the session:
Error Handling
The system provides clear error messages for common issues:Login Errors
Login Errors
- User not found: “User not found or password incorrect.”
- Incorrect password: Redirects to login without specific message (security)
- Deactivated account: “Your account is deactivated. Please contact the administrator.”
- Session expired: “msg=session_expired” in URL
- Invalid CSRF token: “Invalid request. Please try again.”
Code Reference
The authentication system is implemented in:- Controller:
App/auth/controllers/auth_pages_controller.php:30-151 - User Model:
App/users/models/user.php:100-129(find user) - Permissions:
App/users/models/user.php:376-409(load permissions) - Session Check:
App/router.php:92-99(timeout validation)
All authenticated routes should check
$_SESSION['loggedin'] and validate permissions before allowing access to protected resources.