Authentication — Spec¶
Overview¶
Multi-user login with admin-approval flow. New accounts are inactive until an admin approves them.
Password Storage¶
- Passwords hashed with bcrypt; no plaintext stored
Sessions¶
- Persistent sessions: a
UserSessiontoken is stored in the DB and set as a browser cookie (mp_session) on login - Cookie:
httponly; samesite=lax; 30-day TTL - Subsequent page loads restore the session without requiring re-login
- Sign Out deletes the DB session row and clears the browser cookie
User Roles¶
- Regular user: can view all data, upload portfolio
- Admin: can approve new users, add/remove tickers, trigger pipeline runs
Registration Flow¶
- User registers — account created with
is_active=False - Admin sets
is_active=Trueto approve - Login returns 403 with "Account pending approval" for inactive users
Constraints¶
- Session tokens:
secrets.token_urlsafe(32) - Expired sessions deleted on first access
- One
UserSessionrow per active session; cascade-deleted when user is deleted