Overview
Authentication routes handle user login, registration, and logout operations. All routes include rate limiting for security.Login
Handle user login process
User’s email address
User’s password
Whether to remember the user’s session
- On success: Redirects to
main.home - On failure: Redirects back to login with error message
- For authenticated users: Redirects to
main.home
- POST requests: 5 per minute, 20 per hour per IP
Register
Handle user registration process
User’s first name (no whitespace allowed)
User’s last name (no whitespace allowed)
User’s email address (must be unique, no whitespace)
User’s password (will be hashed)
School year (7, 8, 9, 10, 11, 12, or 13)
User’s maths class
- Names and email are checked for profanity
- Email must be unique in the database
- Whitespace is not allowed in names or email
- Year is mapped to key stage automatically:
- Years 7-8: KS3
- Years 9-11: KS4
- Years 12-13: KS5
- On success: Redirects to
auth.loginwith success message - On failure: Redirects back to register with error message
- POST requests: 3 per minute, 10 per hour per IP
Admin Registration
Handle admin user registration (disabled in production)
- Sets
is_admin=Trueon created user - In production: Redirects to
main.homewith warning message
- POST requests: 2 per minute, 5 per hour per IP
Autumn Competition Registration
Handle user registration for autumn competition
User’s first name
User’s last name
User’s email address (must be unique)
User’s password
School year (7-13)
ID of the user’s school (from School model)
- Sets
is_competition_participant=True - Assigns user to selected school
- School choices populated from database
- On success: Redirects to
auth.summer_login - On failure: Redirects back with error message
Autumn Competition Login
Handle login for autumn competition participants
User’s email address
User’s password
User’s school ID (displayed in dropdown)
Whether to remember the session
- On success: Redirects to
main.home - On failure: Redirects to
auth.loginwith error
Logout
Handle user logout process
- Always redirects to
main.home - Terminates current user session via
logout_user()
Security Features
All authentication routes implement:- Password Hashing: Passwords are hashed before database storage
- Profanity Filtering: User names and emails checked using Better Profanity
- Rate Limiting: Per-IP limits on all POST endpoints
- Duplicate Prevention: Email uniqueness enforced
- Whitespace Validation: Names and emails must not contain spaces
- Admin Protection: Admin registration disabled in production