# Spec Delta ## Purpose Staff log in to the Co-Lite admin portal, and every admin page and `/api/admin/**` endpoint admits only active staff holding the module it needs. ## ADDED Requirements ### Requirement: Staff login The system SHALL let an active admin user log in with username and password through the admin portal, and SHALL return the user's name, roles, menu and whether a password change is required. #### Scenario: Correct credentials - **GIVEN** an active admin user `admin` with password `colite-dev-admin` - **WHEN** they submit those credentials on the login page - **THEN** they are signed in and land on the portal home - **AND** the sidebar shows only the menu entries their roles grant #### Scenario: Wrong password - **WHEN** a user submits a wrong password - **THEN** `/api/admin/auth/login` responds 401 - **AND** the login page shows an invalid-credentials message without saying whether the username exists #### Scenario: Deactivated user - **GIVEN** an admin user whose account is deactivated - **WHEN** they submit their correct password - **THEN** login is refused with a 401 and the page shows the same invalid-credentials message #### Scenario: Member account - **WHEN** a member (non-admin) account submits its correct credentials to the admin login - **THEN** login is refused with a 401 ### Requirement: First-login password change The system SHALL require a user whose password is temporary (new user or reset) to set a new password before using any other admin page or endpoint. #### Scenario: Pending change confines the session - **GIVEN** a user logged in with a temporary password - **WHEN** they open any portal page other than the password-change page - **THEN** they are sent to the password-change page - **AND** any `/api/admin/**` call other than first-login and logout responds 403 #### Scenario: Password changed - **GIVEN** a user on the password-change page - **WHEN** they submit a new password that meets the password rules - **THEN** the password is saved, the temporary flag clears, and they can use the portal ### Requirement: Forgot password The system SHALL let a user request a temporary password by entering their username and email on a public forgot-password page. The response SHALL be the same whether or not the username and email match an active admin user. #### Scenario: Matching username and email - **GIVEN** an active admin user with username `sales1` and email `sales1@example.com` - **WHEN** someone submits `sales1` and `sales1@example.com` - **THEN** a temporary password is emailed to `sales1@example.com` - **AND** the user must change it at next login - **AND** the page shows "If the details match an account, we have emailed a temporary password." #### Scenario: Non-matching details - **WHEN** someone submits a username and email that do not match an active admin user - **THEN** no password changes and no email is sent - **AND** the page shows the same message as for a match ### Requirement: Logout The system SHALL end the session on logout, and SHALL reject the logged-out token on every later `/api/admin/**` call even before it expires. #### Scenario: Token used after logout - **GIVEN** a user who logged out - **WHEN** a request reuses their old token on `/api/admin/me` - **THEN** it responds 401 ### Requirement: Admin endpoint guard Every `/api/admin/**` endpoint except login and forgot password SHALL require a valid admin token, and SHALL require at least one of the back-office modules the endpoint declares, granted to one of the caller's roles. A user with the super admin role SHALL pass every module check. An endpoint that declares no module SHALL be denied to everyone except super admin. #### Scenario: No token - **WHEN** `/api/admin/users` is called without a token - **THEN** it responds 401 #### Scenario: Member token on an admin path - **WHEN** a valid member token calls `/api/admin/me` - **THEN** it responds 403 #### Scenario: Missing module - **GIVEN** an admin user whose roles do not grant `BO_USERS` - **WHEN** they call `GET /api/admin/users` - **THEN** it responds 403 #### Scenario: Granted module - **GIVEN** an admin user whose role grants `BO_USERS` - **WHEN** they call `GET /api/admin/users` - **THEN** it responds 200 ### Requirement: Page guard The admin portal SHALL show a not-authorised page when a signed-in user opens a page whose module their roles do not grant, and SHALL send a signed-out visitor to the login page for every page except login and forgot password. #### Scenario: Signed-out visitor - **WHEN** a signed-out visitor opens `/users` - **THEN** they are sent to the login page and return to `/users` after logging in #### Scenario: Page without the module - **GIVEN** a signed-in user without `BO_ROLES` - **WHEN** they open `/roles` - **THEN** the not-authorised page is shown and no role data is loaded