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:
1 parent
5f91be7c21
commit
0aa0f47a9d
10 files changed
+375
-90
No files matched your search
@@ -8,10 +8,12 @@
|
||||
|
||||
### Fixed
|
||||
- **`agent.step` / `plan` 写回**:参数名 `writeback` 遮蔽 `lib/writeback` import,导致 `writeback=True` 时 `method receiver must be an object map`;改为 `host_writeback_record`。金样 `agent-writeback-shadow`。
|
||||
- **`ext/web` C0**:`admin=False` 不再挂载/保留 `/admin*`;可配 `admin_prefix` / `login_redirect` / `logout_redirect`;金样 `web-c0-admin-prefix`。
|
||||
|
||||
### Changed
|
||||
- `build_step_context`:call site 提前到 task 之后;开场白强调 code-as-documentation。
|
||||
- 中文 `构建单步上下文` 委托英文版(含预算 / READ);新增 `dump_step_context`;live 用例改用仓库根 `.env`。
|
||||
- 文档:[ext-web 定制限制](doc/research/ext-web-customization-limits.md) + [解决设计 C0–C4](doc/design/ext-web-customization/)。
|
||||
|
||||
## v0.3.3 — 2026-09-04
|
||||
|
||||
|
||||
@@ -67,6 +67,8 @@
|
||||
|
||||
---
|
||||
|
||||
## 6. 过渡期作者 workaround(实现前)
|
||||
## 6. 过渡期 → 已落地
|
||||
|
||||
继续用 `/desk` 旁路 + JS 调 `/admin/login`;**实现 C0 后应删除该兜底**,避免双入口长期并存。
|
||||
~~继续用 `/desk` 旁路 + JS 调 `/admin/login`。~~
|
||||
|
||||
**C0 已落地(2026-09):** `admin=False` 可直接 `route path="/admin/…"`;或 `admin=True` + `admin_prefix="/desk"` + `login_redirect` / `logout_redirect`。见金样 `tests/ext/web-c0-admin-prefix.mq.md`。
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
| 状态 | **设计草案(待排期实现)** |
|
||||
| 状态 | **C0 done · C1–C4 planned** |
|
||||
| 日期 | 2026-09-04 |
|
||||
| 问题盘点 | [../../research/ext-web-customization-limits.md](../../research/ext-web-customization-limits.md) |
|
||||
| 相关 | [../ext-web.md](../ext-web.md) · [../ext-web-net.md](../ext-web-net.md) · [../../roadmap/ext-web.md](../../roadmap/ext-web.md) |
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
|
||||
| 波次 | 内容 | 状态 |
|
||||
|------|------|------|
|
||||
| **C0** | `admin` 关则不占路径;`admin_prefix` / 登录回跳可配 | **planned** |
|
||||
| **C0** | `admin` 关则不占路径;`admin_prefix` / 登录回跳可配 | **done** |
|
||||
| **C1** | gate 匹配与未登录策略一致;段边界默认 admin gate | **planned** |
|
||||
| **C2** | `shell_css` + `layout` 松绑 | **planned** |
|
||||
| **C3** | 样式 strict / 脚本 defer·version | **planned** |
|
||||
|
||||
+11
-3
@@ -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
@@ -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=`登出回跳`**
|
||||
|
||||
## 门禁
|
||||
+ `路径`
|
||||
|
||||
@@ -193,11 +193,13 @@ fn sql_type_to_input(sql_type: &str, name: &str) -> &'static str {
|
||||
}
|
||||
|
||||
/// Build a form handle from live SQLite schema (admin new/edit).
|
||||
/// `admin_prefix` is the mount root (default `/admin`), without trailing slash.
|
||||
pub fn from_schema(
|
||||
db_url: &str,
|
||||
table: &str,
|
||||
action: &str,
|
||||
id: Option<&str>,
|
||||
admin_prefix: &str,
|
||||
) -> Result<Value, String> {
|
||||
let action = match action {
|
||||
"update" | "更新" => "update",
|
||||
@@ -223,22 +225,24 @@ pub fn from_schema(
|
||||
"pk": c.pk,
|
||||
}));
|
||||
}
|
||||
let base = admin_prefix.trim_end_matches('/');
|
||||
let table_href = format!("{base}/{table}");
|
||||
let mut form = form_new(Some(table), action, id);
|
||||
if let Some(obj) = form.as_object_mut() {
|
||||
obj.insert("fields".into(), Value::Array(fields));
|
||||
obj.insert("redirect".into(), json!(format!("/admin/{table}")));
|
||||
obj.insert("redirect".into(), json!(&table_href));
|
||||
if action == "insert" {
|
||||
obj.insert("action_url".into(), json!(format!("/admin/{table}/new")));
|
||||
obj.insert("action_url".into(), json!(format!("{table_href}/new")));
|
||||
obj.insert("title".into(), json!(format!("New {table}")));
|
||||
} else if let Some(i) = id {
|
||||
obj.insert(
|
||||
"action_url".into(),
|
||||
json!(format!("/admin/{table}/{i}/edit")),
|
||||
json!(format!("{table_href}/{i}/edit")),
|
||||
);
|
||||
obj.insert("title".into(), json!(format!("Edit {table} #{i}")));
|
||||
obj.insert("id".into(), json!(i));
|
||||
}
|
||||
obj.insert("cancel_href".into(), json!(format!("/admin/{table}")));
|
||||
obj.insert("cancel_href".into(), json!(&table_href));
|
||||
}
|
||||
Ok(form)
|
||||
}
|
||||
|
||||
+108
-46
@@ -74,6 +74,10 @@ pub struct AppState {
|
||||
page: Value,
|
||||
pub db_url: Option<String>,
|
||||
admin: bool,
|
||||
/// Built-in admin mount root (e.g. `/admin` or `/desk`); unused when `admin` is false.
|
||||
admin_prefix: String,
|
||||
login_redirect: String,
|
||||
logout_redirect: String,
|
||||
forms: HashMap<String, Value>,
|
||||
/// Page that owns an embedded form (for re-render on validation errors).
|
||||
form_owners: HashMap<String, Value>,
|
||||
@@ -90,6 +94,26 @@ pub struct AppState {
|
||||
site_head: Vec<crate::assets::HeadLink>,
|
||||
}
|
||||
|
||||
impl AppState {
|
||||
fn ap(&self) -> &str {
|
||||
self.admin_prefix.trim_end_matches('/')
|
||||
}
|
||||
|
||||
fn admin_href(&self, rest: &str) -> String {
|
||||
let p = self.ap();
|
||||
let rest = rest.trim().trim_start_matches('/');
|
||||
if rest.is_empty() {
|
||||
p.to_string()
|
||||
} else {
|
||||
format!("{p}/{rest}")
|
||||
}
|
||||
}
|
||||
|
||||
fn login_path(&self) -> String {
|
||||
self.admin_href("login")
|
||||
}
|
||||
}
|
||||
|
||||
fn collect_page_forms(
|
||||
page: &Value,
|
||||
forms: &mut HashMap<String, Value>,
|
||||
@@ -118,6 +142,9 @@ pub fn listen(
|
||||
host: &str,
|
||||
port: u16,
|
||||
admin: bool,
|
||||
admin_prefix: &str,
|
||||
login_redirect: &str,
|
||||
logout_redirect: &str,
|
||||
mut forms: HashMap<String, Value>,
|
||||
routes: HashMap<String, Value>,
|
||||
static_dir: Option<PathBuf>,
|
||||
@@ -166,10 +193,23 @@ pub fn listen(
|
||||
// Resolve relative icon paths: try as-is absolute, else leave for entry_dir resolve in lib.
|
||||
// (Absolute paths preferred; relative already joined in web_listen.)
|
||||
|
||||
let admin_prefix = {
|
||||
let mut p = admin_prefix.trim().to_string();
|
||||
if !p.starts_with('/') {
|
||||
p = format!("/{p}");
|
||||
}
|
||||
while p.len() > 1 && p.ends_with('/') {
|
||||
p.pop();
|
||||
}
|
||||
p
|
||||
};
|
||||
let state = Arc::new(AppState {
|
||||
page: page.clone(),
|
||||
db_url: db_url.map(|s| s.to_string()),
|
||||
admin,
|
||||
admin_prefix: admin_prefix.clone(),
|
||||
login_redirect: login_redirect.to_string(),
|
||||
logout_redirect: logout_redirect.to_string(),
|
||||
forms,
|
||||
form_owners,
|
||||
auth_users,
|
||||
@@ -185,17 +225,23 @@ pub fn listen(
|
||||
let mut app = Router::new()
|
||||
.route("/", get(home))
|
||||
.route("/_part/{id}", get(home_part))
|
||||
.route("/_form/{id}", get(form_get).post(form_post))
|
||||
.route("/admin", get(admin_home))
|
||||
.route("/admin/login", get(admin_login_get).post(admin_login_post))
|
||||
.route("/admin/logout", get(admin_logout))
|
||||
.route("/admin/{table}", get(admin_table))
|
||||
.route("/admin/{table}/new", get(admin_new_get).post(admin_new_post))
|
||||
.route(
|
||||
"/admin/{table}/{id}/edit",
|
||||
get(admin_edit_get).post(admin_edit_post),
|
||||
)
|
||||
.route("/admin/{table}/{id}/delete", get(admin_delete));
|
||||
.route("/_form/{id}", get(form_get).post(form_post));
|
||||
|
||||
// Built-in admin only when enabled — otherwise `/admin…` is free for author routes.
|
||||
if admin {
|
||||
let admin_routes = Router::new()
|
||||
.route("/", get(admin_home))
|
||||
.route("/login", get(admin_login_get).post(admin_login_post))
|
||||
.route("/logout", get(admin_logout))
|
||||
.route("/{table}", get(admin_table))
|
||||
.route("/{table}/new", get(admin_new_get).post(admin_new_post))
|
||||
.route(
|
||||
"/{table}/{id}/edit",
|
||||
get(admin_edit_get).post(admin_edit_post),
|
||||
)
|
||||
.route("/{table}/{id}/delete", get(admin_delete));
|
||||
app = app.nest(&admin_prefix, admin_routes);
|
||||
}
|
||||
|
||||
// Register each author route as an exact GET path + `{path}/_part/{id}`.
|
||||
// Paths containing `{param}` become dynamic routes (e.g. `/post/{slug}`);
|
||||
@@ -434,10 +480,14 @@ pub fn listen(
|
||||
let app = crate::middleware::apply(app, middleware);
|
||||
let app = if !gates.is_empty() {
|
||||
let gates_for_mw = gates.clone();
|
||||
let login_path_for_mw = state.login_path();
|
||||
let admin_prefix_for_mw = state.admin_prefix.clone();
|
||||
app.layer(axum::middleware::from_fn(
|
||||
move |req: axum::http::Request<axum::body::Body>, next: axum::middleware::Next| {
|
||||
let gates = gates_for_mw.clone();
|
||||
async move { rbac_middleware(gates, req, next).await }
|
||||
let login_path = login_path_for_mw.clone();
|
||||
let admin_prefix = admin_prefix_for_mw.clone();
|
||||
async move { rbac_middleware(gates, login_path, admin_prefix, req, next).await }
|
||||
},
|
||||
))
|
||||
} else {
|
||||
@@ -911,8 +961,14 @@ fn path_matches(path: &str, pattern: &str) -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
fn path_under_admin_prefix(path: &str, prefix: &str) -> bool {
|
||||
path == prefix || path.starts_with(&format!("{prefix}/"))
|
||||
}
|
||||
|
||||
async fn rbac_middleware(
|
||||
gates: Vec<(String, Vec<String>)>,
|
||||
login_path: String,
|
||||
admin_prefix: String,
|
||||
req: axum::http::Request<axum::body::Body>,
|
||||
next: axum::middleware::Next,
|
||||
) -> Response {
|
||||
@@ -927,13 +983,13 @@ async fn rbac_middleware(
|
||||
continue;
|
||||
}
|
||||
// Login page itself must stay reachable.
|
||||
if path == "/admin/login" || path.starts_with("/admin/login?") {
|
||||
if path == login_path || path.starts_with(&format!("{login_path}?")) {
|
||||
break;
|
||||
}
|
||||
let role = session::session_role(cookie.as_deref());
|
||||
if !session::role_allowed(&role, roles) {
|
||||
if role == "visitor" && path.starts_with("/admin") {
|
||||
return Redirect::to("/admin/login").into_response();
|
||||
if role == "visitor" && path_under_admin_prefix(&path, &admin_prefix) {
|
||||
return Redirect::to(&login_path).into_response();
|
||||
}
|
||||
return (
|
||||
StatusCode::FORBIDDEN,
|
||||
@@ -1044,18 +1100,15 @@ h1{{margin:0 0 1rem;font-size:1.5rem}}
|
||||
}
|
||||
|
||||
fn admin_gate(st: &AppState, cookie_header: Option<&str>) -> Option<Response> {
|
||||
// When admin=false the built-in routes are not mounted; defense-in-depth only.
|
||||
if !st.admin {
|
||||
return Some(Html(admin_shell(st, "Admin", None, "<p class=\"flash err\">Admin is disabled for this app.</p>")).into_response());
|
||||
return Some((StatusCode::NOT_FOUND, "Not Found").into_response());
|
||||
}
|
||||
if st.db_url.is_none() {
|
||||
return Some(Html(admin_shell(st, "Admin", None, "<p class=\"flash err\">No database bound to this app.</p>")).into_response());
|
||||
}
|
||||
// Login-gated admin: require a valid admin-role session.
|
||||
if st.auth_users.is_some() && !admin_authed(st, cookie_header) {
|
||||
return Some(
|
||||
Redirect::to("/admin/login")
|
||||
.into_response(),
|
||||
);
|
||||
return Some(Redirect::to(&st.login_path()).into_response());
|
||||
}
|
||||
None
|
||||
}
|
||||
@@ -1074,10 +1127,10 @@ fn admin_authed(_st: &AppState, cookie_header: Option<&str>) -> bool {
|
||||
|
||||
async fn admin_login_get(State(st): State<Arc<AppState>>, headers: axum::http::HeaderMap) -> Response {
|
||||
if st.auth_users.is_none() {
|
||||
return Redirect::to("/admin").into_response();
|
||||
return Redirect::to(&st.login_redirect).into_response();
|
||||
}
|
||||
if admin_authed(&st, cookie_from_headers(&headers)) {
|
||||
return Redirect::to("/admin").into_response();
|
||||
return Redirect::to(&st.login_redirect).into_response();
|
||||
}
|
||||
let (_, csrf, set_cookie) = resolve_session(&headers);
|
||||
let mut resp = Html(login_page(&st, None, Some(&csrf))).into_response();
|
||||
@@ -1091,7 +1144,7 @@ async fn admin_login_post(
|
||||
Form(posted): Form<HashMap<String, String>>,
|
||||
) -> Response {
|
||||
let Some(users) = &st.auth_users else {
|
||||
return Redirect::to("/admin").into_response();
|
||||
return Redirect::to(&st.login_redirect).into_response();
|
||||
};
|
||||
let (_, csrf, set_cookie, posted) = match validate_csrf_post(&headers, posted) {
|
||||
Ok(v) => v,
|
||||
@@ -1117,7 +1170,7 @@ async fn admin_login_post(
|
||||
let sid = session::session_new(Some(st.session_ttl));
|
||||
session::session_set(&sid, "username", json!(user));
|
||||
session::session_set(&sid, "role", json!(role));
|
||||
let mut resp = Redirect::to("/admin").into_response();
|
||||
let mut resp = Redirect::to(&st.login_redirect).into_response();
|
||||
let _ = resp.headers_mut().try_append(
|
||||
axum::http::header::SET_COOKIE,
|
||||
session::session_cookie(&sid, st.session_ttl, st.cookie_secure)
|
||||
@@ -1128,7 +1181,7 @@ async fn admin_login_post(
|
||||
resp
|
||||
}
|
||||
|
||||
fn login_page(_st: &AppState, error: Option<&str>, csrf: Option<&str>) -> String {
|
||||
fn login_page(st: &AppState, error: Option<&str>, csrf: Option<&str>) -> String {
|
||||
let err = match error {
|
||||
Some(e) => format!("<p class=\"flash err\">{}</p>", esc(e)),
|
||||
None => String::new(),
|
||||
@@ -1163,7 +1216,7 @@ body {{ margin:0; min-height:100vh; display:grid; place-items:center; background
|
||||
<h1>Admin</h1>
|
||||
<p class="sub">Sign in to manage this site.</p>
|
||||
{err}
|
||||
<form method="post" action="/admin/login">
|
||||
<form method="post" action="{login_action}">
|
||||
{csrf_field}
|
||||
<label>Username<input name="username" autocomplete="username" required autofocus/></label>
|
||||
<label>Password<input name="password" type="password" autocomplete="current-password" required/></label>
|
||||
@@ -1173,11 +1226,12 @@ body {{ margin:0; min-height:100vh; display:grid; place-items:center; background
|
||||
</body></html>"#,
|
||||
err = err,
|
||||
csrf_field = csrf_field,
|
||||
login_action = esc(&st.login_path()),
|
||||
)
|
||||
}
|
||||
|
||||
async fn admin_logout(
|
||||
State(_st): State<Arc<AppState>>,
|
||||
State(st): State<Arc<AppState>>,
|
||||
headers: axum::http::HeaderMap,
|
||||
) -> Response {
|
||||
if let Some(sid) = session::session_id_from_cookie(
|
||||
@@ -1187,7 +1241,7 @@ async fn admin_logout(
|
||||
) {
|
||||
session::session_destroy(&sid);
|
||||
}
|
||||
let mut resp = Redirect::to("/admin/login").into_response();
|
||||
let mut resp = Redirect::to(&st.logout_redirect).into_response();
|
||||
if let Ok(h) = resp.headers_mut().try_append(
|
||||
axum::http::header::SET_COOKIE,
|
||||
"marqdo_sid=; HttpOnly; Path=/; Max-Age=0; SameSite=Lax"
|
||||
@@ -1217,7 +1271,7 @@ fn admin_shell(st: &AppState, title: &str, active: Option<&str>, inner: &str) ->
|
||||
.as_deref()
|
||||
.and_then(|u| db::list_tables(u).ok())
|
||||
.unwrap_or_default();
|
||||
let mut side = String::from("<nav class=\"admin-nav\"><a class=\"brand\" href=\"/admin\">Admin</a>");
|
||||
let mut side = format!("<nav class=\"admin-nav\"><a class=\"brand\" href=\"{}\">Admin</a>", esc(st.ap()));
|
||||
if tables.is_empty() {
|
||||
side.push_str("<p class=\"muted\">No tables yet.</p>");
|
||||
} else {
|
||||
@@ -1229,8 +1283,8 @@ fn admin_shell(st: &AppState, title: &str, active: Option<&str>, inner: &str) ->
|
||||
""
|
||||
};
|
||||
side.push_str(&format!(
|
||||
"<li><a{cls} href=\"/admin/{}\">{}</a></li>",
|
||||
esc(t),
|
||||
"<li><a{cls} href=\"{}\">{}</a></li>",
|
||||
esc(&st.admin_href(t)),
|
||||
esc(t)
|
||||
));
|
||||
}
|
||||
@@ -1325,7 +1379,9 @@ fn admin_form_page(
|
||||
csrf: Option<&str>,
|
||||
) -> String {
|
||||
let mut body = format!(
|
||||
"<p class=\"crumbs\"><a href=\"/admin\">Admin</a> / <a href=\"/admin/{t}\">{t}</a> / {kind}</p><h1>{kind} {t}</h1>",
|
||||
"<p class=\"crumbs\"><a href=\"{home}\">Admin</a> / <a href=\"{table_href}\">{t}</a> / {kind}</p><h1>{kind} {t}</h1>",
|
||||
home = esc(st.ap()),
|
||||
table_href = esc(&st.admin_href(table)),
|
||||
t = esc(table),
|
||||
kind = esc(kind),
|
||||
);
|
||||
@@ -1358,7 +1414,9 @@ async fn admin_home(
|
||||
inner.push_str("<div class=\"table-wrap\"><table class=\"data\"><thead><tr><th>Table</th><th></th></tr></thead><tbody>");
|
||||
for t in &tables {
|
||||
inner.push_str(&format!(
|
||||
"<tr><td><a href=\"/admin/{t}\">{t}</a></td><td class=\"actions\"><a class=\"btn\" href=\"/admin/{t}/new\">New</a></td></tr>",
|
||||
"<tr><td><a href=\"{href}\">{t}</a></td><td class=\"actions\"><a class=\"btn\" href=\"{new_href}\">New</a></td></tr>",
|
||||
href = esc(&st.admin_href(t)),
|
||||
new_href = esc(&st.admin_href(&format!("{t}/new"))),
|
||||
t = esc(t)
|
||||
));
|
||||
}
|
||||
@@ -1407,22 +1465,23 @@ async fn admin_table(
|
||||
}
|
||||
|
||||
let mut inner = format!(
|
||||
"<p class=\"crumbs\"><a href=\"/admin\">Admin</a> / {t}</p><h1>{t}</h1>",
|
||||
"<p class=\"crumbs\"><a href=\"{home}\">Admin</a> / {t}</p><h1>{t}</h1>",
|
||||
home = esc(st.ap()),
|
||||
t = esc(&table)
|
||||
);
|
||||
inner.push_str(&flash_html(q.flash.as_deref()));
|
||||
inner.push_str(&format!(
|
||||
"<div class=\"toolbar\"><a class=\"btn\" href=\"/admin/{}/new\">New row</a><span class=\"meta\">{} row{}</span></div>",
|
||||
esc(&table),
|
||||
"<div class=\"toolbar\"><a class=\"btn\" href=\"{new_href}\">New row</a><span class=\"meta\">{} row{}</span></div>",
|
||||
rows.len(),
|
||||
if rows.len() == 1 { "" } else { "s" }
|
||||
if rows.len() == 1 { "" } else { "s" },
|
||||
new_href = esc(&st.admin_href(&format!("{table}/new"))),
|
||||
));
|
||||
|
||||
if rows.is_empty() {
|
||||
inner.push_str(&format!(
|
||||
"<div class=\"empty\"><strong>No rows in {}</strong><a class=\"btn\" href=\"/admin/{}/new\">Create the first row</a></div>",
|
||||
"<div class=\"empty\"><strong>No rows in {}</strong><a class=\"btn\" href=\"{new_href}\">Create the first row</a></div>",
|
||||
esc(&table),
|
||||
esc(&table)
|
||||
new_href = esc(&st.admin_href(&format!("{table}/new"))),
|
||||
));
|
||||
} else {
|
||||
inner.push_str("<div class=\"table-wrap\"><table class=\"data\"><thead><tr>");
|
||||
@@ -1454,7 +1513,10 @@ async fn admin_table(
|
||||
.unwrap_or_default();
|
||||
if !id.is_empty() {
|
||||
inner.push_str(&format!(
|
||||
"<td class=\"actions\"><a href=\"/admin/{table}/{id}/edit\">Edit</a> · <a class=\"danger\" href=\"/admin/{table}/{id}/delete\" onclick=\"return confirm('Delete row #{id}?')\">Delete</a></td>"
|
||||
"<td class=\"actions\"><a href=\"{edit}\">Edit</a> · <a class=\"danger\" href=\"{del}\" onclick=\"return confirm('Delete row #{id}?')\">Delete</a></td>",
|
||||
edit = esc(&st.admin_href(&format!("{table}/{id}/edit"))),
|
||||
del = esc(&st.admin_href(&format!("{table}/{id}/delete"))),
|
||||
id = esc(&id),
|
||||
));
|
||||
} else {
|
||||
inner.push_str("<td></td>");
|
||||
@@ -1476,7 +1538,7 @@ async fn admin_new_get(
|
||||
}
|
||||
let url = st.db_url.as_deref().unwrap();
|
||||
let (_, csrf, set_cookie) = resolve_session(&headers);
|
||||
match form::from_schema(url, &table, "insert", None) {
|
||||
match form::from_schema(url, &table, "insert", None, st.ap()) {
|
||||
Ok(frm) => {
|
||||
let mut resp = Html(admin_form_page(
|
||||
&st,
|
||||
@@ -1516,7 +1578,7 @@ async fn admin_new_post(
|
||||
Ok(v) => v,
|
||||
Err(r) => return r,
|
||||
};
|
||||
match form::from_schema(url, &table, "insert", None) {
|
||||
match form::from_schema(url, &table, "insert", None, st.ap()) {
|
||||
Ok(frm) => {
|
||||
let mut resp = submit_and_respond(
|
||||
&st,
|
||||
@@ -1571,7 +1633,7 @@ async fn admin_edit_get(
|
||||
}
|
||||
};
|
||||
let (_, csrf, set_cookie) = resolve_session(&headers);
|
||||
match form::from_schema(url, &table, "update", Some(&id)) {
|
||||
match form::from_schema(url, &table, "update", Some(&id), st.ap()) {
|
||||
Ok(frm) => {
|
||||
let mut resp = Html(admin_form_page(
|
||||
&st,
|
||||
@@ -1611,7 +1673,7 @@ async fn admin_edit_post(
|
||||
Ok(v) => v,
|
||||
Err(r) => return r,
|
||||
};
|
||||
match form::from_schema(url, &table, "update", Some(&id)) {
|
||||
match form::from_schema(url, &table, "update", Some(&id), st.ap()) {
|
||||
Ok(frm) => {
|
||||
let mut resp = submit_and_respond(
|
||||
&st,
|
||||
@@ -1653,7 +1715,7 @@ async fn admin_delete(
|
||||
))
|
||||
.into_response();
|
||||
}
|
||||
Redirect::to(&with_flash(&format!("/admin/{table}"), "deleted")).into_response()
|
||||
Redirect::to(&with_flash(&st.admin_href(&table), "deleted")).into_response()
|
||||
}
|
||||
|
||||
fn esc(s: &str) -> String {
|
||||
|
||||
+157
-30
@@ -500,7 +500,7 @@ web_ffi!(web_rss_build, |args: &Value| {
|
||||
|
||||
web_ffi!(web_app_route_rss, |args: &Value| {
|
||||
let mut app = args.get("app").cloned().unwrap_or(json!({}));
|
||||
let path = normalize_route_path(arg_str(args, "path")?)?;
|
||||
let path = normalize_route_path_in_app(arg_str(args, "path")?, &app)?;
|
||||
let table = arg_str(args, "table")?.to_string();
|
||||
let limit = args
|
||||
.get("limit")
|
||||
@@ -537,7 +537,7 @@ web_ffi!(web_app_route_rss, |args: &Value| {
|
||||
|
||||
web_ffi!(web_app_redirect, |args: &Value| {
|
||||
let mut app = args.get("app").cloned().unwrap_or(json!({}));
|
||||
let from = normalize_route_path(arg_str(args, "from").or_else(|_| arg_str(args, "path"))?)?;
|
||||
let from = normalize_route_path_in_app(arg_str(args, "from").or_else(|_| arg_str(args, "path"))?, &app)?;
|
||||
let to = arg_str(args, "to")?.to_string();
|
||||
let permanent = match args
|
||||
.get("permanent")
|
||||
@@ -588,7 +588,7 @@ web_ffi!(web_app_error_page, |args: &Value| {
|
||||
|
||||
web_ffi!(web_app_sitemap, |args: &Value| {
|
||||
let mut app = args.get("app").cloned().unwrap_or(json!({}));
|
||||
let path = normalize_route_path(arg_str(args, "path").unwrap_or("/sitemap.xml"))?;
|
||||
let path = normalize_route_path_in_app(arg_str(args, "path").unwrap_or("/sitemap.xml"), &app)?;
|
||||
let base = arg_str_opt(args, "base").unwrap_or("").to_string();
|
||||
let table = arg_str_opt(args, "table").map(|s| s.to_string());
|
||||
let loc = arg_str_opt(args, "loc").unwrap_or("path").to_string();
|
||||
@@ -655,7 +655,7 @@ fn storage_url_arg(args: &Value, key: &str) -> Result<String, String> {
|
||||
|
||||
web_ffi!(web_app_upload, |args: &Value| {
|
||||
let mut app = args.get("app").cloned().unwrap_or(json!({}));
|
||||
let path = normalize_route_path(arg_str(args, "path").unwrap_or("/_upload"))?;
|
||||
let path = normalize_route_path_in_app(arg_str(args, "path").unwrap_or("/_upload"), &app)?;
|
||||
let field = arg_str_opt(args, "field").unwrap_or("file").to_string();
|
||||
let storage_url = storage_url_arg(args, "storage")?;
|
||||
let prefix = arg_str_opt(args, "prefix").unwrap_or("uploads/").to_string();
|
||||
@@ -1023,27 +1023,44 @@ web_ffi!(web_app_new, |args: &Value| {
|
||||
Some(Value::Number(n)) => n.as_i64().unwrap_or(0) != 0,
|
||||
_ => false,
|
||||
};
|
||||
Ok(json!({
|
||||
let admin_prefix = arg_str_opt(args, "admin_prefix")
|
||||
.or_else(|| arg_str_opt(args, "后台前缀"))
|
||||
.map(normalize_admin_prefix)
|
||||
.transpose()?
|
||||
.unwrap_or_else(|| "/admin".into());
|
||||
let login_redirect = arg_str_opt(args, "login_redirect")
|
||||
.or_else(|| arg_str_opt(args, "登录回跳"))
|
||||
.map(|s| s.to_string());
|
||||
let logout_redirect = arg_str_opt(args, "logout_redirect")
|
||||
.or_else(|| arg_str_opt(args, "登出回跳"))
|
||||
.map(|s| s.to_string());
|
||||
let mut out = json!({
|
||||
"page": page,
|
||||
"db": db,
|
||||
"host": host,
|
||||
"port": port,
|
||||
"admin": admin,
|
||||
"admin_prefix": admin_prefix,
|
||||
"forms": {},
|
||||
"routes": {},
|
||||
"ws_routes": {},
|
||||
"static_dir": null,
|
||||
"static_mount": "/static",
|
||||
}))
|
||||
});
|
||||
if let Some(v) = login_redirect {
|
||||
out.as_object_mut().unwrap().insert("login_redirect".into(), json!(v));
|
||||
}
|
||||
if let Some(v) = logout_redirect {
|
||||
out.as_object_mut().unwrap().insert("logout_redirect".into(), json!(v));
|
||||
}
|
||||
Ok(out)
|
||||
});
|
||||
|
||||
fn normalize_route_path(raw: &str) -> Result<String, String> {
|
||||
/// Normalize a URL path: leading slash, no trailing slash (except never `/` here).
|
||||
fn clean_mount_path(raw: &str) -> Result<String, String> {
|
||||
let s = raw.trim();
|
||||
if s.is_empty() {
|
||||
return Err("route path is empty".into());
|
||||
}
|
||||
if s == "/" {
|
||||
return Err("route path `/` is reserved for the home page".into());
|
||||
return Err("path is empty".into());
|
||||
}
|
||||
let mut path = if s.starts_with('/') {
|
||||
s.to_string()
|
||||
@@ -1053,24 +1070,88 @@ fn normalize_route_path(raw: &str) -> Result<String, String> {
|
||||
while path.len() > 1 && path.ends_with('/') {
|
||||
path.pop();
|
||||
}
|
||||
// reserved prefixes
|
||||
if path == "/admin"
|
||||
|| path.starts_with("/admin/")
|
||||
|| path == "/_form"
|
||||
Ok(path)
|
||||
}
|
||||
|
||||
fn normalize_admin_prefix(raw: &str) -> Result<String, String> {
|
||||
let path = clean_mount_path(raw)?;
|
||||
if path == "/" {
|
||||
return Err("admin_prefix cannot be `/`".into());
|
||||
}
|
||||
if path == "/_form"
|
||||
|| path.starts_with("/_form/")
|
||||
|| path == "/_part"
|
||||
|| path.starts_with("/_part/")
|
||||
|| path == "/static"
|
||||
|| path.starts_with("/static/")
|
||||
{
|
||||
return Err(format!("admin_prefix `{path}` collides with framework paths"));
|
||||
}
|
||||
Ok(path)
|
||||
}
|
||||
|
||||
fn path_under_prefix(path: &str, prefix: &str) -> bool {
|
||||
path == prefix || path.starts_with(&format!("{prefix}/"))
|
||||
}
|
||||
|
||||
fn is_framework_reserved(path: &str, static_mount: &str) -> bool {
|
||||
path == "/_form"
|
||||
|| path.starts_with("/_form/")
|
||||
|| path == "/_part"
|
||||
|| path.starts_with("/_part/")
|
||||
|| path_under_prefix(path, static_mount)
|
||||
}
|
||||
|
||||
/// Reserved only while built-in admin is enabled, for the active prefix.
|
||||
fn normalize_route_path_for(
|
||||
raw: &str,
|
||||
admin: bool,
|
||||
admin_prefix: &str,
|
||||
static_mount: &str,
|
||||
) -> Result<String, String> {
|
||||
let path = clean_mount_path(raw)?;
|
||||
if path == "/" {
|
||||
return Err("route path `/` is reserved for the home page".into());
|
||||
}
|
||||
if is_framework_reserved(&path, static_mount) {
|
||||
return Err(format!("route path `{path}` is reserved"));
|
||||
}
|
||||
if admin && path_under_prefix(&path, admin_prefix) {
|
||||
return Err(format!("route path `{path}` is reserved"));
|
||||
}
|
||||
Ok(path)
|
||||
}
|
||||
|
||||
fn app_admin_flag(app: &Value) -> bool {
|
||||
app.get("admin")
|
||||
.and_then(|v| v.as_bool())
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
fn app_admin_prefix(app: &Value) -> String {
|
||||
app.get("admin_prefix")
|
||||
.and_then(|v| v.as_str())
|
||||
.and_then(|s| normalize_admin_prefix(s).ok())
|
||||
.unwrap_or_else(|| "/admin".into())
|
||||
}
|
||||
|
||||
fn app_static_mount(app: &Value) -> String {
|
||||
app.get("static_mount")
|
||||
.and_then(|v| v.as_str())
|
||||
.map(http::normalize_static_mount)
|
||||
.unwrap_or_else(|| "/static".into())
|
||||
}
|
||||
|
||||
fn normalize_route_path_in_app(raw: &str, app: &Value) -> Result<String, String> {
|
||||
normalize_route_path_for(
|
||||
raw,
|
||||
app_admin_flag(app),
|
||||
&app_admin_prefix(app),
|
||||
&app_static_mount(app),
|
||||
)
|
||||
}
|
||||
|
||||
web_ffi!(web_app_route, |args: &Value| {
|
||||
let mut app = args.get("app").cloned().unwrap_or(json!({}));
|
||||
let path = normalize_route_path(arg_str(args, "path")?)?;
|
||||
let path = normalize_route_path_in_app(arg_str(args, "path")?, &app)?;
|
||||
let mut page = args
|
||||
.get("page")
|
||||
.cloned()
|
||||
@@ -1094,7 +1175,7 @@ web_ffi!(web_app_route, |args: &Value| {
|
||||
|
||||
web_ffi!(web_app_route_ws, |args: &Value| {
|
||||
let mut app = args.get("app").cloned().unwrap_or(json!({}));
|
||||
let path = normalize_route_path(arg_str(args, "path")?)?;
|
||||
let path = normalize_route_path_in_app(arg_str(args, "path")?, &app)?;
|
||||
let mode = if let Some(m) = args.get("mode").or_else(|| args.get("模式")) {
|
||||
crate::ws_hub::WsMode::parse(m)
|
||||
} else {
|
||||
@@ -1179,6 +1260,23 @@ web_ffi!(web_app_auth, |args: &Value| {
|
||||
.get("session_ttl")
|
||||
.and_then(|v| v.as_u64().or_else(|| v.as_i64().map(|i| i as u64)))
|
||||
.unwrap_or(3600);
|
||||
if let Some(p) = arg_str_opt(args, "admin_prefix").or_else(|| arg_str_opt(args, "后台前缀")) {
|
||||
let p = normalize_admin_prefix(p)?;
|
||||
app.as_object_mut()
|
||||
.ok_or_else(|| "app must be a map".to_string())?
|
||||
.insert("admin_prefix".into(), json!(p));
|
||||
}
|
||||
if let Some(v) = arg_str_opt(args, "login_redirect").or_else(|| arg_str_opt(args, "登录回跳")) {
|
||||
app.as_object_mut()
|
||||
.ok_or_else(|| "app must be a map".to_string())?
|
||||
.insert("login_redirect".into(), json!(v));
|
||||
}
|
||||
if let Some(v) = arg_str_opt(args, "logout_redirect").or_else(|| arg_str_opt(args, "登出回跳")) {
|
||||
app.as_object_mut()
|
||||
.ok_or_else(|| "app must be a map".to_string())?
|
||||
.insert("logout_redirect".into(), json!(v));
|
||||
}
|
||||
let prefix = app_admin_prefix(&app);
|
||||
let obj = app
|
||||
.as_object_mut()
|
||||
.ok_or_else(|| "app must be a map".to_string())?;
|
||||
@@ -1186,19 +1284,20 @@ web_ffi!(web_app_auth, |args: &Value| {
|
||||
"auth".to_string(),
|
||||
json!({ "users": users, "session_ttl": session_ttl }),
|
||||
);
|
||||
// Default RBAC: `/admin*` requires role `admin` when auth is configured.
|
||||
// Default RBAC: `{admin_prefix}*` requires role `admin` when auth is configured.
|
||||
let mut gates = obj
|
||||
.get("gates")
|
||||
.and_then(|v| v.as_array())
|
||||
.cloned()
|
||||
.unwrap_or_default();
|
||||
let gate_star = format!("{prefix}*");
|
||||
let has_admin_gate = gates.iter().any(|g| {
|
||||
g.get("path")
|
||||
.and_then(|v| v.as_str())
|
||||
.is_some_and(|p| p == "/admin" || p == "/admin*")
|
||||
.is_some_and(|p| p == prefix || p == gate_star)
|
||||
});
|
||||
if !has_admin_gate {
|
||||
gates.push(json!({ "path": "/admin*", "roles": ["admin"] }));
|
||||
gates.push(json!({ "path": gate_star, "roles": ["admin"] }));
|
||||
obj.insert("gates".into(), Value::Array(gates));
|
||||
}
|
||||
Ok(app)
|
||||
@@ -1226,10 +1325,11 @@ web_ffi!(web_app_gate, |args: &Value| {
|
||||
|
||||
web_ffi!(web_app_gallery, |args: &Value| {
|
||||
let mut app = args.get("app").cloned().unwrap_or(json!({}));
|
||||
let path = normalize_route_path(
|
||||
let path = normalize_route_path_in_app(
|
||||
arg_str(args, "path")
|
||||
.or_else(|_| arg_str(args, "路径"))
|
||||
.unwrap_or("/gallery"),
|
||||
&app,
|
||||
)?;
|
||||
let storage_url = storage_url_arg(args, "storage")
|
||||
.or_else(|_| storage_url_arg(args, "存储"))?;
|
||||
@@ -1293,16 +1393,16 @@ web_ffi!(web_app_static, |args: &Value| {
|
||||
}
|
||||
let mount = arg_str_opt(args, "mount").unwrap_or("/static");
|
||||
let mount = http::normalize_static_mount(mount);
|
||||
// Also reserve custom mounts against later routes.
|
||||
if mount == "/admin"
|
||||
|| mount.starts_with("/admin/")
|
||||
|| mount == "/_form"
|
||||
if mount == "/_form"
|
||||
|| mount.starts_with("/_form/")
|
||||
|| mount == "/_part"
|
||||
|| mount.starts_with("/_part/")
|
||||
{
|
||||
return Err(format!("static mount `{mount}` is reserved"));
|
||||
}
|
||||
if app_admin_flag(&app) && path_under_prefix(&mount, &app_admin_prefix(&app)) {
|
||||
return Err(format!("static mount `{mount}` is reserved"));
|
||||
}
|
||||
let obj = app
|
||||
.as_object_mut()
|
||||
.ok_or_else(|| "app must be a map".to_string())?;
|
||||
@@ -1463,7 +1563,10 @@ web_ffi!(web_form_from_schema, |args: &Value| {
|
||||
None | Some(Value::Null) => None,
|
||||
Some(_) => Some(arg_text(args, "id")?),
|
||||
};
|
||||
form::from_schema(&url, &table, action, id.as_deref())
|
||||
let admin_prefix = arg_str_opt(args, "admin_prefix")
|
||||
.or_else(|| arg_str_opt(args, "后台前缀"))
|
||||
.unwrap_or("/admin");
|
||||
form::from_schema(&url, &table, action, id.as_deref(), admin_prefix)
|
||||
});
|
||||
|
||||
web_ffi!(web_db_table_info, |args: &Value| {
|
||||
@@ -1852,12 +1955,36 @@ web_ffi!(web_listen, |args: &Value| {
|
||||
r
|
||||
})
|
||||
.collect();
|
||||
let admin_cfg_app = args.get("app").cloned().unwrap_or_else(|| {
|
||||
json!({
|
||||
"admin": admin,
|
||||
"admin_prefix": arg_str_opt(args, "admin_prefix").unwrap_or("/admin"),
|
||||
"login_redirect": args.get("login_redirect").cloned().unwrap_or(Value::Null),
|
||||
"logout_redirect": args.get("logout_redirect").cloned().unwrap_or(Value::Null),
|
||||
})
|
||||
});
|
||||
let admin_prefix = app_admin_prefix(&admin_cfg_app);
|
||||
let login_redirect = admin_cfg_app
|
||||
.get("login_redirect")
|
||||
.and_then(|v| v.as_str())
|
||||
.filter(|s| !s.is_empty())
|
||||
.map(|s| s.to_string())
|
||||
.unwrap_or_else(|| admin_prefix.clone());
|
||||
let logout_redirect = admin_cfg_app
|
||||
.get("logout_redirect")
|
||||
.and_then(|v| v.as_str())
|
||||
.filter(|s| !s.is_empty())
|
||||
.map(|s| s.to_string())
|
||||
.unwrap_or_else(|| format!("{admin_prefix}/login"));
|
||||
http::listen(
|
||||
&page,
|
||||
db_url.as_deref(),
|
||||
&host,
|
||||
port,
|
||||
admin,
|
||||
&admin_prefix,
|
||||
&login_redirect,
|
||||
&logout_redirect,
|
||||
forms,
|
||||
routes,
|
||||
static_dir,
|
||||
@@ -2087,7 +2214,7 @@ pub unsafe extern "C" fn marqdo_plugin_init(host: *const MarqdoHostApi) -> c_int
|
||||
("web_db_list_tables", "url", web_db_list_tables as PluginFn),
|
||||
(
|
||||
"web_app_new",
|
||||
"page,db,admin,host,port",
|
||||
"page,db,admin,host,port,admin_prefix,login_redirect,logout_redirect",
|
||||
web_app_new as PluginFn,
|
||||
),
|
||||
("web_app_route", "app,path,page", web_app_route as PluginFn),
|
||||
@@ -2136,7 +2263,7 @@ pub unsafe extern "C" fn marqdo_plugin_init(host: *const MarqdoHostApi) -> c_int
|
||||
("web_auth_logout", "session_id", web_auth_logout as PluginFn),
|
||||
("web_password_hash", "password", web_password_hash as PluginFn),
|
||||
("web_auth_new", "users,session_ttl", web_auth_new as PluginFn),
|
||||
("web_app_auth", "app,users,session_ttl", web_app_auth as PluginFn),
|
||||
("web_app_auth", "app,users,session_ttl,admin_prefix,login_redirect,logout_redirect", web_app_auth as PluginFn),
|
||||
("web_app_gate", "app,path,roles", web_app_gate as PluginFn),
|
||||
(
|
||||
"web_app_gallery",
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
---
|
||||
title: web C0 admin prefix / route release
|
||||
description: admin=False frees /admin; custom admin_prefix reserves only that mount.
|
||||
import web:ext/web/web.mq.md
|
||||
import json:lib/json.mq.md
|
||||
import sys:lib/sys.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
*首页 = > web.page title="home"*
|
||||
*页 = > web.page title="news"*
|
||||
|
||||
*应用 = > web.app page=`首页` admin=False*
|
||||
*应用 = > `应用`.route path="/admin/news" page=`页`*
|
||||
*routes = > json.get value=`应用` key="routes"*
|
||||
*hit = > json.get value=`routes` key="/admin/news"*
|
||||
1. `hit`
|
||||
> print text=free-admin-ok
|
||||
2. *
|
||||
> print text=free-admin-fail
|
||||
> sys.exit code=1
|
||||
|
||||
*应用3 = > web.app page=`首页` admin=True admin_prefix="/desk"*
|
||||
*应用3 = > `应用3`.route path="/admin/news" page=`页`*
|
||||
*routes3 = > json.get value=`应用3` key="routes"*
|
||||
*hit3 = > json.get value=`routes3` key="/admin/news"*
|
||||
1. `hit3`
|
||||
> print text=prefix-frees-admin-ok
|
||||
2. *
|
||||
> print text=prefix-frees-admin-fail
|
||||
> sys.exit code=1
|
||||
|
||||
*prefix = > json.get value=`应用3` key="admin_prefix"*
|
||||
1. `prefix` == "/desk"
|
||||
> print text=prefix-stored-ok
|
||||
2. *
|
||||
> print text=prefix-stored-fail
|
||||
> sys.exit code=1
|
||||
|
||||
`用户表` =
|
||||
| 用户名 | 密码 | 角色 |
|
||||
|--------|------|------|
|
||||
| admin | secret | admin |
|
||||
|
||||
*应用4 = > web.app page=`首页` admin=True*
|
||||
*应用4 = > `应用4`.auth users=`用户表` admin_prefix="/desk" login_redirect="/desk" logout_redirect="/desk/login"*
|
||||
*prefix4 = > json.get value=`应用4` key="admin_prefix"*
|
||||
*login4 = > json.get value=`应用4` key="login_redirect"*
|
||||
*logout4 = > json.get value=`应用4` key="logout_redirect"*
|
||||
*gates = > json.get value=`应用4` key="gates"*
|
||||
*g0 = > at value=`gates` index=0*
|
||||
*gpath = > json.get value=`g0` key="path"*
|
||||
1. `prefix4` == "/desk"
|
||||
1. `login4` == "/desk"
|
||||
1. `logout4` == "/desk/login"
|
||||
1. `gpath` == "/desk*"
|
||||
> print text=auth-prefix-ok
|
||||
2. *
|
||||
> print text=auth-gate-fail
|
||||
> sys.exit code=1
|
||||
2. *
|
||||
> print text=auth-logout-fail
|
||||
> sys.exit code=1
|
||||
2. *
|
||||
> print text=auth-login-fail
|
||||
> sys.exit code=1
|
||||
2. *
|
||||
> print text=auth-prefix-fail
|
||||
> sys.exit code=1
|
||||
|
||||
> print text=c0-admin-ok
|
||||
Reference in new issue
Block a user