Skip to content

Authentication and Accounts

Authentication is provided uniformly by the backend, and the frontend carries the token via Authorization: Bearer <token>.

Method Path Description Auth
POST /api/auth/login Log in No
POST /api/auth/register Register No
POST /api/auth/logout Log out Python: yes; Java: tolerates unauthenticated calls

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 behavior is controlled by two system settings:

  • When open registration (openRegistration) is false, the registration endpoint returns “Registration is closed” (注册已关闭).
  • When manual review (manualReview) is true, new accounts are assigned the pending_review role, and the endpoint returns only “Registration successful, please wait for administrator approval” (注册成功,请等待管理员审核), without issuing a token; when false, the account is directly assigned the user role and logged in automatically.

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.

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.
Python Java
Token type JWT (PyJWT, HS256) Sa-Token UUID session token
Validity 24 hours by default 86400 seconds by default
Logout Requires login; deletes the server-side session Tolerates unauthenticated calls and also returns success

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.