feat(web): C1 segment-boundary gates with on_deny and exclude
Make auth/admin gates use path segment prefixes, configurable redirect vs 403, and login_path exclusion so /admin-publish and /desk/login are not mis-matched. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
0aa0f47a9d
commit
b10a84466b
9 files changed
+365
-67
No files matched your search
+8
-4
@@ -644,18 +644,22 @@ Register a WebSocket endpoint at `path` (e.g. `/live`). `mode` is `echo` (defaul
|
||||
+ `admin_prefix`=None
|
||||
+ `login_redirect`=None
|
||||
+ `logout_redirect`=None
|
||||
+ `login_path`=None
|
||||
|
||||
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.
|
||||
Keep the app's `admin=True`, and gate `{admin_prefix}` (segment-boundary prefix) behind a login page (default `/admin`). Unauthenticated requests **redirect** to `login_path` (default `{admin_prefix}/login`, auto-excluded). Does **not** match `/admin-publish`-style siblings.
|
||||
|
||||
**> web_app_auth app=`self` users=`users` session_ttl=`session_ttl` admin_prefix=`admin_prefix` login_redirect=`login_redirect` logout_redirect=`logout_redirect`**
|
||||
**> web_app_auth app=`self` users=`users` session_ttl=`session_ttl` admin_prefix=`admin_prefix` login_redirect=`login_redirect` logout_redirect=`logout_redirect` login_path=`login_path`**
|
||||
|
||||
## gate
|
||||
+ `path`
|
||||
+ `roles`=admin
|
||||
+ `match`=prefix
|
||||
+ `on_deny`=forbid
|
||||
+ `exclude`=None
|
||||
|
||||
Require one of `roles` (CSV) for `path` (prefix or `path*`). Anonymous sessions count as `visitor`.
|
||||
Require one of `roles` (CSV) for `path`. `match=prefix` uses segment boundaries; `exact` is equality. Trailing `*` on `path` means prefix. `on_deny=redirect` sends visitors to `login_path` (with `?next=`); `forbid` returns 403. `exclude` is CSV or list of open paths.
|
||||
|
||||
**> web_app_gate app=`self` path=`path` roles=`roles`**
|
||||
**> web_app_gate app=`self` path=`path` roles=`roles` match=`match` on_deny=`on_deny` exclude=`exclude`**
|
||||
|
||||
## gallery
|
||||
+ `path`=/gallery
|
||||
|
||||
+8
-4
@@ -619,18 +619,22 @@ SEO / OpenGraph 元数据表(`|键|值|`)。如 `title`、`description`、`c
|
||||
+ `后台前缀`=None
|
||||
+ `登录回跳`=None
|
||||
+ `登出回跳`=None
|
||||
+ `登录路径`=None
|
||||
|
||||
在保持 `后台=真` 的同时,为 `{后台前缀}*` 加登录门禁(默认前缀 `/admin`)。`用户表` 为 `|用户名|密码|`(可选 `角色`:`admin`/`author`/`visitor`);未登录重定向到 `{前缀}/login`。默认登记门禁 `{前缀}*` → `admin`。可选参数可覆盖应用上的前缀与回跳。
|
||||
在保持 `后台=真` 的同时,为 `{后台前缀}` 加**段边界**前缀门禁(默认 `/admin`)。未登录 **重定向** 到 `登录路径`(默认 `{前缀}/login`,自动排除)。不会匹配 `/admin-publish` 这类旁系路径。
|
||||
|
||||
**> web_app_auth app=`self` users=`用户表` session_ttl=`会话时长` admin_prefix=`后台前缀` login_redirect=`登录回跳` logout_redirect=`登出回跳`**
|
||||
**> web_app_auth app=`self` users=`用户表` session_ttl=`会话时长` admin_prefix=`后台前缀` login_redirect=`登录回跳` logout_redirect=`登出回跳` login_path=`登录路径`**
|
||||
|
||||
## 门禁
|
||||
+ `路径`
|
||||
+ `角色`=admin
|
||||
+ `匹配`=prefix
|
||||
+ `拒绝`=forbid
|
||||
+ `排除`=None
|
||||
|
||||
要求会话角色落在 `角色`(CSV)之一才可访问 `路径`(前缀或 `路径*`)。匿名视为 `visitor`。
|
||||
要求会话角色落在 `角色`(CSV)之一。`匹配=prefix` 为段边界前缀;`exact` 为精确路径。路径末尾 `*` 亦表示前缀。`拒绝=redirect` 时访客跳转登录页(带 `?next=`);`forbid` 返回 403。`排除` 为 CSV/列表(如登录页)。
|
||||
|
||||
**> web_app_gate app=`self` path=`路径` roles=`角色`**
|
||||
**> web_app_gate app=`self` path=`路径` roles=`角色` match=`匹配` on_deny=`拒绝` exclude=`排除`**
|
||||
|
||||
## 相册
|
||||
+ `路径`=/gallery
|
||||
|
||||
Reference in new issue
Block a user