Release 2.7.0: executable handbooks and native user-site workflows

This commit is contained in:
cflmy committed 2026-11-10 17:03:06 +08:00
1 parent aa0c4d0f55
commit d9aef957f7
562 files changed
+21064 -20387

No files matched your search

+53 -3
View File
@@ -26,6 +26,56 @@ We retain **`p` = [Locate the installed native plugin](plugin.native_path(name="
We **[End this run with the selected exit status](sys.exit(code=1))**.
Return *None*.
## attach
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| app | any | required | Prepared web application |
| users | any | required | Credential table or native database-backed user configuration |
| session_ttl | number | 3600 | Session lifetime in seconds |
| admin_prefix | text | "/admin" | Native administration prefix |
| login_path | text | "/login" | Declared login route |
| login_redirect | text | "" | Optional successful login destination |
| logout_redirect | text | "" | Optional logout destination |
| register | bool | False | Explicitly enable user registration |
| register_path | text | "/register" | Registration route when enabled |
| default_role | text | "user" | Role assigned to a registered user |
| session_url | text | "" | Optional session backend URL |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Updated app with native login/session policy |
Use `app`, `users`, `session_ttl`=3600, `admin_prefix`="/admin", `login_path`="/login", `login_redirect`="", `logout_redirect`="", `register`=False, `register_path`="/register", `default_role`="user" and `session_url`="" before web.listen. This resource owns the login/session policy, while Endpoint auth metadata and explicit gates decide which requests need a session or role. Retain the returned app; construction does not authenticate a request or start a server. Credential tables in local examples are fixtures; real user stores should contain the hashes produced by hash_password. Registration is off until deliberately enabled. Session lifetime is in seconds, and external session backends require their own connection configuration.
We **[Load the native authentication implementation](plugin.load(path=plugin.native_path(name="web")))**.
Return *[Bind the selected login and session policy](web_app_auth(app=`app`, users=`users`, session_ttl=`session_ttl`, admin_prefix=`admin_prefix`, login_redirect=`login_redirect`, logout_redirect=`logout_redirect`, login_path=`login_path`, register=`register`, register_path=`register_path`, default_role=`default_role`, session_url=`session_url`))*.
## gate
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| app | any | required | Prepared application retaining its actual resources |
| path | text | required | Explicit URL path to protect |
| roles | any | "admin" | Allowed role CSV or list |
| permissions | text | "" | Optional permission CSV; native any-match policy |
| match | text | "prefix" | prefix or exact path matching |
| on_deny | text | "forbid" | forbid or redirect anonymous requests to login |
| exclude | any | None | Explicit path exclusions; native login/logout exclusions remain |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Updated app with a server-enforced gate; no listener starts |
Use `app`, `path`, `roles`="admin", `permissions`="", `match`="prefix", `on_deny`="forbid" and `exclude`=None before listening, with plugin permission. Retain the returned app. This security-owned operation protects real requests; hiding a navigation link does not do that. It reuses the existing native gate and does not mutate Document content or invent routes.
Prefix matching includes the selected path and its slash descendants. The runtime keeps login and logout available to avoid authentication loops. When permissions are supplied, native permission matching applies instead of the role list; any required permission may match. Redirect applies to anonymous denial, while a signed-in subject without access receives forbidden. Test both direct denied requests and authenticated access, and gate the actual form/API endpoint separately if its data is private.
We **[Load the native access-policy implementation](_load())**.
Return *[Bind the explicit server access rule](web_app_gate(app=`app`, path=`path`, roles=`roles`, permissions=`permissions`, match=`match`, on_deny=`on_deny`, exclude=`exclude`))*.
# auth
| 参数 | 类型 | 默认 | 说明 |
@@ -35,14 +85,14 @@ Return *None*.
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Session/auth helper. Constructs a config object; `login` validates against the users table. To gate `/admin` on this app, use `app.auth users=…` instead. |
| result | any | Session/auth helper. Constructs a config object; `login` validates against the users table. To bind native login and protect `/admin`, call attach and gate before listening. |
Use `users`, `session_ttl`=3600 as the inputs for this operation.
Session/auth helper. Constructs a config object; `login` validates against the users table. To gate `/admin` on this app, use `app.auth users=…` instead.
Session/auth helper. Constructs a config object; `login` validates against the users table. To bind native login and protect `/admin`, call attach and gate before listening.
We **[Load the native plugin required by this operation](_load())**.
Return *[Session/auth helper. Constructs a config object; login validates against the users table. To gate /admin on this app, use app.auth users=… instead.](web_auth_new(users=`users`, session_ttl=`session_ttl`))*.
Return *[Session/auth helper. Constructs a config object; login validates against the users table. To bind server login and gates, use this module's attach function before web.listen.](web_auth_new(users=`users`, session_ttl=`session_ttl`))*.
## login