Authentication and Accounts
Authentication is provided uniformly by the backend, and the frontend carries the token via Authorization: Bearer <token>.
Endpoints
Section titled “Endpoints”| Method | Path | Description | Auth |
|---|---|---|---|
| POST | /api/auth/login |
Log in | No |
| POST | /api/auth/register |
Register | No |
| POST | /api/auth/logout |
Log out (revokes the current token immediately) | Yes |
On success, the backend returns a token and user information (including permission codes and roles); the frontend stores the token and enters the admin panel. On failure, it returns a Chinese error message and records an audit log.
Registration
Section titled “Registration”Registration behavior is controlled by two system settings:
- When open registration (
openRegistration) isfalse, the registration endpoint returns “Registration is closed” (注册已关闭). - When manual review (
manualReview) istrue, new accounts are assigned thepending_reviewrole, and the endpoint returns only “Registration successful, please wait for administrator approval” (注册成功,请等待管理员审核), without issuing a token; whenfalse, the account is directly assigned theuserrole and logged in automatically.
Rate Limiting
Section titled “Rate Limiting”Login and registration are limited by IP: at most 5 times per minute. Exceeding this returns:
- Login: “Too many login attempts, please try again later” (登录尝试过于频繁,请稍后再试)
- Registration: “Too many registration attempts, please try again later” (注册尝试过于频繁,请稍后再试)
The limit is enforced before credential validation. IP resolution order is X-Real-IP (set by Nginx, cannot be forged) → first entry of X-Forwarded-For → direct connection address.
Maintenance Mode
Section titled “Maintenance Mode”Administrators can enable maintenance mode in system settings. Once enabled:
- Non-admin logins are rejected and return the custom maintenance message (“System under maintenance” (系统维护中) if none is configured).
- Administrators can still log in normally so they can turn maintenance mode off.
Tokens and Logout
Section titled “Tokens and Logout”| Python | Java | |
|---|---|---|
| Token type | JWT (PyJWT, HS256) | Sa-Token UUID session token |
| Validity | 24 hours by default | 86400 seconds by default |
| Logout | Requires login; bumps the user token version to invalidate existing tokens | Requires login; revokes every server-side session for the user |
Logout takes effect immediately in both stacks: any request with the old token afterwards returns 401. Changing a password, or an admin resetting one, also invalidates that user’s existing tokens.
Frontend Behavior
Section titled “Frontend Behavior”On receiving 401, the frontend request layer automatically clears the local login state and redirects to the login page; there is no need to handle this separately on each page.