the dizey family joins the chrome: a services config names the siblings, the signed-in pages wear the in·im·iz wordmark trio with the current app inked, and the landing opens with a directory of cards above the account sections; logout grows a GET face for the relying parties' exit walk, its back admitted only as a local path or exactly one of the configured services' origins, and both faces revoke the central session so a sign-out anywhere ends the session everywhere
Browse files at this commitb230307f8c239cd0817ba99fefc105080bb288a0Parent: fbf69ca11 changed files +487 -7
- config/im.toml +18 -0
- crates/im-web/assets/main.css +65 -0
- crates/im-web/src/auth.rs +68 -1
- crates/im-web/src/config.rs +41 -0
- crates/im-web/src/directory.rs +154 -3
- crates/im-web/src/i18n.rs +3 -0
- crates/im-web/src/layout.rs +32 -0
- crates/im-web/src/pages.rs +32 -2
- crates/im-web/src/people.rs +2 -1
- crates/im-web/src/photo.rs +1 -0
- style/main.scss +71 -0
config/im.tomlmodified+18 -0
| @@ -2,6 +2,24 @@ database = "im.db" | ||
| 2 | 2 | listen = "127.0.0.1:7650" |
| 3 | 3 | issuer = "http://127.0.0.1:7650" |
| 4 | 4 | |
| 5 | +# The sibling apps of the switcher and the landing's services home, in | |
| 6 | +# wordmark order. Prod uses https://<key>.dizey.sh — deploy-side config, | |
| 7 | +# not committed here. | |
| 8 | +[[services]] | |
| 9 | +key = "in" | |
| 10 | +name = "Files" | |
| 11 | +url = "http://127.0.0.1:7655" | |
| 12 | + | |
| 13 | +[[services]] | |
| 14 | +key = "im" | |
| 15 | +name = "Account" | |
| 16 | +url = "http://127.0.0.1:7650" | |
| 17 | + | |
| 18 | +[[services]] | |
| 19 | +key = "iz" | |
| 20 | +name = "Board" | |
| 21 | +url = "http://127.0.0.1:7654" | |
| 22 | + | |
| 5 | 23 | # Without an [smtp] table the server runs in dev mode: invite links are |
| 6 | 24 | # printed to stdout instead of mailed. |
| 7 | 25 | # [smtp] |
crates/im-web/assets/main.cssmodified+65 -0
| @@ -319,11 +319,76 @@ body:has(.auth-stage) > .auth-stage::-webkit-scrollbar { | ||
| 319 | 319 | padding: 4px 0 10px; |
| 320 | 320 | } |
| 321 | 321 | |
| 322 | +.service-trio { | |
| 323 | + display: flex; | |
| 324 | + justify-content: center; | |
| 325 | + align-items: baseline; | |
| 326 | + gap: 10px; | |
| 327 | + padding: 0 0 2px; | |
| 328 | +} | |
| 329 | + | |
| 330 | +.trio-mark { | |
| 331 | + font-family: var(--font-mono); | |
| 332 | + font-size: 13px; | |
| 333 | + font-weight: 500; | |
| 334 | + letter-spacing: 0.02em; | |
| 335 | + text-decoration: none; | |
| 336 | + color: var(--muted); | |
| 337 | +} | |
| 338 | +.trio-mark:hover { | |
| 339 | + color: var(--ink); | |
| 340 | +} | |
| 341 | +.trio-mark-on { | |
| 342 | + color: var(--ink); | |
| 343 | + box-shadow: inset 0 -2px 0 var(--accent); | |
| 344 | +} | |
| 345 | + | |
| 346 | +.trio-sep { | |
| 347 | + color: var(--muted-soft); | |
| 348 | +} | |
| 349 | + | |
| 322 | 350 | .landing-stage .auth-column { |
| 323 | 351 | margin-top: max(24px, (100dvh - 640px) / 2); |
| 324 | 352 | margin-bottom: 24px; |
| 325 | 353 | } |
| 326 | 354 | |
| 355 | +.service-grid { | |
| 356 | + display: flex; | |
| 357 | + flex-wrap: wrap; | |
| 358 | + gap: 10px; | |
| 359 | +} | |
| 360 | + | |
| 361 | +.service-card { | |
| 362 | + flex: 1 1 140px; | |
| 363 | + display: flex; | |
| 364 | + align-items: center; | |
| 365 | + gap: 10px; | |
| 366 | + padding: 10px 14px; | |
| 367 | + border: 1px solid var(--border); | |
| 368 | + border-radius: var(--radius); | |
| 369 | + text-decoration: none; | |
| 370 | + color: inherit; | |
| 371 | +} | |
| 372 | +.service-card:hover { | |
| 373 | + border-color: var(--accent); | |
| 374 | + color: inherit; | |
| 375 | +} | |
| 376 | +.service-card-on { | |
| 377 | + border-color: var(--accent); | |
| 378 | + background: var(--accent-tint); | |
| 379 | +} | |
| 380 | + | |
| 381 | +.service-mark { | |
| 382 | + font-family: var(--font-mono); | |
| 383 | + font-size: 15px; | |
| 384 | + font-weight: 500; | |
| 385 | +} | |
| 386 | + | |
| 387 | +.service-name { | |
| 388 | + font-size: 13px; | |
| 389 | + color: var(--muted); | |
| 390 | +} | |
| 391 | + | |
| 327 | 392 | .auth-card { |
| 328 | 393 | background: var(--surface); |
| 329 | 394 | border: 1px solid var(--border); |
crates/im-web/src/auth.rsmodified+68 -1
| @@ -43,6 +43,47 @@ fn safe_back(raw: &str) -> &str { | ||
| 43 | 43 | } |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | +/// Where a logout sends the browser. A local absolute path always | |
| 47 | +/// qualifies — the login `back` rule. An absolute URL qualifies when its | |
| 48 | +/// origin is exactly one of the configured services': the sibling app that | |
| 49 | +/// sent the browser here gets it handed back. A foreign origin — and | |
| 50 | +/// anything unparseable — is refused to the front door. | |
| 51 | +fn logout_target(raw: Option<&str>, services: &[crate::config::Service]) -> String { | |
| 52 | + let Some(raw) = raw else { | |
| 53 | + return "/".to_string(); | |
| 54 | + }; | |
| 55 | + if raw.starts_with('/') && !raw.starts_with("//") { | |
| 56 | + return raw.to_string(); | |
| 57 | + } | |
| 58 | + if let Some(origin) = url_origin(raw) { | |
| 59 | + if services | |
| 60 | + .iter() | |
| 61 | + .any(|s| url_origin(&s.url).is_some_and(|known| known == origin)) | |
| 62 | + { | |
| 63 | + return raw.to_string(); | |
| 64 | + } | |
| 65 | + } | |
| 66 | + "/".to_string() | |
| 67 | +} | |
| 68 | + | |
| 69 | +/// The `scheme://authority` of an absolute http(s) URL, lowercased — the | |
| 70 | +/// whole of what an origin match compares. `None` for anything else. | |
| 71 | +fn url_origin(raw: &str) -> Option<String> { | |
| 72 | + let (scheme, rest) = raw.split_once("://")?; | |
| 73 | + if !scheme.eq_ignore_ascii_case("http") && !scheme.eq_ignore_ascii_case("https") { | |
| 74 | + return None; | |
| 75 | + } | |
| 76 | + let authority = rest.split(['/', '?', '#']).next()?; | |
| 77 | + if authority.is_empty() { | |
| 78 | + return None; | |
| 79 | + } | |
| 80 | + Some(format!( | |
| 81 | + "{}://{}", | |
| 82 | + scheme.to_ascii_lowercase(), | |
| 83 | + authority.to_ascii_lowercase() | |
| 84 | + )) | |
| 85 | +} | |
| 86 | + | |
| 46 | 87 | /// Creation-time facts for the session row: the address the browser came |
| 47 | 88 | /// through and the agent it claims to be. The accept loop discards the peer |
| 48 | 89 | /// address, so the proxy headers are the only source — the first |
| @@ -248,6 +289,14 @@ async fn enroll(cx: &Cx, Form(input): Form<TotpForm>) -> Redirect { | ||
| 248 | 289 | /// refresh token any app is still holding — see `sessions::revoke_session`. |
| 249 | 290 | #[route(POST "/logout")] |
| 250 | 291 | async fn logout(cx: &Cx) -> Redirect { |
| 292 | + sign_out_everywhere(cx).await?; | |
| 293 | + see("/".to_string()) | |
| 294 | +} | |
| 295 | + | |
| 296 | +/// The shared half of both logouts: the central session dies — with it | |
| 297 | +/// every refresh token and app session bound to it — and the cookie is | |
| 298 | +/// tidied. Where the browser goes next is each route's own business. | |
| 299 | +async fn sign_out_everywhere(cx: &Cx) -> Result<()> { | |
| 251 | 300 | if let Some(token) = server::presented_session(cx) { |
| 252 | 301 | let email = im_core::sessions::resolve_session(&server::app(cx).store, &token) |
| 253 | 302 | .await? |
| @@ -256,7 +305,25 @@ async fn logout(cx: &Cx) -> Redirect { | ||
| 256 | 305 | server::log_event(cx, "logout", email.as_deref(), None).await; |
| 257 | 306 | } |
| 258 | 307 | server::clear_session_cookie(cx); |
| 259 | - see("/".to_string()) | |
| 308 | + Ok(()) | |
| 309 | +} | |
| 310 | + | |
| 311 | +/// The RP-initiated exit: a sibling app has cleared its own cookie and | |
| 312 | +/// sent the browser here as a top-level navigation. `back` names the | |
| 313 | +/// return address, judged by [`logout_target`] — and the central session | |
| 314 | +/// dies whatever the answer is. | |
| 315 | +#[route(GET "/logout")] | |
| 316 | +async fn logout_return(cx: &Cx) -> Redirect { | |
| 317 | + let query = topcoat::router::request::uri(cx) | |
| 318 | + .query() | |
| 319 | + .unwrap_or("") | |
| 320 | + .to_string(); | |
| 321 | + let back = crate::pages::query_value(&query, "back"); | |
| 322 | + sign_out_everywhere(cx).await?; | |
| 323 | + see(logout_target( | |
| 324 | + back.as_deref(), | |
| 325 | + &server::app(cx).config.services, | |
| 326 | + )) | |
| 260 | 327 | } |
| 261 | 328 | |
| 262 | 329 | #[derive(Deserialize)] |
crates/im-web/src/config.rsmodified+41 -0
| @@ -25,6 +25,24 @@ pub struct Config { | ||
| 25 | 25 | /// The OIDC issuer — the public base URL every endpoint address and every |
| 26 | 26 | /// `iss` claim derives from. |
| 27 | 27 | pub issuer: String, |
| 28 | + pub services: Vec<Service>, | |
| 29 | +} | |
| 30 | + | |
| 31 | +/// One sibling app in the switcher and on the landing's services home: | |
| 32 | +/// the wordmark `key` ("in", "im", "iz" — im's own), a human `name`, and | |
| 33 | +/// the absolute base `url` without a trailing slash. | |
| 34 | +#[derive(Clone)] | |
| 35 | +pub struct Service { | |
| 36 | + pub key: String, | |
| 37 | + pub name: String, | |
| 38 | + pub url: String, | |
| 39 | +} | |
| 40 | + | |
| 41 | +#[derive(Deserialize)] | |
| 42 | +struct RawService { | |
| 43 | + key: String, | |
| 44 | + name: String, | |
| 45 | + url: String, | |
| 28 | 46 | } |
| 29 | 47 | |
| 30 | 48 | #[derive(Deserialize)] |
| @@ -32,6 +50,8 @@ struct Raw { | ||
| 32 | 50 | database: Option<String>, |
| 33 | 51 | listen: Option<String>, |
| 34 | 52 | issuer: Option<String>, |
| 53 | + #[serde(default)] | |
| 54 | + services: Vec<RawService>, | |
| 35 | 55 | } |
| 36 | 56 | |
| 37 | 57 | impl Config { |
| @@ -52,6 +72,26 @@ impl Config { | ||
| 52 | 72 | if !issuer.starts_with("http://") && !issuer.starts_with("https://") { |
| 53 | 73 | return Err(format!("{PATH}: issuer {issuer:?} must be an http(s) URL")); |
| 54 | 74 | } |
| 75 | + let mut services = Vec::new(); | |
| 76 | + for service in raw.services { | |
| 77 | + if !matches!(service.key.as_str(), "in" | "im" | "iz") { | |
| 78 | + return Err(format!( | |
| 79 | + "{PATH}: services: key {:?} must be in, im, or iz", | |
| 80 | + service.key | |
| 81 | + )); | |
| 82 | + } | |
| 83 | + if !service.url.starts_with("http://") && !service.url.starts_with("https://") { | |
| 84 | + return Err(format!( | |
| 85 | + "{PATH}: services.{}.url {:?} must be an http(s) URL", | |
| 86 | + service.key, service.url | |
| 87 | + )); | |
| 88 | + } | |
| 89 | + services.push(Service { | |
| 90 | + key: service.key, | |
| 91 | + name: service.name, | |
| 92 | + url: service.url.trim_end_matches('/').to_string(), | |
| 93 | + }); | |
| 94 | + } | |
| 55 | 95 | Ok(Config { |
| 56 | 96 | database: PathBuf::from(raw.database.unwrap_or_else(|| "im.db".to_string())), |
| 57 | 97 | listen: raw |
| @@ -60,6 +100,7 @@ impl Config { | ||
| 60 | 100 | .parse() |
| 61 | 101 | .map_err(|e| format!("{PATH}: listen: {e}"))?, |
| 62 | 102 | issuer: issuer.trim_end_matches('/').to_string(), |
| 103 | + services, | |
| 63 | 104 | }) |
| 64 | 105 | } |
| 65 | 106 |
crates/im-web/src/directory.rsmodified+154 -3
| @@ -53,21 +53,23 @@ mod tests { | ||
| 53 | 53 | |
| 54 | 54 | use im_core::accounts::{create_invite, create_user_from_invite}; |
| 55 | 55 | use im_core::oidc::create_client; |
| 56 | + use im_core::model::ClientId; | |
| 56 | 57 | use im_core::store::Store; |
| 57 | 58 | use topcoat::cookie::RouterBuilderCookieExt as _; |
| 58 | 59 | use topcoat::router::{Body, Router, RouterBuilderDiscoverExt as _, StatusCode, header, to_bytes}; |
| 59 | 60 | |
| 60 | 61 | use crate::config::Config; |
| 61 | - use crate::server; | |
| 62 | + use crate::server::{self, SESSION_COOKIE}; | |
| 62 | 63 | |
| 63 | 64 | struct Setup { |
| 64 | 65 | router: Router, |
| 65 | 66 | client_id: String, |
| 66 | 67 | secret: String, |
| 68 | + store: Arc<Store>, | |
| 67 | 69 | } |
| 68 | 70 | |
| 69 | 71 | async fn setup() -> Setup { |
| 70 | - let store = Store::open(Path::new(":memory:")).await.unwrap(); | |
| 72 | + let store = Arc::new(Store::open(Path::new(":memory:")).await.unwrap()); | |
| 71 | 73 | let (client_id, secret) = create_client(&store, "tasks", vec!["http://app/callback".into()]) |
| 72 | 74 | .await |
| 73 | 75 | .unwrap(); |
| @@ -94,11 +96,28 @@ mod tests { | ||
| 94 | 96 | .unwrap(); |
| 95 | 97 | let (live, _) = tokio::sync::broadcast::channel(64); |
| 96 | 98 | let app = server::App { |
| 97 | - store: Arc::new(store), | |
| 99 | + store: store.clone(), | |
| 98 | 100 | config: Config { |
| 99 | 101 | database: ":memory:".into(), |
| 100 | 102 | listen: "127.0.0.1:7650".parse().unwrap(), |
| 101 | 103 | issuer: "http://127.0.0.1:7650".into(), |
| 104 | + services: vec![ | |
| 105 | + crate::config::Service { | |
| 106 | + key: "in".into(), | |
| 107 | + name: "Files".into(), | |
| 108 | + url: "http://127.0.0.1:7655".into(), | |
| 109 | + }, | |
| 110 | + crate::config::Service { | |
| 111 | + key: "im".into(), | |
| 112 | + name: "Account".into(), | |
| 113 | + url: "http://127.0.0.1:7650".into(), | |
| 114 | + }, | |
| 115 | + crate::config::Service { | |
| 116 | + key: "iz".into(), | |
| 117 | + name: "Board".into(), | |
| 118 | + url: "http://127.0.0.1:7654".into(), | |
| 119 | + }, | |
| 120 | + ], | |
| 102 | 121 | }, |
| 103 | 122 | live, |
| 104 | 123 | }; |
| @@ -111,6 +130,7 @@ mod tests { | ||
| 111 | 130 | router, |
| 112 | 131 | client_id: client_id.to_string(), |
| 113 | 132 | secret: secret.expose().to_string(), |
| 133 | + store, | |
| 114 | 134 | } |
| 115 | 135 | } |
| 116 | 136 | |
| @@ -133,12 +153,60 @@ mod tests { | ||
| 133 | 153 | (parts.status, String::from_utf8(bytes).unwrap()) |
| 134 | 154 | } |
| 135 | 155 | |
| 156 | + /// A form post through the router, answered as (status, Location, body). | |
| 157 | + async fn post_form( | |
| 158 | + router: &Router, | |
| 159 | + uri: &str, | |
| 160 | + body: &str, | |
| 161 | + cookie: Option<&str>, | |
| 162 | + ) -> (StatusCode, Option<String>, String) { | |
| 163 | + let mut builder = http::Request::builder() | |
| 164 | + .method(http::Method::POST) | |
| 165 | + .uri(uri) | |
| 166 | + .header(header::CONTENT_TYPE, "application/x-www-form-urlencoded"); | |
| 167 | + if let Some(cookie) = cookie { | |
| 168 | + builder = builder.header(header::COOKIE, cookie); | |
| 169 | + } | |
| 170 | + let response = router | |
| 171 | + .handle(builder.body(Body::from(body.to_string())).unwrap()) | |
| 172 | + .await; | |
| 173 | + let (parts, body) = response.into_parts(); | |
| 174 | + let location = parts | |
| 175 | + .headers | |
| 176 | + .get(header::LOCATION) | |
| 177 | + .and_then(|v| v.to_str().ok()) | |
| 178 | + .map(str::to_string); | |
| 179 | + let bytes = to_bytes(body, usize::MAX).await.unwrap().to_vec(); | |
| 180 | + (parts.status, location, String::from_utf8(bytes).unwrap()) | |
| 181 | + } | |
| 182 | + | |
| 183 | + /// A top-level GET (the RP-initiated logout's shape), same answer triple. | |
| 184 | + async fn get_location(router: &Router, uri: &str, cookie: &str) -> (StatusCode, Option<String>) { | |
| 185 | + let response = router | |
| 186 | + .handle( | |
| 187 | + http::Request::builder() | |
| 188 | + .uri(uri) | |
| 189 | + .header(header::COOKIE, cookie) | |
| 190 | + .body(Body::empty()) | |
| 191 | + .unwrap(), | |
| 192 | + ) | |
| 193 | + .await; | |
| 194 | + let (parts, _) = response.into_parts(); | |
| 195 | + let location = parts | |
| 196 | + .headers | |
| 197 | + .get(header::LOCATION) | |
| 198 | + .and_then(|v| v.to_str().ok()) | |
| 199 | + .map(str::to_string); | |
| 200 | + (parts.status, location) | |
| 201 | + } | |
| 202 | + | |
| 136 | 203 | #[tokio::test] |
| 137 | 204 | async fn the_directory_names_every_non_disabled_user_with_its_admin_flag() { |
| 138 | 205 | let Setup { |
| 139 | 206 | router, |
| 140 | 207 | client_id, |
| 141 | 208 | secret, |
| 209 | + .. | |
| 142 | 210 | } = setup().await; |
| 143 | 211 | let (status, body) = get(&router, Some(basic(&client_id, &secret))).await; |
| 144 | 212 | assert_eq!(status, StatusCode::OK); |
| @@ -173,4 +241,87 @@ mod tests { | ||
| 173 | 241 | let (status, _) = get(&router, Some(basic("no-such-client", "wrong"))).await; |
| 174 | 242 | assert_eq!(status, StatusCode::UNAUTHORIZED); |
| 175 | 243 | } |
| 244 | + | |
| 245 | + #[tokio::test] | |
| 246 | + async fn logout_revokes_the_central_session_and_only_returns_known_origins() { | |
| 247 | + let Setup { | |
| 248 | + router, | |
| 249 | + client_id, | |
| 250 | + secret, | |
| 251 | + store, | |
| 252 | + } = setup().await; | |
| 253 | + let ada = im_core::accounts::user_by_email(&store, "ada@example.com") | |
| 254 | + .await | |
| 255 | + .unwrap() | |
| 256 | + .unwrap(); | |
| 257 | + | |
| 258 | + // The RP-initiated exit: `back` naming a configured service's own | |
| 259 | + // origin is honored verbatim — the sibling gets its browser back. | |
| 260 | + let one = im_core::sessions::create_session(&store, &ada.id, &Default::default()) | |
| 261 | + .await | |
| 262 | + .unwrap(); | |
| 263 | + let (status, location) = get_location( | |
| 264 | + &router, | |
| 265 | + "/logout?back=http%3A%2F%2F127.0.0.1%3A7655%2F", | |
| 266 | + &format!("{SESSION_COOKIE}={}", one.expose()), | |
| 267 | + ) | |
| 268 | + .await; | |
| 269 | + assert_eq!(status, StatusCode::SEE_OTHER); | |
| 270 | + assert_eq!(location.as_deref(), Some("http://127.0.0.1:7655/")); | |
| 271 | + | |
| 272 | + // A live app session bound to a second central session introspects | |
| 273 | + // active — until a logout with a foreign `back` lands. The refusal | |
| 274 | + // itself goes to the front door, and the revocation still lands: | |
| 275 | + // the very next introspection is inactive. | |
| 276 | + let two = im_core::sessions::create_session(&store, &ada.id, &Default::default()) | |
| 277 | + .await | |
| 278 | + .unwrap(); | |
| 279 | + let app_token = im_core::oidc::issue_app_session( | |
| 280 | + &store, | |
| 281 | + &ada.id, | |
| 282 | + &ClientId::from(client_id.clone()), | |
| 283 | + &im_core::accounts::hash_token(two.expose()), | |
| 284 | + ) | |
| 285 | + .await | |
| 286 | + .unwrap(); | |
| 287 | + let probe = format!( | |
| 288 | + "token={}&client_id={client_id}&client_secret={secret}", | |
| 289 | + app_token.expose() | |
| 290 | + ); | |
| 291 | + let (status, _, body) = post_form(&router, "/introspect", &probe, None).await; | |
| 292 | + assert_eq!(status, StatusCode::OK); | |
| 293 | + assert_eq!( | |
| 294 | + serde_json::from_str::<serde_json::Value>(&body).unwrap()["active"], | |
| 295 | + true | |
| 296 | + ); | |
| 297 | + | |
| 298 | + let (status, location) = get_location( | |
| 299 | + &router, | |
| 300 | + "/logout?back=https%3A%2F%2Fevil.example%2F", | |
| 301 | + &format!("{SESSION_COOKIE}={}", two.expose()), | |
| 302 | + ) | |
| 303 | + .await; | |
| 304 | + assert_eq!(status, StatusCode::SEE_OTHER); | |
| 305 | + assert_eq!(location.as_deref(), Some("/")); | |
| 306 | + let (status, _, body) = post_form(&router, "/introspect", &probe, None).await; | |
| 307 | + assert_eq!(status, StatusCode::OK); | |
| 308 | + assert_eq!( | |
| 309 | + serde_json::from_str::<serde_json::Value>(&body).unwrap()["active"], | |
| 310 | + false | |
| 311 | + ); | |
| 312 | + | |
| 313 | + // im's own form logout is untouched: front door, no `back` at all. | |
| 314 | + let three = im_core::sessions::create_session(&store, &ada.id, &Default::default()) | |
| 315 | + .await | |
| 316 | + .unwrap(); | |
| 317 | + let (status, location, _) = post_form( | |
| 318 | + &router, | |
| 319 | + "/logout", | |
| 320 | + "", | |
| 321 | + Some(&format!("{SESSION_COOKIE}={}", three.expose())), | |
| 322 | + ) | |
| 323 | + .await; | |
| 324 | + assert_eq!(status, StatusCode::SEE_OTHER); | |
| 325 | + assert_eq!(location.as_deref(), Some("/")); | |
| 326 | + } | |
| 176 | 327 | } |
crates/im-web/src/i18n.rsmodified+3 -0
| @@ -126,6 +126,7 @@ pub enum Key { | ||
| 126 | 126 | StatActiveSessions, |
| 127 | 127 | StatConnectedApps, |
| 128 | 128 | SessionsTitle, |
| 129 | + ServicesTitle, | |
| 129 | 130 | SignOutEverywhere, |
| 130 | 131 | AdminPanelLink, |
| 131 | 132 | ViewPhotoAria, |
| @@ -447,6 +448,8 @@ pub fn t(lang: Lang, key: Key) -> &'static str { | ||
| 447 | 448 | (StatConnectedApps, Tr) => "Bağlı uygulamalar", |
| 448 | 449 | (SessionsTitle, En) => "Sessions", |
| 449 | 450 | (SessionsTitle, Tr) => "Oturumlar", |
| 451 | + (ServicesTitle, En) => "Services", | |
| 452 | + (ServicesTitle, Tr) => "Hizmetler", | |
| 450 | 453 | (SignOutEverywhere, En) => "Sign out everywhere", |
| 451 | 454 | (SignOutEverywhere, Tr) => "Her yerde oturumu kapat", |
| 452 | 455 | (AdminPanelLink, En) => "Admin panel", |
crates/im-web/src/layout.rsmodified+32 -0
| @@ -8,6 +8,7 @@ use topcoat::context::Cx; | ||
| 8 | 8 | use topcoat::view::view; |
| 9 | 9 | |
| 10 | 10 | use crate::i18n::{Key, Lang, lang_of, t}; |
| 11 | +use crate::server; | |
| 11 | 12 | |
| 12 | 13 | /// `style/main.scss`, compiled by `build.rs` into `assets/main.css`. |
| 13 | 14 | const STYLE: Asset = asset!("assets/main.css"); |
| @@ -23,6 +24,37 @@ pub async fn wordmark(cx: &Cx) -> Result { | ||
| 23 | 24 | } |
| 24 | 25 | } |
| 25 | 26 | |
| 27 | +/// The signed-in chrome's app trio: every configured service's wordmark, | |
| 28 | +/// middots between, the home one (`im`) inked and marked current, its | |
| 29 | +/// siblings plain links. A deployment that names no services renders | |
| 30 | +/// nothing — the single mark above stays the whole chrome. | |
| 31 | +pub async fn service_trio(cx: &Cx) -> Result { | |
| 32 | + let services = &server::app(cx).config.services; | |
| 33 | + let marks = (!services.is_empty()).then(|| { | |
| 34 | + services | |
| 35 | + .iter() | |
| 36 | + .map(|service| { | |
| 37 | + let key = crate::pages::escape(&service.key); | |
| 38 | + if service.key == "im" { | |
| 39 | + format!( | |
| 40 | + r#"<span class="trio-mark trio-mark-on" aria-current="page">{key}</span>"# | |
| 41 | + ) | |
| 42 | + } else { | |
| 43 | + let url = crate::pages::escape(&service.url); | |
| 44 | + format!(r#"<a class="trio-mark" href="{url}">{key}</a>"#) | |
| 45 | + } | |
| 46 | + }) | |
| 47 | + .collect::<Vec<_>>() | |
| 48 | + .join(r#"<span class="trio-sep">·</span>"#) | |
| 49 | + }); | |
| 50 | + view! { | |
| 51 | + cx => | |
| 52 | + if let Some(marks) = marks { | |
| 53 | + <nav class="service-trio">(topcoat::view::Unescaped::new_unchecked(marks))</nav> | |
| 54 | + } | |
| 55 | + } | |
| 56 | +} | |
| 57 | + | |
| 26 | 58 | /// The profile card's face: the photo when the account has one, the name's |
| 27 | 59 | /// first letter on a quiet tile when it does not. The URL's stamp comes from |
| 28 | 60 | /// `photo::PhotoStamps`, so a changed photo is a changed URL. |
crates/im-web/src/pages.rsmodified+32 -2
| @@ -12,7 +12,7 @@ use topcoat::router::{page, path_param, route}; | ||
| 12 | 12 | use topcoat::view::view; |
| 13 | 13 | |
| 14 | 14 | use crate::i18n::{Key, Lang, lang_of, t}; |
| 15 | -use crate::layout::{avatar, shell, wordmark}; | |
| 15 | +use crate::layout::{avatar, service_trio, shell, wordmark}; | |
| 16 | 16 | use crate::server::{self, PendingPurpose}; |
| 17 | 17 | |
| 18 | 18 | path_param!(token); |
| @@ -429,7 +429,7 @@ async fn enroll(cx: &Cx) -> Result<Response> { | ||
| 429 | 429 | /// so its interpolations never pass through `view!`'s escaping. The |
| 430 | 430 | /// discipline matches admin.rs's `escape`: everything user-controlled |
| 431 | 431 | /// (agent, address) crosses it before it reaches the markup. |
| 432 | -fn escape(raw: &str) -> String { | |
| 432 | +pub(crate) fn escape(raw: &str) -> String { | |
| 433 | 433 | raw.replace('&', "&") |
| 434 | 434 | .replace('<', "<") |
| 435 | 435 | .replace('>', ">") |
| @@ -601,12 +601,42 @@ async fn signed_in(cx: &Cx, user: &im_core::model::User) -> Result { | ||
| 601 | 601 | ) |
| 602 | 602 | }) |
| 603 | 603 | .collect::<String>(); |
| 604 | + // The services home: one card per configured app — wordmark and name, | |
| 605 | + // the whole card the link. im's own card reads current. Above the | |
| 606 | + // profile sections: im is the account center, and its landing is the | |
| 607 | + // door to the rest. | |
| 608 | + let services_html = server::app(cx) | |
| 609 | + .config | |
| 610 | + .services | |
| 611 | + .iter() | |
| 612 | + .map(|service| { | |
| 613 | + let current = service.key == "im"; | |
| 614 | + let open = if current { | |
| 615 | + r#"<span class="service-card service-card-on" aria-current="page">"#.to_string() | |
| 616 | + } else { | |
| 617 | + format!(r#"<a class="service-card" href="{}">"#, escape(&service.url)) | |
| 618 | + }; | |
| 619 | + format!( | |
| 620 | + r#"{open}<span class="service-mark">{}</span><span class="service-name">{}</span></{}>"#, | |
| 621 | + escape(&service.key), | |
| 622 | + escape(&service.name), | |
| 623 | + if current { "span" } else { "a" }, | |
| 624 | + ) | |
| 625 | + }) | |
| 626 | + .collect::<String>(); | |
| 604 | 627 | let stage = view! { |
| 605 | 628 | cx => |
| 606 | 629 | <main class="auth-stage landing-stage"> |
| 607 | 630 | <div class="auth-column"> |
| 608 | 631 | (wordmark(cx).await?) |
| 632 | + (service_trio(cx).await?) | |
| 609 | 633 | <nav class="admin-tabs landing-nav">(topcoat::view::Unescaped::new_unchecked(nav))</nav> |
| 634 | + if !services_html.is_empty() { | |
| 635 | + <div class="auth-card"> | |
| 636 | + <div class="auth-title">(t(lang, Key::ServicesTitle))</div> | |
| 637 | + <div class="service-grid">(topcoat::view::Unescaped::new_unchecked(services_html))</div> | |
| 638 | + </div> | |
| 639 | + } | |
| 610 | 640 | if let Some(code) = ok { |
| 611 | 641 | <div class="auth-ok">(ok_text(&code, lang))</div> |
| 612 | 642 | } |
crates/im-web/src/people.rsmodified+2 -1
| @@ -14,7 +14,7 @@ use topcoat::view::view; | ||
| 14 | 14 | use im_core::accounts; |
| 15 | 15 | |
| 16 | 16 | use crate::i18n::{Key, lang_of, t}; |
| 17 | -use crate::layout::{avatar, shell, wordmark}; | |
| 17 | +use crate::layout::{avatar, service_trio, shell, wordmark}; | |
| 18 | 18 | use crate::server; |
| 19 | 19 | |
| 20 | 20 | path_param!(user_id); |
| @@ -40,6 +40,7 @@ async fn people_page(cx: &Cx) -> Result { | ||
| 40 | 40 | <main class="auth-stage"> |
| 41 | 41 | <div class="auth-column"> |
| 42 | 42 | (wordmark(cx).await?) |
| 43 | + (service_trio(cx).await?) | |
| 43 | 44 | <div class="auth-card"> |
| 44 | 45 | <div class="profile-head"> |
| 45 | 46 | if person.has_photo { |
crates/im-web/src/photo.rsmodified+1 -0
| @@ -326,6 +326,7 @@ mod tests { | ||
| 326 | 326 | database: ":memory:".into(), |
| 327 | 327 | listen: "127.0.0.1:7650".parse().unwrap(), |
| 328 | 328 | issuer: "http://127.0.0.1:7650".into(), |
| 329 | + services: Vec::new(), | |
| 329 | 330 | }, |
| 330 | 331 | live, |
| 331 | 332 | }; |
style/main.scssmodified+71 -0
| @@ -279,6 +279,35 @@ body:has(.auth-stage) { | ||
| 279 | 279 | padding: 4px 0 10px; |
| 280 | 280 | } |
| 281 | 281 | |
| 282 | +// The app trio under the signed-in wordmark: lower-case marks in the | |
| 283 | +// wordmark's mono, the home one inked, its siblings quiet links. The | |
| 284 | +// middots are part of the mark, not decoration between cards. | |
| 285 | +.service-trio { | |
| 286 | + display: flex; | |
| 287 | + justify-content: center; | |
| 288 | + align-items: baseline; | |
| 289 | + gap: 10px; | |
| 290 | + padding: 0 0 2px; | |
| 291 | +} | |
| 292 | + | |
| 293 | +.trio-mark { | |
| 294 | + font-family: var(--font-mono); | |
| 295 | + font-size: 13px; | |
| 296 | + font-weight: 500; | |
| 297 | + letter-spacing: 0.02em; | |
| 298 | + text-decoration: none; | |
| 299 | + color: var(--muted); | |
| 300 | + | |
| 301 | + &:hover { color: var(--ink); } | |
| 302 | + | |
| 303 | + &-on { | |
| 304 | + color: var(--ink); | |
| 305 | + box-shadow: inset 0 -2px 0 var(--accent); | |
| 306 | + } | |
| 307 | +} | |
| 308 | + | |
| 309 | +.trio-sep { color: var(--muted-soft); } | |
| 310 | + | |
| 282 | 311 | // The landing's column tops out where it would sit if the TALLEST section |
| 283 | 312 | // were the one being centred: the wordmark and tab row hold that line on |
| 284 | 313 | // every section, and shorter sections simply end sooner below it. 640px |
| @@ -290,6 +319,48 @@ body:has(.auth-stage) { | ||
| 290 | 319 | margin-bottom: 24px; |
| 291 | 320 | } |
| 292 | 321 | |
| 322 | +// The landing's services home: one card per configured app — wordmark and | |
| 323 | +// name on one line, the whole card the link. im's own card reads current: | |
| 324 | +// accent border, tinted, no pointer. | |
| 325 | +.service-grid { | |
| 326 | + display: flex; | |
| 327 | + flex-wrap: wrap; | |
| 328 | + gap: 10px; | |
| 329 | +} | |
| 330 | + | |
| 331 | +.service-card { | |
| 332 | + flex: 1 1 140px; | |
| 333 | + display: flex; | |
| 334 | + align-items: center; | |
| 335 | + gap: 10px; | |
| 336 | + padding: 10px 14px; | |
| 337 | + border: 1px solid var(--border); | |
| 338 | + border-radius: var(--radius); | |
| 339 | + text-decoration: none; | |
| 340 | + color: inherit; | |
| 341 | + | |
| 342 | + &:hover { | |
| 343 | + border-color: var(--accent); | |
| 344 | + color: inherit; | |
| 345 | + } | |
| 346 | + | |
| 347 | + &-on { | |
| 348 | + border-color: var(--accent); | |
| 349 | + background: var(--accent-tint); | |
| 350 | + } | |
| 351 | +} | |
| 352 | + | |
| 353 | +.service-mark { | |
| 354 | + font-family: var(--font-mono); | |
| 355 | + font-size: 15px; | |
| 356 | + font-weight: 500; | |
| 357 | +} | |
| 358 | + | |
| 359 | +.service-name { | |
| 360 | + font-size: 13px; | |
| 361 | + color: var(--muted); | |
| 362 | +} | |
| 363 | + | |
| 293 | 364 | |
| 294 | 365 | |
| 295 | 366 | .auth-card { |