feat(web): C0 release /admin when disabled; configurable admin_prefix

Stop mounting reserved admin routes when admin=False, nest CRUD under a
configurable prefix, and honor login/logout redirects so custom desks need no JS bypass.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
cflmyandCursor committed 2026-09-04 11:50:11 +08:00
1 parent 5f91be7c21
commit 0aa0f47a9d
10 files changed
+375 -90

No files matched your search

+11 -3
View File
@@ -565,9 +565,14 @@ Field table + rules table; submit writes through `# db`.
+ `admin`=False
+ `host`=127.0.0.1
+ `port`=18081
+ `admin_prefix`=/admin
+ `login_redirect`=None
+ `logout_redirect`=None
Construct an app. `admin=True` mounts the built-in CRUD UI under `admin_prefix` (default `/admin`). When `admin=False`, that prefix is **not** reserved — you may `route` your own pages there. Optional `login_redirect` / `logout_redirect` override post-auth landing (defaults: `{admin_prefix}` and `{admin_prefix}/login`).
> ensure_plugin
**> web_app_new page=`page` db=`db` admin=`admin` host=`host` port=`port`**
**> web_app_new page=`page` db=`db` admin=`admin` host=`host` port=`port` admin_prefix=`admin_prefix` login_redirect=`login_redirect` logout_redirect=`logout_redirect`**
## route
+ `path`
@@ -636,10 +641,13 @@ Register a WebSocket endpoint at `path` (e.g. `/live`). `mode` is `echo` (defaul
## auth
+ `users`
+ `session_ttl`=3600
+ `admin_prefix`=None
+ `login_redirect`=None
+ `logout_redirect`=None
Keep the app's `admin=True`, and gate `/admin*` behind a login page. `users` is an admin-users table (`|username|password|` / `|用户名|密码|`); optional `role` / `角色` column (`admin` / `author` / `visitor`). Unauthenticated requests redirect to `/admin/login`. Registers a default gate `/admin*` → `admin`.
Keep the app's `admin=True`, and gate `{admin_prefix}*` behind a login page (default prefix `/admin`). `users` is an admin-users table (`|username|password|` / `|用户名|密码|`); optional `role` / `角色` column (`admin` / `author` / `visitor`). Unauthenticated requests under the prefix redirect to `{admin_prefix}/login`. Registers a default gate `{admin_prefix}*` → `admin`. Optional args override `admin_prefix` / `login_redirect` / `logout_redirect` on the app.
**> web_app_auth app=`self` users=`users` session_ttl=`session_ttl`**
**> web_app_auth app=`self` users=`users` session_ttl=`session_ttl` admin_prefix=`admin_prefix` login_redirect=`login_redirect` logout_redirect=`logout_redirect`**
## gate
+ `path`
+11 -3
View File
@@ -545,9 +545,14 @@ SEO / OpenGraph 元数据表(`|键|值|`)。如 `title`、`description`、`c
+ `后台`=False
+ `主机`=127.0.0.1
+ `端口`=18081
+ `后台前缀`=/admin
+ `登录回跳`=None
+ `登出回跳`=None
构造应用。`后台=真` 时在 `后台前缀`(默认 `/admin`)挂载内置 CRUD。`后台=假` 时该前缀**不再保留**,可自行 `路由` 到 `/admin…`。可选 `登录回跳` / `登出回跳`(默认分别为前缀本身与 `{前缀}/login`)。
> 确保插件
**> web_app_new page=`页面` db=`数据库` admin=`后台` host=`主机` port=`端口`**
**> web_app_new page=`页面` db=`数据库` admin=`后台` host=`主机` port=`端口` admin_prefix=`后台前缀` login_redirect=`登录回跳` logout_redirect=`登出回跳`**
## 路由
+ `路径`
@@ -611,10 +616,13 @@ SEO / OpenGraph 元数据表(`|键|值|`)。如 `title`、`description`、`c
## 鉴权
+ `用户表`
+ `会话时长`=3600
+ `后台前缀`=None
+ `登录回跳`=None
+ `登出回跳`=None
在保持 `后台=真` 的同时,为 `/admin*` 加登录门禁。`用户表` 为 `|用户名|密码|`(可选 `角色`:`admin`/`author`/`visitor`);未登录重定向到 `/admin/login`。默认登记门禁 `/admin*` → `admin`。
在保持 `后台=真` 的同时,为 `{后台前缀}*` 加登录门禁(默认前缀 `/admin`)。`用户表` 为 `|用户名|密码|`(可选 `角色`:`admin`/`author`/`visitor`);未登录重定向到 `{前缀}/login`。默认登记门禁 `{前缀}*` → `admin`。可选参数可覆盖应用上的前缀与回跳。
**> web_app_auth app=`self` users=`用户表` session_ttl=`会话时长`**
**> web_app_auth app=`self` users=`用户表` session_ttl=`会话时长` admin_prefix=`后台前缀` login_redirect=`登录回跳` logout_redirect=`登出回跳`**
## 门禁
+ `路径`