From 25140f308a711d4090fa75bb29558a3f5335587c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Thu, 10 Sep 2026 01:29:31 +0300 Subject: [PATCH] chore: bump remaining crates to latest topcoat 0.8, ulid 3, chacha20poly1305 0.11, base64 0.23, rsa 0.10-rc.18. --- Cargo.lock | 325 ++++++++++++++++-------------- Cargo.toml | 6 +- crates/im-client/Cargo.toml | 17 +- crates/im-client/src/directory.rs | 8 +- crates/im-client/src/oidc.rs | 20 +- crates/im-core/Cargo.toml | 11 +- crates/im-core/src/accounts.rs | 38 ++-- crates/im-core/src/events.rs | 2 +- crates/im-core/src/keys.rs | 7 +- crates/im-core/src/model.rs | 2 +- crates/im-core/src/oidc.rs | 12 +- crates/im-core/src/photos.rs | 4 +- crates/im-core/src/secret.rs | 6 +- crates/im-core/src/settings.rs | 25 ++- crates/im-core/src/store.rs | 2 +- crates/im-migrate/src/main.rs | 2 +- crates/im-web/Cargo.toml | 2 +- crates/im-web/src/admin.rs | 253 ++++++++++++----------- crates/im-web/src/auth.rs | 21 +- crates/im-web/src/dropdown.rs | 6 +- crates/im-web/src/layout.rs | 67 +++--- crates/im-web/src/live.rs | 102 +++++----- crates/im-web/src/pages.rs | 139 ++++++++----- crates/im-web/src/people.rs | 35 ++-- crates/im-web/src/server.rs | 4 +- 25 files changed, 605 insertions(+), 511 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f8cf2e5..a457196 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -18,6 +18,16 @@ dependencies = [ "generic-array", ] +[[package]] +name = "aead" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1973cfbc1a2daf9cf550e74e1f088c28e7f7d8c1e1418fb6c9dc5184b7e84c99" +dependencies = [ + "crypto-common 0.2.2", + "inout 0.2.2", +] + [[package]] name = "aegis" version = "0.9.15" @@ -35,7 +45,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0" dependencies = [ "cfg-if", - "cipher", + "cipher 0.4.4", "cpufeatures 0.2.17", ] @@ -45,9 +55,9 @@ version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "831010a0f742e1209b3bcea8fab6a8e149051ba6099432c8cb2cc117dec3ead1" dependencies = [ - "aead", + "aead 0.5.2", "aes", - "cipher", + "cipher 0.4.4", "ctr", "ghash", "subtle", @@ -293,6 +303,12 @@ dependencies = [ "pkg-config", ] +[[package]] +name = "base16ct" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd307490d624467aa6f74b0eabb77633d1f758a7b25f12bceb0b22e08d9726f6" + [[package]] name = "base64" version = "0.22.1" @@ -537,17 +553,6 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "18758054972164c3264f7c8386f5fc6da6114cb46b619fd365d4e3b2dc3ae487" -[[package]] -name = "chacha20" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3613f74bd2eac03dad61bd53dbe620703d4371614fe0bc3b9f04dd36fe4e818" -dependencies = [ - "cfg-if", - "cipher", - "cpufeatures 0.2.17", -] - [[package]] name = "chacha20" version = "0.10.2" @@ -555,21 +560,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "65c35e4b699c7e15ccbe7ee35c005e4fc0a278d22238a2857e6ce2dadeda1b06" dependencies = [ "cfg-if", + "cipher 0.5.2", "cpufeatures 0.3.1", "rand_core 0.10.1", ] [[package]] name = "chacha20poly1305" -version = "0.10.1" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10cd79432192d1c0f4e1a0fef9527696cc039165d729fb41b3f4f4f354c2dc35" +checksum = "9b89e1c441e926b9c82a8d023f6e1b7ae0adcfaa7d621814e4d60789bac751cb" dependencies = [ - "aead", - "chacha20 0.9.1", - "cipher", + "aead 0.6.1", + "chacha20", + "cipher 0.5.2", "poly1305", - "zeroize", ] [[package]] @@ -592,8 +597,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad" dependencies = [ "crypto-common 0.1.7", - "inout", - "zeroize", + "inout 0.1.4", +] + +[[package]] +name = "cipher" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8cf2a2c93cd704877c0858356ed03480ff301ee950b43f1cbe4573b088bfa6c" +dependencies = [ + "block-buffer 0.12.1", + "crypto-common 0.2.2", + "inout 0.2.2", ] [[package]] @@ -698,12 +713,6 @@ dependencies = [ "crossbeam-utils", ] -[[package]] -name = "const-oid" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" - [[package]] name = "const-oid" version = "0.10.2" @@ -750,6 +759,12 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f8f80099a98041a3d1622845c271458a2d73e688351bf3cb999266764b81d48" +[[package]] +name = "cpubits" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15b85f9c39137c3a891689859392b1bd49812121d0d61c9caf00d46ed5ce06ae" + [[package]] name = "cpufeatures" version = "0.2.17" @@ -826,6 +841,20 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "460fbee9c2c2f33933d720630a6a0bac33ba7053db5344fac858d4b8952d77d5" +[[package]] +name = "crypto-bigint" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a52aa3fcda4e6302a9f48734f234d35d4721b96f8fe07d073f07ce9df4f0271" +dependencies = [ + "cpubits", + "ctutils", + "num-traits", + "rand_core 0.10.1", + "serdect", + "zeroize", +] + [[package]] name = "crypto-common" version = "0.1.7" @@ -843,7 +872,19 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ce6e4c961d6cd6c9a86db418387425e8bdeaf05b3c8bc1411e6dca4c252f1453" dependencies = [ + "getrandom 0.4.3", "hybrid-array", + "rand_core 0.10.1", +] + +[[package]] +name = "crypto-primes" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3633a51a39c69ebbaa4feaa694bd83d241e4093901c84a0963b19d9bb3f0cf8f" +dependencies = [ + "crypto-bigint", + "rand_core 0.10.1", ] [[package]] @@ -852,7 +893,7 @@ version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0369ee1ad671834580515889b80f2ea915f23b8be8d0daa4bbaf2ac5c7590835" dependencies = [ - "cipher", + "cipher 0.4.4", ] [[package]] @@ -912,11 +953,11 @@ checksum = "c286de4e81ea2590afc24d754e0f83810c566f50a1388fa75ebd57928c0d9745" [[package]] name = "der" -version = "0.7.10" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7c1832837b905bbfb5101e07cc24c8deddf52f93225eee6ead5f4d63d53ddcb" +checksum = "a878c850e9e421b20262e9b41f9c860e4785fa07541c266b62ff9d1ef998a80a" dependencies = [ - "const-oid 0.9.6", + "const-oid", "pem-rfc7468", "zeroize", ] @@ -937,7 +978,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer 0.10.4", - "const-oid 0.9.6", "crypto-common 0.1.7", "subtle", ] @@ -949,7 +989,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1dd6dbb5841937940781866fa1281a1ff7bd3bf827091440879f9994983d5c2" dependencies = [ "block-buffer 0.12.1", - "const-oid 0.10.2", + "const-oid", "crypto-common 0.2.2", "ctutils", ] @@ -1782,16 +1822,15 @@ dependencies = [ name = "im-client" version = "0.1.0" dependencies = [ - "base64 0.22.1", + "base64 0.23.1", "chacha20poly1305", "http", "rand 0.10.2", - "rand_core 0.6.4", + "rand_core 0.10.1", "reqwest", "rsa", "serde", "serde_json", - "sha2 0.10.9", "sha2 0.11.0", "subtle", "thiserror", @@ -1805,17 +1844,16 @@ name = "im-core" version = "0.1.0" dependencies = [ "argon2", - "base64 0.22.1", + "base64 0.23.1", "chacha20poly1305", "data-encoding", "hmac 0.13.0", "rand 0.10.2", - "rand_core 0.6.4", + "rand_core 0.10.1", "rsa", "serde", "serde_json", "sha1 0.11.0", - "sha2 0.10.9", "sha2 0.11.0", "subtle", "tempfile", @@ -1842,7 +1880,7 @@ dependencies = [ name = "im-web" version = "0.1.0" dependencies = [ - "base64 0.22.1", + "base64 0.23.1", "data-encoding", "futures-util", "grass", @@ -1880,6 +1918,15 @@ dependencies = [ "generic-array", ] +[[package]] +name = "inout" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4250ce6452e92010fdf7268ccc5d14faa80bb12fc741938534c58f16804e03c7" +dependencies = [ + "hybrid-array", +] + [[package]] name = "intrusive-collections" version = "0.9.7" @@ -2029,9 +2076,6 @@ name = "lazy_static" version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" -dependencies = [ - "spin", -] [[package]] name = "lazycell" @@ -2391,22 +2435,6 @@ dependencies = [ "num-traits", ] -[[package]] -name = "num-bigint-dig" -version = "0.8.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e661dda6640fad38e827a6d4a310ff4763082116fe217f279885c97f511bb0b7" -dependencies = [ - "lazy_static", - "libm", - "num-integer", - "num-iter", - "num-traits", - "rand 0.8.8", - "smallvec", - "zeroize", -] - [[package]] name = "num-conv" version = "0.2.2" @@ -2422,16 +2450,6 @@ dependencies = [ "num-traits", ] -[[package]] -name = "num-iter" -version = "0.1.46" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c92800bd69a1eac91786bcfe9da64a897eb72911b8dc3095decbd07429e8048b" -dependencies = [ - "num-integer", - "num-traits", -] - [[package]] name = "num-traits" version = "0.2.19" @@ -2439,7 +2457,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", - "libm", ] [[package]] @@ -2546,9 +2563,9 @@ checksum = "2ee67f1008b1ba2321834326597b8e186293b049a023cdef258527550b9935b4" [[package]] name = "pem-rfc7468" -version = "0.7.0" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88b39c9bfcfc231068454382784bb460aae594343fb030d46e9f50a645418412" +checksum = "a6305423e0e7738146434843d1694d621cce767262b2a86910beab705e4493d9" dependencies = [ "base64ct", ] @@ -2620,20 +2637,19 @@ checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" [[package]] name = "pkcs1" -version = "0.7.5" +version = "0.8.0-rc.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8ffb9f10fa047879315e6625af03c164b16962a5368d724ed16323b68ace47f" +checksum = "986d2e952779af96ea048f160fd9194e1751b4faea78bcf3ceb456efe008088e" dependencies = [ "der", - "pkcs8", "spki", ] [[package]] name = "pkcs8" -version = "0.10.2" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" +checksum = "451913da69c775a56034ea8d9003d27ee8948e12443eae7c038ba100a4f21cb7" dependencies = [ "der", "spki", @@ -2661,13 +2677,12 @@ dependencies = [ [[package]] name = "poly1305" -version = "0.8.0" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8159bd90725d2df49889a078b54f4f79e87f1f8a8444194cdca81d38f5393abf" +checksum = "6e2d0073b297041425c7c3df6eb4792d598a15323fe63346852b092eca02904c" dependencies = [ - "cpufeatures 0.2.17", - "opaque-debug", - "universal-hash", + "cpufeatures 0.3.1", + "universal-hash 0.6.1", ] [[package]] @@ -2679,7 +2694,7 @@ dependencies = [ "cfg-if", "cpufeatures 0.2.17", "opaque-debug", - "universal-hash", + "universal-hash 0.5.1", ] [[package]] @@ -2892,7 +2907,7 @@ version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c7f5fa3a058cd35567ef9bfa5e75732bee0f9e4c55fa90477bef2dfcdbc4be80" dependencies = [ - "chacha20 0.10.2", + "chacha20", "getrandom 0.4.3", "rand_core 0.10.1", ] @@ -3110,21 +3125,19 @@ dependencies = [ [[package]] name = "rsa" -version = "0.9.10" +version = "0.10.0-rc.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8573f03f5883dcaebdfcf4725caa1ecb9c15b2ef50c43a07b816e06799bb12d" +checksum = "30b2aa4ba0d89f73d1e332df05be0eeab8840351c36ca5654341dfdb57bb3caf" dependencies = [ - "const-oid 0.9.6", - "digest 0.10.7", - "num-bigint-dig", - "num-integer", - "num-traits", + "const-oid", + "crypto-bigint", + "crypto-primes", + "digest 0.11.3", "pkcs1", "pkcs8", - "rand_core 0.6.4", + "rand_core 0.10.1", "signature", "spki", - "subtle", "zeroize", ] @@ -3418,6 +3431,16 @@ dependencies = [ "serde", ] +[[package]] +name = "serdect" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "66cf8fedced2fcf12406bcb34223dffb92eaf34908ede12fed414c82b7f00b3e" +dependencies = [ + "base16ct", + "serde", +] + [[package]] name = "sha1" version = "0.10.7" @@ -3521,12 +3544,12 @@ dependencies = [ [[package]] name = "signature" -version = "2.2.0" +version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" +checksum = "28d567dcbaf0049cb8ac2608a76cd95ff9e4412e1899d389ee400918ca7537f5" dependencies = [ - "digest 0.10.7", - "rand_core 0.6.4", + "digest 0.11.3", + "rand_core 0.10.1", ] [[package]] @@ -3611,9 +3634,9 @@ checksum = "3763264f6b73151db08c50ff20d7d8a0b8796e021cdea7ceedad07b80155fa0e" [[package]] name = "spki" -version = "0.7.3" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" +checksum = "1d9efca8738c78ee9484207732f728b1ef517bbb1833d6fc0879ca898a522f6f" dependencies = [ "base64ct", "der", @@ -4076,14 +4099,13 @@ checksum = "7d56353a2a665ad0f41a421187180aab746c8c325620617ad883a99a1cbe66d2" [[package]] name = "topcoat" -version = "0.6.2" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "050c11e7b0e146a2b1eb15855abd5fa03e2754eb880922f8b6cab5ec71cac5aa" +checksum = "f3c199295b1c52e0a9c88a2b0518f6bc7522503cd0bb06d9f4742c515ac4df0a" dependencies = [ "futures-util", "inventory", "serde", - "serde_urlencoded", "tokio", "tokio-tungstenite", "topcoat-asset", @@ -4104,9 +4126,9 @@ dependencies = [ [[package]] name = "topcoat-asset" -version = "0.6.2" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a72e4ba8cb6a9d29613a25c2151e72d887b4a79b3f179b497734eed0e65ea702" +checksum = "fba199ae779d0409672929e7c32711ac35e87c9e39e0823d0b33b6293e3e0011" dependencies = [ "http", "memchr", @@ -4122,9 +4144,9 @@ dependencies = [ [[package]] name = "topcoat-cookie" -version = "0.6.2" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f68c83654c4bf075f667d39463cd38ef0be9fee057054454b06612efe16e7a37" +checksum = "3cb0bf2f95c1931d32d579389695e8cf221d114f9629a57fc005d7a0bb459c0d" dependencies = [ "cookie", "getrandom 0.2.17", @@ -4137,9 +4159,9 @@ dependencies = [ [[package]] name = "topcoat-core" -version = "0.6.2" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42f94adaa301d7a4b949d650fa803323c00cc8ffa8bf1984511c1ec5d390b6c6" +checksum = "d88c5ed693dd383ba8a4112f5b665bdb7e979ada413a7b5f9ede6935fe18e8e6" dependencies = [ "anyhow", "anymap3", @@ -4153,9 +4175,9 @@ dependencies = [ [[package]] name = "topcoat-core-grammar" -version = "0.6.2" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0756aa9285794c155624494bc563d56859e35205313db883a89d7dabfa6d0393" +checksum = "ce257f5c2248b4d7bf1bbd76a0e71709221f06d690462a49aad5929732c42001" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -4165,9 +4187,9 @@ dependencies = [ [[package]] name = "topcoat-core-macro" -version = "0.6.2" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4908dba6268c8592be73e9059cdefa053066e1b1bc879c1c9a5d8d3b6e97aad" +checksum = "5d239098a8c674f16120e7bfcba6f670865c807eec2a0e2648cb319d300fab39" dependencies = [ "quote", "syn 2.0.119", @@ -4176,9 +4198,9 @@ dependencies = [ [[package]] name = "topcoat-font" -version = "0.6.2" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7b8308aff65f46bbe2f58371fc9823db596236bd0ea3c9d87de6534fd977e60" +checksum = "8ccc2da492bfdcf2d23d761b60338eb20ad178fd754ef19570abe6030663137d" dependencies = [ "heck", "inventory", @@ -4193,9 +4215,9 @@ dependencies = [ [[package]] name = "topcoat-font-grammar" -version = "0.6.2" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b7d68e226827fb7531d0dba69cb74fa7b82515f8428fd1a75f556f5a2bf87c1" +checksum = "6125e270bb16bf826a54e4b40b41484682b2b660af4803688887f64a9918745a" dependencies = [ "proc-macro2", "quote", @@ -4206,9 +4228,9 @@ dependencies = [ [[package]] name = "topcoat-font-macro" -version = "0.6.2" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e655c430bcb380f879603ea750c6222ade2ff3ade33869d9eaa32e3fc49f5469" +checksum = "5f46d0a9c08e7bf774683c05add490824af80a844f410e6ffc9fdaf00c88d7be" dependencies = [ "quote", "syn 2.0.119", @@ -4217,9 +4239,9 @@ dependencies = [ [[package]] name = "topcoat-mail" -version = "0.6.2" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "959c9c32172ad3840f94c589a29bd143c072661c9abf2215a68fd76440ed2300" +checksum = "1b8fa0e1ad5a4f4419c50b783ac565426df5c30dfa3dc9ca9602c8cd1c3535a3" dependencies = [ "lettre", "thiserror", @@ -4231,9 +4253,9 @@ dependencies = [ [[package]] name = "topcoat-router" -version = "0.6.2" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e062bd348df5647f6904f4f4045b3c92c08c4a8826196e8e91a51aade00b5764" +checksum = "9f452945373fac2b61a4050639681829e99afeea872faebc93ef0b03c4211335" dependencies = [ "bytes", "form_urlencoded", @@ -4249,6 +4271,7 @@ dependencies = [ "matchit", "multer", "percent-encoding", + "pin-project-lite", "ref-cast", "serde", "serde_json", @@ -4263,9 +4286,9 @@ dependencies = [ [[package]] name = "topcoat-router-grammar" -version = "0.6.2" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c052423d2aa4039036f1ac5567d1e2dac48897602d34561b3024a87830e5bdce" +checksum = "188df45ec401d790e3dd84564580c5c436a456331a187bdbfb7441f8e48fa1ca" dependencies = [ "heck", "proc-macro2", @@ -4276,9 +4299,9 @@ dependencies = [ [[package]] name = "topcoat-router-macro" -version = "0.6.2" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cea98692b786bab3adda35a60d71981f60b2a98c6e7105ac92e582b7c9ce9cab" +checksum = "ac6f9a61d3ecfe1252b861795070c4317aca6b816382919d9c941eccad2fe42d" dependencies = [ "quote", "syn 2.0.119", @@ -4287,9 +4310,9 @@ dependencies = [ [[package]] name = "topcoat-runtime" -version = "0.6.2" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5dea200c86ca554bab7410f09cae8790a8adcbfd8f306eb78db7092ca71f8aae" +checksum = "b75367a6fb32878f28bb1e42fe97385c9b14f1d3455b0bb69afb399260a8995a" dependencies = [ "inventory", "ref-cast", @@ -4299,14 +4322,13 @@ dependencies = [ "topcoat-core", "topcoat-router", "topcoat-view", - "uuid", ] [[package]] name = "topcoat-runtime-grammar" -version = "0.6.2" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87b73f7e4e10f49e006a71dd43e8ee629c76c08451acbc51faa7ec5b6952c53c" +checksum = "c19d5cf0ad59525a9fdd0a6ada36448833b39b85602736df16d32712f6c3a3c8" dependencies = [ "proc-macro2", "quote", @@ -4320,9 +4342,9 @@ dependencies = [ [[package]] name = "topcoat-runtime-macro" -version = "0.6.2" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5dc3e4e245abcaea6af780437cae072e8f2157c9852ec5b3058a658c61b9e0bf" +checksum = "3504cd2966788c4cb6f417a9f73faf3ae2631c5aa415bc0d37d142ba597d5c42" dependencies = [ "quote", "syn 2.0.119", @@ -4331,9 +4353,9 @@ dependencies = [ [[package]] name = "topcoat-session" -version = "0.6.2" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e079e8c5a63987d7f929ab05a75922feab1fe390a9cfa2c101eb35829e67eac2" +checksum = "d432a276f3d7e4e0af0f9789ee0c919fbfbf8d2025d0dac7f8072a918521cf6d" dependencies = [ "base64 0.22.1", "getrandom 0.4.3", @@ -4348,25 +4370,26 @@ dependencies = [ [[package]] name = "topcoat-view" -version = "0.6.2" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5904449bd6f633759d187fa621ded68178b551428c297959fd53d8fb91f3e6f6" +checksum = "4acc959c83729cb4b967c2e7de8ee78a2fc3216cceb1be650ee9524fabd26baa" dependencies = [ + "base64 0.22.1", "futures-core", "futures-util", "http", - "itoa", "memchr", "pin-project-lite", + "siphasher", "smallvec", "topcoat-core", ] [[package]] name = "topcoat-view-grammar" -version = "0.6.2" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bf4293156d7c5fa7960edc573b686eb27426dcd888bfbe9e532304178cdda24" +checksum = "fa71393a00dba3ce203d3236e24311851134721f5bfae6a17bfacd709a983660" dependencies = [ "heck", "proc-macro2", @@ -4378,9 +4401,9 @@ dependencies = [ [[package]] name = "topcoat-view-macro" -version = "0.6.2" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58ab2b200eda4516abdb543f307006d83fedd3681b871d2042c17106c688f716" +checksum = "2a625be243364f6674204ba412700d9eed2a1c9168f7add3b1020be4825f0e49" dependencies = [ "quote", "syn 2.0.119", @@ -4792,11 +4815,11 @@ dependencies = [ [[package]] name = "ulid" -version = "1.2.1" +version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "470dbf6591da1b39d43c14523b2b469c86879a53e8b758c8e090a470fe7b1fbe" +checksum = "947dde63b6d514cc5e044edad4e0ca7261afd1099d16c83d942cb2b2f348689c" dependencies = [ - "rand 0.9.5", + "rand 0.10.2", "web-time", ] @@ -4831,6 +4854,16 @@ dependencies = [ "subtle", ] +[[package]] +name = "universal-hash" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4987bdc12753382e0bec4a65c50738ffaabc998b9cdd1f952fb5f39b0048a96" +dependencies = [ + "crypto-common 0.2.2", + "ctutils", +] + [[package]] name = "untrusted" version = "0.9.0" diff --git a/Cargo.toml b/Cargo.toml index 8930e87..d3dde4b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,7 @@ im-core = { path = "crates/im-core", default-features = false } serde = { version = "1.0.229", features = ["derive"] } serde_json = "1.0.151" thiserror = "2.0.20" -ulid = "1" +ulid = "3" time = { version = "0.3.55", features = ["serde", "formatting", "parsing", "macros"] } tokio = { version = "1.53.1", features = ["full"] } turso = "=0.8.0-pre.10" @@ -26,8 +26,8 @@ argon2 = "0.6.0" rand = "0.10.2" sha2 = "0.11.0" subtle = "2.6.1" -chacha20poly1305 = "0.10.1" -base64 = "0.22.1" +chacha20poly1305 = "0.11.0" +base64 = "0.23.1" toml = "1" async-trait = "0.1.92" diff --git a/crates/im-client/Cargo.toml b/crates/im-client/Cargo.toml index 391d987..886be3c 100644 --- a/crates/im-client/Cargo.toml +++ b/crates/im-client/Cargo.toml @@ -15,7 +15,7 @@ default = ["oidc"] oidc = [] [dependencies] -topcoat = { version = "0.6.2", default-features = false, features = [ +topcoat = { version = "0.8.0", default-features = false, features = [ "router", "cookie", ] } @@ -29,10 +29,9 @@ rand.workspace = true sha2.workspace = true subtle.workspace = true chacha20poly1305.workspace = true -# rsa 0.9 verifies through the digest 0.10 traits, so its hasher comes from -# the sha2 0.10 line; the workspace sha2 0.11 stays for PKCE. -sha2-for-rsa = { package = "sha2", version = "0.10", features = ["oid"] } -rsa = "0.9.10" +# rsa 0.10 verifies through the digest 0.11 traits, so its hasher is the +# workspace sha2 0.11 that PKCE already uses. +rsa = "0.10.0-rc.18" reqwest = { version = "0.13.5", default-features = false, features = [ "rustls", "json", @@ -46,7 +45,7 @@ name = "demo" required-features = ["oidc"] [dev-dependencies] -topcoat = { version = "0.6.2", default-features = false, features = [ +topcoat = { version = "0.8.0", default-features = false, features = [ "router", "cookie", "view", @@ -54,6 +53,6 @@ topcoat = { version = "0.6.2", default-features = false, features = [ "discover", ] } http = "1.5" -# Tests generate their own RSA keys, and rsa 0.9's RNG is the rand_core 0.6 -# line. -rand_core06 = { package = "rand_core", version = "0.6.4", features = ["getrandom"] } +# Tests generate their own RSA keys, and rsa 0.10's RNG is the rand_core 0.10 +# line that the workspace rand 0.10 provides. +rand_core010 = { package = "rand_core", version = "0.10.1" } diff --git a/crates/im-client/src/directory.rs b/crates/im-client/src/directory.rs index 03c257a..085c195 100644 --- a/crates/im-client/src/directory.rs +++ b/crates/im-client/src/directory.rs @@ -257,10 +257,10 @@ impl SseParser { fn take_event(&mut self) -> Option { let data = std::mem::take(&mut self.data); let event = self.event.take(); - if let Some(kind) = event { - if kind != "profile" { - return None; - } + if let Some(kind) = event + && kind != "profile" + { + return None; } serde_json::from_str::(&data) .ok() diff --git a/crates/im-client/src/oidc.rs b/crates/im-client/src/oidc.rs index 60aee5b..4606eaa 100644 --- a/crates/im-client/src/oidc.rs +++ b/crates/im-client/src/oidc.rs @@ -178,8 +178,9 @@ fn seal(key: &[u8; 32], plaintext: &[u8]) -> String { let cipher = XChaCha20Poly1305::new(key.into()); let mut nonce_bytes = [0u8; 24]; rand::rng().fill_bytes(&mut nonce_bytes); + let nonce = XNonce::from(nonce_bytes); let ciphertext = cipher - .encrypt(XNonce::from_slice(&nonce_bytes), plaintext) + .encrypt(&nonce, plaintext) .expect("XChaCha20-Poly1305 cannot fail on a payload this small"); let mut payload = nonce_bytes.to_vec(); payload.extend_from_slice(&ciphertext); @@ -193,9 +194,8 @@ fn open(key: &[u8; 32], sealed: &str) -> Option> { } let (nonce_bytes, ciphertext) = payload.split_at(24); let cipher = XChaCha20Poly1305::new(key.into()); - cipher - .decrypt(XNonce::from_slice(nonce_bytes), ciphertext) - .ok() + let nonce: &XNonce = nonce_bytes.try_into().ok()?; + cipher.decrypt(nonce, ciphertext).ok() } fn seal_json(key: &[u8; 32], value: &T) -> String { @@ -514,7 +514,7 @@ fn verify_claims( .map_err(|e| Error::Token(e.to_string()))?; let signature = rsa::pkcs1v15::Signature::try_from(signature_bytes.as_slice()) .map_err(|e| Error::Token(e.to_string()))?; - let verifying = rsa::pkcs1v15::VerifyingKey::::new(key.clone()); + let verifying = rsa::pkcs1v15::VerifyingKey::::new(key.clone()); verifying .verify(format!("{}.{}", parts[0], parts[1]).as_bytes(), &signature) .map_err(|_| Error::Token("bad signature".into()))?; @@ -575,8 +575,8 @@ async fn refetch_jwks(state: &ImClient) -> Result<()> { continue; }; let key = rsa::RsaPublicKey::new( - rsa::BigUint::from_bytes_be(&n), - rsa::BigUint::from_bytes_be(&e), + rsa::BoxedUint::from_be_slice_vartime(&n), + rsa::BoxedUint::from_be_slice_vartime(&e), ) .map_err(|err| Error::Token(format!("bad jwk {kid}: {err}")))?; keys.push((kid.to_string(), key)); @@ -595,8 +595,8 @@ mod tests { fn keypair() -> (rsa::RsaPrivateKey, rsa::RsaPublicKey) { // 2048-bit generation is slow for a unit test; 1024 is the smallest - // rsa 0.9 accepts and the signature math under test is identical. - let private = rsa::RsaPrivateKey::new(&mut rand_core06::OsRng, 1024).unwrap(); + // rsa accepts and the signature math under test is identical. + let private = rsa::RsaPrivateKey::new(&mut rand::rng(), 1024).unwrap(); let public = private.to_public_key(); (private, public) } @@ -606,7 +606,7 @@ mod tests { let mut out = b64url.encode(header.to_string()); out.push('.'); out.push_str(&b64url.encode(claims.to_string())); - let signing = rsa::pkcs1v15::SigningKey::::new(key.clone()); + let signing = rsa::pkcs1v15::SigningKey::::new(key.clone()); let signature = signing.sign(out.as_bytes()); format!("{}.{}", out, b64url.encode(signature.to_bytes())) } diff --git a/crates/im-core/Cargo.toml b/crates/im-core/Cargo.toml index 9e001a8..e358a89 100644 --- a/crates/im-core/Cargo.toml +++ b/crates/im-core/Cargo.toml @@ -22,7 +22,6 @@ server = [ "dep:rsa", "dep:sha1", "dep:sha2", - "dep:sha2-for-rsa", "dep:subtle", "dep:tokio", "dep:turso", @@ -36,14 +35,12 @@ chacha20poly1305 = { workspace = true, optional = true } data-encoding = { version = "2.11.1", optional = true } hmac = { version = "0.13.0", optional = true } rand = { workspace = true, optional = true } -# rsa 0.9 sits on the rand_core 0.6 / digest 0.10 trait lines, so its RNG -# and its hasher come from those lines, not the workspace's rand 0.10 / -# sha2 0.11. sha2 0.11 stays for token digests. -rand_core = { version = "0.6.4", features = ["getrandom"], optional = true } -rsa = { version = "0.9.10", optional = true } +# rsa 0.10 sits on the rand_core 0.10 / digest 0.11 trait lines, so its RNG +# and its hasher come from those lines: the workspace rand 0.10 / sha2 0.11. +rand_core = { version = "0.10.1", optional = true } +rsa = { version = "0.10.0-rc.18", optional = true } sha1 = { version = "0.11.0", optional = true } sha2 = { workspace = true, optional = true } -sha2-for-rsa = { package = "sha2", version = "0.10", features = ["oid"], optional = true } subtle = { workspace = true, optional = true } serde.workspace = true serde_json.workspace = true diff --git a/crates/im-core/src/accounts.rs b/crates/im-core/src/accounts.rs index e3d03a1..04e7aab 100644 --- a/crates/im-core/src/accounts.rs +++ b/crates/im-core/src/accounts.rs @@ -909,10 +909,10 @@ fn normalize_email(email: &str) -> std::result::Result { /// address the account already carries quietly succeeds. pub async fn set_email(store: &Store, user: &UserId, email: &str) -> std::result::Result<(), AccountError> { let email = normalize_email(email)?; - if let Some(other) = user_by_email(store, &email).await? { - if other.id != *user { - return Err(AccountError::EmailTaken); - } + if let Some(other) = user_by_email(store, &email).await? + && other.id != *user + { + return Err(AccountError::EmailTaken); } let conn = store.conn.lock().await; conn.execute( @@ -953,10 +953,10 @@ pub async fn request_email_change( if new_email == old_email { return Err(AccountError::SameEmail); } - if let Some(other) = user_by_email(store, &new_email).await? { - if other.id != *user { - return Err(AccountError::EmailTaken); - } + if let Some(other) = user_by_email(store, &new_email).await? + && other.id != *user + { + return Err(AccountError::EmailTaken); } let old_token = Token::mint(); let new_token = Token::mint(); @@ -1040,17 +1040,17 @@ pub async fn confirm_email_change( } let completes = (clicked_old && new_done) || (!clicked_old && old_done); if completes { - if let Some(other) = user_by_email(store, &new_email).await? { - if other.id != user_id { - let conn = store.conn.lock().await; - conn.execute( - "DELETE FROM email_changes WHERE old_token_hash = ?1 OR new_token_hash = ?1", - turso::params![hash], - ) - .await - .map_err(backend)?; - return Err(AccountError::EmailTaken); - } + if let Some(other) = user_by_email(store, &new_email).await? + && other.id != user_id + { + let conn = store.conn.lock().await; + conn.execute( + "DELETE FROM email_changes WHERE old_token_hash = ?1 OR new_token_hash = ?1", + turso::params![hash], + ) + .await + .map_err(backend)?; + return Err(AccountError::EmailTaken); } set_email(store, &user_id, &new_email).await?; let stamp = store::stamp(store::now())?; diff --git a/crates/im-core/src/events.rs b/crates/im-core/src/events.rs index 30b432d..5c9539b 100644 --- a/crates/im-core/src/events.rs +++ b/crates/im-core/src/events.rs @@ -22,7 +22,7 @@ pub async fn log(store: &Store, kind: &str, actor: Option<&str>, detail: Option< .execute( "INSERT INTO events (id, at, kind, actor, detail) VALUES (?1, ?2, ?3, ?4, ?5)", turso::params![ - ulid::Ulid::new().to_string(), + ulid::Ulid::generate().to_string(), store::stamp(store::now()).expect("rfc3339 of now"), kind, actor, diff --git a/crates/im-core/src/keys.rs b/crates/im-core/src/keys.rs index 12858b2..d10bb99 100644 --- a/crates/im-core/src/keys.rs +++ b/crates/im-core/src/keys.rs @@ -5,6 +5,7 @@ //! XChaCha20-Poly1305 envelope of its PKCS#8 DER under `im.key`, and only //! `active_signing_key` (signing) and `jwks` (the public half) cross the //! boundary. +use rand::SeedableRng as _; use rsa::pkcs8::{DecodePrivateKey, DecodePublicKey, EncodePrivateKey, EncodePublicKey}; use rsa::traits::PublicKeyParts; use rsa::{RsaPrivateKey, RsaPublicKey}; @@ -38,7 +39,7 @@ pub async fn active_signing_key(store: &Store) -> Result<(String, RsaPrivateKey) return Ok((kid, key)); } - let mut rng = rand_core::OsRng; + let mut rng = rand::rngs::StdRng::from_rng(&mut rand::rng()); let key = RsaPrivateKey::new(&mut rng, 2048) .map_err(|e| StoreError::Backend(format!("key generation: {e}")))?; let public_der = key @@ -96,8 +97,8 @@ pub async fn jwks(store: &Store) -> Result { "use": "sig", "alg": "RS256", "kid": kid, - "n": b64.encode(public.n().to_bytes_be()), - "e": b64.encode(public.e().to_bytes_be()), + "n": b64.encode(public.n().to_be_bytes_trimmed_vartime()), + "e": b64.encode(public.e().to_be_bytes_trimmed_vartime()), })); } Ok(serde_json::json!({ "keys": keys })) diff --git a/crates/im-core/src/model.rs b/crates/im-core/src/model.rs index dc2d581..4f7bdf6 100644 --- a/crates/im-core/src/model.rs +++ b/crates/im-core/src/model.rs @@ -23,7 +23,7 @@ macro_rules! id_wrapper { /// A fresh ULID — sortable, URL-safe, unguessable enough for an id. #[cfg(feature = "server")] pub fn mint() -> Self { - Self(ulid::Ulid::new().to_string()) + Self(ulid::Ulid::generate().to_string()) } pub fn as_str(&self) -> &str { diff --git a/crates/im-core/src/oidc.rs b/crates/im-core/src/oidc.rs index 1051ac3..5d52111 100644 --- a/crates/im-core/src/oidc.rs +++ b/crates/im-core/src/oidc.rs @@ -43,7 +43,7 @@ pub fn sign_jwt(claims: &serde_json::Value, kid: &str, key: &RsaPrivateKey) -> S let mut out = b64url.encode(header.to_string()); out.push('.'); out.push_str(&b64url.encode(claims.to_string())); - let signing = rsa::pkcs1v15::SigningKey::::new(key.clone()); + let signing = rsa::pkcs1v15::SigningKey::::new(key.clone()); let signature = signing.sign(out.as_bytes()); out.push('.'); out.push_str(&b64url.encode(signature.to_bytes())); @@ -474,7 +474,7 @@ pub async fn verify_jwt( let Ok(signature) = rsa::pkcs1v15::Signature::try_from(signature_bytes.as_slice()) else { return Ok(None); }; - let verifying = rsa::pkcs1v15::VerifyingKey::::new(public); + let verifying = rsa::pkcs1v15::VerifyingKey::::new(public); if verifying .verify(format!("{}.{}", parts[0], parts[1]).as_bytes(), &signature) .is_err() @@ -487,10 +487,8 @@ pub async fn verify_jwt( let Ok(claims) = serde_json::from_slice::(&claims_bytes) else { return Ok(None); }; - if let Some(audience) = audience { - if claims["aud"].as_str() != Some(audience) { - return Ok(None); - } + if let Some(audience) = audience && claims["aud"].as_str() != Some(audience) { + return Ok(None); } let Some(exp) = claims["exp"].as_i64() else { return Ok(None); @@ -771,7 +769,7 @@ mod tests { assert_eq!(claims["sub"], "u1"); let verifying = - rsa::pkcs1v15::VerifyingKey::::new(key.to_public_key()); + rsa::pkcs1v15::VerifyingKey::::new(key.to_public_key()); let signature = rsa::pkcs1v15::Signature::try_from(b64url.decode(parts[2]).unwrap().as_slice()) .unwrap(); diff --git a/crates/im-core/src/photos.rs b/crates/im-core/src/photos.rs index ffa559d..6a043ca 100644 --- a/crates/im-core/src/photos.rs +++ b/crates/im-core/src/photos.rs @@ -26,7 +26,7 @@ fn photo_file(store: &Store, user_id: &str) -> std::path::PathBuf { /// there before intact, never a truncated one under the real name. fn write_file_atomic(path: &std::path::Path, bytes: &[u8]) -> std::io::Result<()> { use std::io::Write as _; - let tmp = path.with_extension(format!("{}.tmp", ulid::Ulid::new())); + let tmp = path.with_extension(format!("{}.tmp", ulid::Ulid::generate())); let mut file = std::fs::File::create(&tmp)?; file.write_all(bytes)?; file.sync_all()?; @@ -42,7 +42,7 @@ pub async fn set_photo(store: &Store, user: &UserId, bytes: &[u8], mime: &str) - // leaves the committed photo exactly as it was, and a crash between // commit and rename serves the old bytes next to a staged file the boot // sweep collects — stale, never destroyed. - let staged = path.with_extension(format!("incoming-{}", ulid::Ulid::new())); + let staged = path.with_extension(format!("incoming-{}", ulid::Ulid::generate())); write_file_atomic(&staged, bytes).map_err(|e| StoreError::Backend(e.to_string()))?; let written = { let conn = store.conn.lock().await; diff --git a/crates/im-core/src/secret.rs b/crates/im-core/src/secret.rs index a858672..e434d20 100644 --- a/crates/im-core/src/secret.rs +++ b/crates/im-core/src/secret.rs @@ -42,9 +42,9 @@ pub fn seal(key: &Key, plaintext: &[u8]) -> String { let cipher = XChaCha20Poly1305::new(key.into()); let mut nonce_bytes = [0u8; NONCE_BYTES]; rand::rng().fill_bytes(&mut nonce_bytes); - let nonce = XNonce::from_slice(&nonce_bytes); + let nonce = XNonce::from(nonce_bytes); let ciphertext = cipher - .encrypt(nonce, plaintext) + .encrypt(&nonce, plaintext) .expect("XChaCha20-Poly1305 cannot fail to encrypt a plaintext this small"); let mut payload = Vec::with_capacity(NONCE_BYTES + ciphertext.len()); payload.extend_from_slice(&nonce_bytes); @@ -63,7 +63,7 @@ pub fn open(key: &Key, sealed: &str) -> Option> { } let (nonce_bytes, ciphertext) = payload.split_at(NONCE_BYTES); let cipher = XChaCha20Poly1305::new(key.into()); - let nonce = XNonce::from_slice(nonce_bytes); + let nonce: &XNonce = nonce_bytes.try_into().ok()?; cipher.decrypt(nonce, ciphertext).ok() } diff --git a/crates/im-core/src/settings.rs b/crates/im-core/src/settings.rs index 5198970..8a06114 100644 --- a/crates/im-core/src/settings.rs +++ b/crates/im-core/src/settings.rs @@ -218,15 +218,15 @@ pub async fn set_smtp(store: &Store, smtp: &Smtp, password: Option<&str>) -> Res set(store, "smtp_username", &smtp.username).await?; set(store, "smtp_from", &smtp.from).await?; set(store, "smtp_from_name", &smtp.from_name).await?; - if let Some(password) = password { - if !password.is_empty() { - set( - store, - "smtp_password", - &secret::seal(store.key(), password.as_bytes()), - ) - .await?; - } + if let Some(password) = password + && !password.is_empty() + { + set( + store, + "smtp_password", + &secret::seal(store.key(), password.as_bytes()), + ) + .await?; } Ok(()) } @@ -480,17 +480,16 @@ mod tests { assert_eq!(policy(&store).await.unwrap().max_sessions, 5); // A written value comes back... - let mut value = Policy::default(); - value.max_sessions = 2; + let value = Policy { max_sessions: 2, ..Policy::default() }; set_policy(&store, &value).await.unwrap(); assert_eq!(policy(&store).await.unwrap().max_sessions, 2); // ...and zero or negative — a cap that would lock every user out // of their own account — clamps back to the default, unstored. - value.max_sessions = 0; + let value = Policy { max_sessions: 0, ..Policy::default() }; set_policy(&store, &value).await.unwrap(); assert_eq!(policy(&store).await.unwrap().max_sessions, 5); - value.max_sessions = -3; + let value = Policy { max_sessions: -3, ..Policy::default() }; set_policy(&store, &value).await.unwrap(); assert_eq!(policy(&store).await.unwrap().max_sessions, 5); } diff --git a/crates/im-core/src/store.rs b/crates/im-core/src/store.rs index 4210727..8c75905 100644 --- a/crates/im-core/src/store.rs +++ b/crates/im-core/src/store.rs @@ -351,7 +351,7 @@ impl Store { /// is a fresh tempdir, as throwaway as the database itself. fn photos_dir(path: &Path) -> std::path::PathBuf { if path.as_os_str() == ":memory:" { - return std::env::temp_dir().join(format!("im-storage-{}", ulid::Ulid::new())); + return std::env::temp_dir().join(format!("im-storage-{}", ulid::Ulid::generate())); } path.parent() .filter(|d| !d.as_os_str().is_empty()) diff --git a/crates/im-migrate/src/main.rs b/crates/im-migrate/src/main.rs index 97e62f7..0eb5907 100644 --- a/crates/im-migrate/src/main.rs +++ b/crates/im-migrate/src/main.rs @@ -269,7 +269,7 @@ async fn run(args: &Args) -> Result { mapping.push_str(&format!("{},{sub}\n", user.id)); continue; } - let sub = ulid::Ulid::new().to_string(); + let sub = ulid::Ulid::generate().to_string(); conn.execute( "INSERT INTO users (id, email, name, password_hash, created_at) \ VALUES (?1, ?2, ?3, ?4, ?5)", diff --git a/crates/im-web/Cargo.toml b/crates/im-web/Cargo.toml index 2b3b14a..1f713b1 100644 --- a/crates/im-web/Cargo.toml +++ b/crates/im-web/Cargo.toml @@ -8,7 +8,7 @@ description = "im web app: topcoat UI, OIDC endpoints and the server" build = "build.rs" [dependencies] -topcoat = { version = "0.6.2", default-features = false, features = [ +topcoat = { version = "0.8.0", default-features = false, features = [ "router", "view", "runtime", diff --git a/crates/im-web/src/admin.rs b/crates/im-web/src/admin.rs index 6eb0acf..b64d0ff 100644 --- a/crates/im-web/src/admin.rs +++ b/crates/im-web/src/admin.rs @@ -13,7 +13,7 @@ use topcoat::cookie::Cookies; use topcoat::router::content::Form; use topcoat::router::response::{IntoResponse, Response}; use topcoat::router::{HeaderValue, StatusCode, header, route}; -use topcoat::view::view; +use topcoat::view::{Child, ViewExt, view}; use crate::i18n::{self, Key, lang_of, t}; use crate::layout::shell; @@ -26,15 +26,17 @@ fn app(cx: &Cx) -> &App { } /// The admin behind this request, or the redirect the request gets instead. -async fn require_admin(cx: &Cx) -> std::result::Result { +async fn require_admin(cx: &Cx) -> std::result::Result> { match server::current_user(cx).await { Some(user) if user.admin => Ok(user), - _ => Err(( - StatusCode::SEE_OTHER, - [(header::LOCATION, HeaderValue::from_static("/"))], - ) - .into_response(cx) - .expect("a redirect can always be built")), + _ => Err(Box::new( + ( + StatusCode::SEE_OTHER, + [(header::LOCATION, HeaderValue::from_static("/"))], + ) + .into_response(cx) + .expect("a redirect can always be built"), + )), } } @@ -49,18 +51,30 @@ fn escape(raw: &str) -> String { /// One row action as a two-step disclosure — iz's `confirm-details` idiom: /// the summary is the word ("Delete"), the opened panel says what it costs -/// and holds the button that actually does it. Works with no script at all; -/// the live script adds outside-click closing. -fn confirm_action( - field: &str, - id: &str, - action: &str, - word: &str, - extra_class: &str, - title: &str, - cost: &str, - confirm: &str, -) -> String { +/// and holds the button that actually does it. The eight `&str`s travel as +/// named fields: eight positional parameters tripped the too-many-arguments +/// lint, and the names read better at the call sites anyway. +struct ConfirmAction<'a> { + field: &'a str, + id: &'a str, + action: &'a str, + word: &'a str, + extra_class: &'a str, + title: &'a str, + cost: &'a str, + confirm: &'a str, +} +fn confirm_action(ask: ConfirmAction<'_>) -> String { + let ConfirmAction { + field, + id, + action, + word, + extra_class, + title, + cost, + confirm, + } = ask; format!( r#"
{word}
{title}
{cost}
"# ) @@ -110,7 +124,7 @@ fn back(cx: &Cx, section: &str, extra: &str) -> Result { async fn admin_page(cx: &Cx) -> Result { let me = match require_admin(cx).await { Ok(me) => me, - Err(redirect) => return Ok(redirect), + Err(redirect) => return Ok(*redirect), }; let lang = lang_of(Some(&me)); let query = topcoat::router::request::uri(cx) @@ -188,6 +202,7 @@ async fn admin_page(cx: &Cx) -> Result { _ => None, }; + let my_email = escape(&me.email); let stage = view! { cx =>
@@ -197,7 +212,7 @@ async fn admin_page(cx: &Cx) -> Result { // topbar; the address stays a link too. "im" - (escape(&me.email)) + (my_email) if let Some(banner) = banner { (topcoat::view::Unescaped::new_unchecked(banner)) @@ -207,7 +222,9 @@ async fn admin_page(cx: &Cx) -> Result {
}; - shell(cx, t(lang, Key::TitleAdmin), Some(&me), stage) + shell(cx, t(lang, Key::TitleAdmin), Some(me), Child::new(stage)) + .await? + .first() .await? .into_response(cx) } @@ -330,38 +347,38 @@ async fn users_section( // the button that actually does it. No script required; the live // script adds outside-click closing on top. let toggle = if user.disabled { - confirm_action( - "user", - &id, - "/admin/enable", - t(lang, Key::EnableWord), - "", - &i18n::enable_title(lang, &email), - t(lang, Key::EnableCost), - t(lang, Key::ConfirmEnable), - ) + confirm_action(ConfirmAction { + field: "user", + id: &id, + action: "/admin/enable", + word: t(lang, Key::EnableWord), + extra_class: "", + title: &i18n::enable_title(lang, &email), + cost: t(lang, Key::EnableCost), + confirm: t(lang, Key::ConfirmEnable), + }) } else { - confirm_action( - "user", - &id, - "/admin/disable", - t(lang, Key::DisableWord), - "", - &i18n::disable_title(lang, &email), - t(lang, Key::DisableCost), - t(lang, Key::ConfirmDisable), - ) + confirm_action(ConfirmAction { + field: "user", + id: &id, + action: "/admin/disable", + word: t(lang, Key::DisableWord), + extra_class: "", + title: &i18n::disable_title(lang, &email), + cost: t(lang, Key::DisableCost), + confirm: t(lang, Key::ConfirmDisable), + }) }; - let remove = confirm_action( - "user", - &id, - "/admin/delete", - t(lang, Key::DeleteWord), - " admin-danger", - &i18n::delete_title(lang, &email), - t(lang, Key::DeleteCost), - t(lang, Key::ConfirmDelete), - ); + let remove = confirm_action(ConfirmAction { + field: "user", + id: &id, + action: "/admin/delete", + word: t(lang, Key::DeleteWord), + extra_class: " admin-danger", + title: &i18n::delete_title(lang, &email), + cost: t(lang, Key::DeleteCost), + confirm: t(lang, Key::ConfirmDelete), + }); format!( r#"{toggle}
{remove}"#, sign_out = t(lang, Key::SignOutEverywhere), @@ -524,16 +541,16 @@ async fn services_section( kept_word = t(lang, Key::ServiceKept), ) } else { - confirm_action( - "key", - &key, - "/admin/services_remove", - t(lang, Key::Remove), - " admin-danger", - &i18n::remove_service_title(lang, &name), - t(lang, Key::RemoveCost), - t(lang, Key::ConfirmRemove), - ) + confirm_action(ConfirmAction { + field: "key", + id: &key, + action: "/admin/services_remove", + word: t(lang, Key::Remove), + extra_class: " admin-danger", + title: &i18n::remove_service_title(lang, &name), + cost: t(lang, Key::RemoveCost), + confirm: t(lang, Key::ConfirmRemove), + }) }; let (client_cell, uris_cell, registered_cell, client_actions) = match linked(service.client_id.as_ref()) { @@ -647,26 +664,26 @@ async fn services_section( /// A client's Rotate/Revoke pair, as the two-step disclosures — the same /// controls on a linked service row and on a credential-only row. fn client_controls(client_id: &str, name_html: &str, lang: i18n::Lang) -> String { - let rotate = confirm_action( - "client", - client_id, - "/admin/clients_rotate", - t(lang, Key::RotateWord), - "", - &i18n::rotate_client_title(lang, name_html), - t(lang, Key::RotateCost), - t(lang, Key::ConfirmRotate), - ); - let revoke_action = confirm_action( - "client", - client_id, - "/admin/clients_revoke", - t(lang, Key::RevokeWord), - " admin-danger", - &i18n::revoke_client_title(lang, name_html), - t(lang, Key::RevokeCost), - t(lang, Key::ConfirmRevoke), - ); + let rotate = confirm_action(ConfirmAction { + field: "client", + id: client_id, + action: "/admin/clients_rotate", + word: t(lang, Key::RotateWord), + extra_class: "", + title: &i18n::rotate_client_title(lang, name_html), + cost: t(lang, Key::RotateCost), + confirm: t(lang, Key::ConfirmRotate), + }); + let revoke_action = confirm_action(ConfirmAction { + field: "client", + id: client_id, + action: "/admin/clients_revoke", + word: t(lang, Key::RevokeWord), + extra_class: " admin-danger", + title: &i18n::revoke_client_title(lang, name_html), + cost: t(lang, Key::RevokeCost), + confirm: t(lang, Key::ConfirmRevoke), + }); format!("{rotate}{revoke_action}") } @@ -749,7 +766,7 @@ struct ServiceForm { async fn services_add(cx: &Cx, Form(input): Form) -> Result { let me = match require_admin(cx).await { Ok(me) => me, - Err(redirect) => return Ok(redirect), + Err(redirect) => return Ok(*redirect), }; let limit = match posted_limit(&input.limit_amount, &input.limit_unit) { Ok(limit) => limit, @@ -774,7 +791,7 @@ async fn services_add(cx: &Cx, Form(input): Form) -> Result) -> Result { let me = match require_admin(cx).await { Ok(me) => me, - Err(redirect) => return Ok(redirect), + Err(redirect) => return Ok(*redirect), }; let limit = match posted_limit(&input.limit_amount, &input.limit_unit) { Ok(limit) => limit, @@ -800,7 +817,7 @@ struct ServiceKeyForm { async fn services_remove(cx: &Cx, Form(input): Form) -> Result { let me = match require_admin(cx).await { Ok(me) => me, - Err(redirect) => return Ok(redirect), + Err(redirect) => return Ok(*redirect), }; let outcome = im_core::services::remove(&app(cx).store, &input.key).await; service_outcome(cx, &me, outcome).await @@ -817,7 +834,7 @@ struct ServiceMoveForm { async fn services_move(cx: &Cx, Form(input): Form) -> Result { let me = match require_admin(cx).await { Ok(me) => me, - Err(redirect) => return Ok(redirect), + Err(redirect) => return Ok(*redirect), }; let up = match input.dir.as_str() { "up" => true, @@ -862,7 +879,7 @@ struct ClientForm { async fn clients_add(cx: &Cx, Form(input): Form) -> Result { let me = match require_admin(cx).await { Ok(me) => me, - Err(redirect) => return Ok(redirect), + Err(redirect) => return Ok(*redirect), }; let name = input.name.trim().to_string(); let uris: Vec = input @@ -890,7 +907,7 @@ struct ClientAction { async fn clients_rotate(cx: &Cx, Form(input): Form) -> Result { let me = match require_admin(cx).await { Ok(me) => me, - Err(redirect) => return Ok(redirect), + Err(redirect) => return Ok(*redirect), }; // The log line names the client like a person, so the name comes off // the row before the secret under it moves. @@ -913,7 +930,7 @@ async fn clients_rotate(cx: &Cx, Form(input): Form) -> Result) -> Result { let me = match require_admin(cx).await { Ok(me) => me, - Err(redirect) => return Ok(redirect), + Err(redirect) => return Ok(*redirect), }; let name = match im_core::oidc::client_by_id(&app(cx).store, &input.client).await? { Some(client) => client.name, @@ -983,7 +1000,7 @@ struct PolicyForm { async fn settings_save(cx: &Cx, Form(input): Form) -> Result { let me = match require_admin(cx).await { Ok(me) => me, - Err(redirect) => return Ok(redirect), + Err(redirect) => return Ok(*redirect), }; let store = &app(cx).store; settings::set_policy( @@ -1361,6 +1378,22 @@ async fn logs_section(cx: &Cx, lang: i18n::Lang) -> Result{}"#, + if dir == events::Dir::Newest { + " selected" + } else { + "" + }, + t(lang, Key::NewestFirst), + if dir == events::Dir::Oldest { + " selected" + } else { + "" + }, + t(lang, Key::OldestFirst), + ); + Ok(format!( r#"
{title}
@@ -1394,21 +1427,7 @@ async fn logs_section(cx: &Cx, lang: i18n::Lang) -> Result{}"#, - if dir == events::Dir::Newest { - " selected" - } else { - "" - }, - t(lang, Key::NewestFirst), - if dir == events::Dir::Oldest { - " selected" - } else { - "" - }, - t(lang, Key::OldestFirst), - ), + dir_options = dir_options, )) .map(|card| card + LOG_FIT_SCRIPT) } @@ -1491,7 +1510,7 @@ struct InviteForm { async fn invite(cx: &Cx, Form(input): Form) -> Result { let me = match require_admin(cx).await { Ok(me) => me, - Err(redirect) => return Ok(redirect), + Err(redirect) => return Ok(*redirect), }; let store = &app(cx).store; let email = input.email.trim().to_string(); @@ -1543,7 +1562,7 @@ struct UserEmailForm { async fn user_email(cx: &Cx, Form(input): Form) -> Result { let me = match require_admin(cx).await { Ok(me) => me, - Err(redirect) => return Ok(redirect), + Err(redirect) => return Ok(*redirect), }; let store = &app(cx).store; let user_id = UserId::from(input.user); @@ -1568,7 +1587,7 @@ struct InviteAction { async fn uninvite(cx: &Cx, Form(input): Form) -> Result { let me = match require_admin(cx).await { Ok(me) => me, - Err(redirect) => return Ok(redirect), + Err(redirect) => return Ok(*redirect), }; let store = &app(cx).store; let email = accounts::revoke_invite(store, &input.invite).await?; @@ -1583,7 +1602,7 @@ async fn uninvite(cx: &Cx, Form(input): Form) -> Result async fn delete(cx: &Cx, Form(input): Form) -> Result { let me = match require_admin(cx).await { Ok(me) => me, - Err(redirect) => return Ok(redirect), + Err(redirect) => return Ok(*redirect), }; let store = &app(cx).store; let user_id = UserId::from(input.user); @@ -1603,7 +1622,7 @@ struct UserAction { async fn revoke(cx: &Cx, Form(input): Form) -> Result { let me = match require_admin(cx).await { Ok(me) => me, - Err(redirect) => return Ok(redirect), + Err(redirect) => return Ok(*redirect), }; let store = &app(cx).store; let user_id = UserId::from(input.user); @@ -1636,7 +1655,7 @@ struct SessionRevokeForm { async fn session_revoke(cx: &Cx, Form(input): Form) -> Result { let me = match require_admin(cx).await { Ok(me) => me, - Err(redirect) => return Ok(redirect), + Err(redirect) => return Ok(*redirect), }; let user_id = UserId::from(input.user.clone()); if !im_core::sessions::revoke_owned_session(&app(cx).store, &user_id, &input.session).await? { @@ -1659,7 +1678,7 @@ async fn enable(cx: &Cx, Form(input): Form) -> Result { async fn set_disabled(cx: &Cx, input: UserAction, disabled: bool) -> Result { let me = match require_admin(cx).await { Ok(me) => me, - Err(redirect) => return Ok(redirect), + Err(redirect) => return Ok(*redirect), }; let store = &app(cx).store; let user_id = UserId::from(input.user); @@ -1710,7 +1729,7 @@ struct SmtpForm { async fn smtp_save(cx: &Cx, Form(input): Form) -> Result { let me = match require_admin(cx).await { Ok(me) => me, - Err(redirect) => return Ok(redirect), + Err(redirect) => return Ok(*redirect), }; let store = &app(cx).store; let value = Smtp { @@ -1733,7 +1752,7 @@ async fn smtp_save(cx: &Cx, Form(input): Form) -> Result { async fn smtp_test(cx: &Cx) -> Result { let me = match require_admin(cx).await { Ok(me) => me, - Err(redirect) => return Ok(redirect), + Err(redirect) => return Ok(*redirect), }; if !settings::smtp(&app(cx).store).await?.configured() { return back(cx, "mail", "&error=sender_unset"); @@ -1778,7 +1797,7 @@ struct MessageForm { async fn message(cx: &Cx, Form(input): Form) -> Result { let me = match require_admin(cx).await { Ok(me) => me, - Err(redirect) => return Ok(redirect), + Err(redirect) => return Ok(*redirect), }; let store = &app(cx).store; if !settings::smtp(store).await?.configured() { @@ -1834,7 +1853,7 @@ async fn message(cx: &Cx, Form(input): Form) -> Result { async fn smtp_check(cx: &Cx) -> Result { let me = match require_admin(cx).await { Ok(me) => me, - Err(redirect) => return Ok(redirect), + Err(redirect) => return Ok(*redirect), }; if !settings::smtp(&app(cx).store).await?.configured() { return back(cx, "mail", "&error=sender_unset"); diff --git a/crates/im-web/src/auth.rs b/crates/im-web/src/auth.rs index c90cdd7..aff4c87 100644 --- a/crates/im-web/src/auth.rs +++ b/crates/im-web/src/auth.rs @@ -55,13 +55,12 @@ fn logout_target(raw: Option<&str>, services: &[im_core::services::Service]) -> if raw.starts_with('/') && !raw.starts_with("//") { return raw.to_string(); } - if let Some(origin) = url_origin(raw) { - if services + if let Some(origin) = url_origin(raw) + && services .iter() .any(|s| url_origin(&s.url).is_some_and(|known| known == origin)) - { - return raw.to_string(); - } + { + return raw.to_string(); } "/".to_string() } @@ -519,12 +518,12 @@ async fn revoke_session(cx: &Cx, Form(input): Form) -> Redire return see("/".to_string()); }; let store = &server::app(cx).store; - if let Some(presented) = server::presented_session(cx) { - if im_core::accounts::hash_token(&presented) == input.session { - im_core::sessions::revoke_session(store, &presented).await?; - server::clear_session_cookie(cx); - return see("/".to_string()); - } + if let Some(presented) = server::presented_session(cx) + && im_core::accounts::hash_token(&presented) == input.session + { + im_core::sessions::revoke_session(store, &presented).await?; + server::clear_session_cookie(cx); + return see("/".to_string()); } // The row's address, when it is still there, is the useful half of the // log line — which of their devices they just killed. diff --git a/crates/im-web/src/dropdown.rs b/crates/im-web/src/dropdown.rs index c26ce10..07c110c 100644 --- a/crates/im-web/src/dropdown.rs +++ b/crates/im-web/src/dropdown.rs @@ -15,9 +15,9 @@ use topcoat::Result; use topcoat::context::Cx; -use topcoat::view::{Unescaped, view}; +use topcoat::view::{Unescaped, View, view}; -pub async fn dropdown_script(cx: &Cx) -> Result { +pub async fn dropdown_script(cx: &Cx) -> Result { const JS: &str = "\ (function () {\ function enhanceAll() { document.querySelectorAll('select.auth-input').forEach(enhance); }\ @@ -242,5 +242,5 @@ pub async fn dropdown_script(cx: &Cx) -> Result { }, true);\ enhanceAll();\ })();"; - view! { cx => } + Ok(view! { cx => }) } diff --git a/crates/im-web/src/layout.rs b/crates/im-web/src/layout.rs index 5261268..0343100 100644 --- a/crates/im-web/src/layout.rs +++ b/crates/im-web/src/layout.rs @@ -5,7 +5,7 @@ use im_core::model::User; use topcoat::Result; use topcoat::asset::{Asset, asset}; use topcoat::context::Cx; -use topcoat::view::view; +use topcoat::view::{BoxView, Child, View, ViewExt, view}; use crate::i18n::{Key, Lang, lang_of, t}; use crate::server; @@ -15,13 +15,13 @@ pub(crate) const STYLE: Asset = asset!("assets/main.css"); /// The mark, in the word as it is in the name: lower case, the Turkish /// tittle. Text-only here — the auth card is the whole chrome. -pub async fn wordmark(cx: &Cx) -> Result { - view! { +pub async fn wordmark(cx: &Cx) -> Result { + Ok(view! { cx => "im" - } + }) } /// The signed-in chrome's wordmark with the family behind it: the `im` @@ -31,7 +31,7 @@ pub async fn wordmark(cx: &Cx) -> Result { /// is CSS on `:hover` / `:focus-within`. A family with no siblings renders /// the bare mark — nothing to reveal. The list is the stored one, the same /// rows `/family` serves, minus im's own row. -pub async fn family_wordmark(cx: &Cx) -> Result { +pub async fn family_wordmark(cx: &Cx) -> Result> { let services = im_core::services::list(&server::app(cx).store).await?; let siblings = services .iter() @@ -43,10 +43,10 @@ pub async fn family_wordmark(cx: &Cx) -> Result { }) .collect::>(); if siblings.is_empty() { - return wordmark(cx).await; + return wordmark(cx).await.map(ViewExt::boxed); } let marks = siblings.join(r#"·"#); - view! { + Ok(view! { cx =>
@@ -55,19 +55,21 @@ pub async fn family_wordmark(cx: &Cx) -> Result {
} + .boxed()) } /// The profile card's face: the photo when the account has one, the name's /// first letter on a quiet tile when it does not. The URL's `?v=` is the /// row's `photo_version` — the same number `/directory` answers with — so /// a changed photo is a changed URL, in this process and in every sibling. -pub async fn avatar(cx: &Cx, user: &im_core::model::User) -> Result { +pub async fn avatar<'a>(cx: &'a Cx, user: &'a im_core::model::User) -> Result> { if user.has_photo { let src = format!("/photo/{}?v={}", user.id, user.photo_version); - view! { + Ok(view! { cx => (user.name.clone()) } + .boxed()) } else { let initial = user .name @@ -76,11 +78,13 @@ pub async fn avatar(cx: &Cx, user: &im_core::model::User) -> Result { .unwrap_or('?') .to_uppercase() .to_string(); - view! { + Ok(view! { cx => (initial) } + .boxed()) } + } /// The one script im serves, and the only behavior it carries: the avatar @@ -94,7 +98,7 @@ pub async fn avatar(cx: &Cx, user: &im_core::model::User) -> Result { /// document listeners, so the hard-post re-render never needs rewiring. /// Emitted by the landing and the person page — every surface that draws a /// clickable face. -pub async fn avatar_script(cx: &Cx, lang: Lang) -> Result { +pub async fn avatar_script(cx: &Cx, lang: Lang) -> Result { use topcoat::view::Unescaped; /// Single-quoted into the script below; the staged strings carry no /// quoting of their own, and this keeps it true if one ever does. @@ -212,7 +216,7 @@ pub async fn avatar_script(cx: &Cx, lang: Lang) -> Result { "__IM_CANCEL_UPLOAD__", &js_escape(t(lang, Key::CancelUploadLabel)), ); - view! { cx => } + Ok(view! { cx => }) } /// Soft navigation, iz's model cut to im's shape: same-app links and form @@ -222,7 +226,7 @@ pub async fn avatar_script(cx: &Cx, lang: Lang) -> Result { /// belong to the avatar script above and are left to it. Global listeners /// live on document/window and survive every swap; the guard makes the /// re-created script a no-op. -pub async fn soft_nav_script(cx: &Cx) -> Result { +pub async fn soft_nav_script(cx: &Cx) -> Result { use topcoat::view::Unescaped; const JS: &str = r#"(function () { if (window.__imSoft) { return; } @@ -410,7 +414,7 @@ pub async fn soft_nav_script(cx: &Cx) -> Result { .catch(function () {}); }; })();"#; - view! { cx => } + Ok(view! { cx => }) } /// The live channel's client, iz's shape: a bare tick says *something* @@ -418,7 +422,7 @@ pub async fn soft_nav_script(cx: &Cx) -> Result { /// ordinary gate answers — and morphs with fields and scroll intact. A /// focused field freezes the refresh mid-typing. Mounted only for a signed-in /// viewer, so auth screens never reconnect against a 401. -pub async fn live_script(cx: &Cx) -> Result { +pub async fn live_script(cx: &Cx) -> Result { use topcoat::view::Unescaped; const JS: &str = r#"(function () { if (window.__imLive) { return; } @@ -433,19 +437,28 @@ pub async fn live_script(cx: &Cx) -> Result { src.onmessage = function () { schedule(); }; } catch (err) {} })();"#; - view! { cx => } + Ok(view! { cx => }) } /// A full document around an already-rendered stage — the same way /// izlek-web's `#[layout]` receives its slot. The viewer stamps the chrome: /// their theme/language/ui when signed in, English/light/instrument when /// not — mirroring iz's root_layout, minus its build stamp. -pub async fn shell(cx: &Cx, title: &str, viewer: Option<&User>, stage: Result) -> Result { - let stage = stage?; - let lang = lang_of(viewer); - let dark = viewer.is_some_and(|user| user.theme == "dark"); - let ui = viewer.map_or("instrument", |user| user.ui.as_str()); - view! { +pub async fn shell<'a>( + cx: &'a Cx, + title: impl Into, + viewer: Option, + stage: Child<'a>, +) -> Result { + let title = title.into(); + let lang = lang_of(viewer.as_ref()); + let dark = viewer.as_ref().is_some_and(|user| user.theme == "dark"); + let ui = viewer + .as_ref() + .map_or("instrument", |user| user.ui.as_str()) + .to_string(); + let live = viewer.is_some(); + Ok(view! { cx => @@ -463,12 +476,12 @@ pub async fn shell(cx: &Cx, title: &str, viewer: Option<&User>, stage: Result) - (stage) - (soft_nav_script(cx).await?) - if viewer.is_some() { - (live_script(cx).await?) - (crate::dropdown::dropdown_script(cx).await?) + (soft_nav_script(cx).await?.first().await?) + if live { + (live_script(cx).await?.first().await?) + (crate::dropdown::dropdown_script(cx).await?.first().await?) } - } + }) } diff --git a/crates/im-web/src/live.rs b/crates/im-web/src/live.rs index 139c428..198ce92 100644 --- a/crates/im-web/src/live.rs +++ b/crates/im-web/src/live.rs @@ -49,61 +49,59 @@ async fn live(cx: &Cx) -> topcoat::Result { let events = futures_util::stream::unfold( (rx, deadline, stopping), |(mut rx, deadline, mut stopping)| async move { - loop { - // Already going down: end, so this connection is not one the - // shutdown has to sit and wait out. - if stopping.as_ref().is_some_and(|watch| *watch.borrow()) { - return None; - } - let left = deadline.saturating_duration_since(Instant::now()); - if left.is_zero() { - return None; + // Already going down: end, so this connection is not one the + // shutdown has to sit and wait out. + if stopping.as_ref().is_some_and(|watch| *watch.borrow()) { + return None; + } + let left = deadline.saturating_duration_since(Instant::now()); + if left.is_zero() { + return None; + } + // Three things end the wait: an announcement, the window + // running out, and the server being told to stop. The third + // is watched rather than polled, so SIGTERM is felt at once. + let heard = tokio::time::timeout(left, async { + match stopping.as_mut() { + Some(watch) => tokio::select! { + _ = watch.changed() => None, + got = rx.recv() => Some(got), + }, + None => Some(rx.recv().await), } - // Three things end the wait: an announcement, the window - // running out, and the server being told to stop. The third - // is watched rather than polled, so SIGTERM is felt at once. - let heard = tokio::time::timeout(left, async { - match stopping.as_mut() { - Some(watch) => tokio::select! { - _ = watch.changed() => None, - got = rx.recv() => Some(got), - }, - None => Some(rx.recv().await), - } - }) - .await; - match heard { - // The window closed, or the server is stopping. Ending - // the stream is the point: the browser reconnects by - // itself and authenticates again. - Err(_) | Ok(None) => return None, - // The broadcaster is gone, which means the process is - // going with it. - Ok(Some(Err(RecvError::Closed))) => return None, - // This reader fell behind and announcements were dropped. - // Which ones is unknowable, so the tick says "re-read - // everything" — the client refetches the whole page, so - // a lagged tick and a plain tick are the same frame. - Ok(Some(Err(RecvError::Lagged(_)))) | Ok(Some(Ok(server::LiveEvent::Tick))) => {} - // One member's row changed. The frame names which one — - // im's own client still just re-fetches the page it is - // on, so the payload is forward-compatibility for a - // future page that can react to its own subject alone. - Ok(Some(Ok(server::LiveEvent::Profile(member)))) => { - return Some(( - Ok::<_, std::convert::Infallible>(Event::new().data( - serde_json::json!({ "kind": "profile", "sub": member.sub }) - .to_string(), - )), - (rx, deadline, stopping), - )); - } + }) + .await; + match heard { + // The window closed, or the server is stopping. Ending + // the stream is the point: the browser reconnects by + // itself and authenticates again. + Err(_) | Ok(None) => return None, + // The broadcaster is gone, which means the process is + // going with it. + Ok(Some(Err(RecvError::Closed))) => return None, + // This reader fell behind and announcements were dropped. + // Which ones is unknowable, so the tick says "re-read + // everything" — the client refetches the whole page, so + // a lagged tick and a plain tick are the same frame. + Ok(Some(Err(RecvError::Lagged(_)))) | Ok(Some(Ok(server::LiveEvent::Tick))) => {} + // One member's row changed. The frame names which one — + // im's own client still just re-fetches the page it is + // on, so the payload is forward-compatibility for a + // future page that can react to its own subject alone. + Ok(Some(Ok(server::LiveEvent::Profile(member)))) => { + return Some(( + Ok::<_, std::convert::Infallible>(Event::new().data( + serde_json::json!({ "kind": "profile", "sub": member.sub }) + .to_string(), + )), + (rx, deadline, stopping), + )); } - return Some(( - Ok::<_, std::convert::Infallible>(Event::new().data("{}")), - (rx, deadline, stopping), - )); } + Some(( + Ok::<_, std::convert::Infallible>(Event::new().data("{}")), + (rx, deadline, stopping), + )) }, ); diff --git a/crates/im-web/src/pages.rs b/crates/im-web/src/pages.rs index 813bf8d..aa5e742 100644 --- a/crates/im-web/src/pages.rs +++ b/crates/im-web/src/pages.rs @@ -9,7 +9,7 @@ use topcoat::context::Cx; use topcoat::router::error::see_other; use topcoat::router::response::{IntoResponse, Response}; use topcoat::router::{page, path_param, route}; -use topcoat::view::view; +use topcoat::view::{BoxView, Child, View, ViewExt, view}; use crate::i18n::{Key, Lang, lang_of, t}; use crate::layout::{avatar, family_wordmark, shell, wordmark}; @@ -161,21 +161,21 @@ fn current_query(cx: &Cx) -> String { /// The front door: the sign-in card, or the signed-in landing when the /// browser already holds a session. #[page("/")] -async fn landing(cx: &Cx) -> Result { +async fn landing(cx: &Cx) -> Result> { match server::current_user(cx).await { - Some(user) => signed_in(cx, &user).await, - None => login_card(cx).await, + Some(user) => signed_in(cx, user).await.map(ViewExt::boxed), + None => login_card(cx).await.map(ViewExt::boxed), } } /// `/login` is the same card with a `back` it must keep: the `/authorize` /// call the browser was in the middle of. #[page("/login")] -async fn login(cx: &Cx) -> Result { +async fn login(cx: &Cx) -> Result> { login_card(cx).await } -async fn login_card(cx: &Cx) -> Result { +async fn login_card(cx: &Cx) -> Result> { // No session to read a preference from — mirroring iz's auth pages. let lang = Lang::En; let query = current_query(cx); @@ -186,7 +186,7 @@ async fn login_card(cx: &Cx) -> Result { cx =>
- (wordmark(cx).await?) + (wordmark(cx).await?.first().await?)
(t(lang, Key::SignInTitle))
@@ -230,7 +230,7 @@ async fn login_card(cx: &Cx) -> Result {
}; - shell(cx, t(lang, Key::TitleSignIn), None, stage).await + shell(cx, t(lang, Key::TitleSignIn), None, Child::new(stage)).await.map(ViewExt::boxed) } /// The second factor. Reached only with a pending-login cookie; without one @@ -246,7 +246,7 @@ async fn totp(cx: &Cx) -> Result { cx =>
- (wordmark(cx).await?) + (wordmark(cx).await?.first().await?)
(t(lang, Key::TotpTitle))
@@ -277,9 +277,11 @@ async fn totp(cx: &Cx) -> Result {
}; - shell(cx, t(lang, Key::TitleTotp), None, stage) - .await? - .into_response(cx) + shell(cx, t(lang, Key::TitleTotp), None, Child::new(stage)) + .await? + .first() + .await? + .into_response(cx) } _ => see_other("/login").into_response(cx), } @@ -305,7 +307,7 @@ async fn invite(cx: &Cx) -> Result { cx =>
- (wordmark(cx).await?) + (wordmark(cx).await?.first().await?)
(t(lang, Key::InviteTitle))
@@ -363,6 +365,7 @@ async fn invite(cx: &Cx) -> Result {
} + .boxed() } else { let code = match &invite { None => "invite_invalid", @@ -373,7 +376,7 @@ async fn invite(cx: &Cx) -> Result { cx =>
- (wordmark(cx).await?) + (wordmark(cx).await?.first().await?)
(t(lang, Key::InviteDeadTitle))
@@ -384,8 +387,11 @@ async fn invite(cx: &Cx) -> Result {
} + .boxed() }; - shell(cx, t(lang, Key::TitleInvited), None, stage) + shell(cx, t(lang, Key::TitleInvited), None, Child::new(stage)) + .await? + .first() .await? .into_response(cx) } @@ -414,12 +420,10 @@ async fn enroll(cx: &Cx) -> Result { let issuer = &server::app(cx).config.issuer; let uri = im_core::totp::totp_uri("im", &user.email, &secret); let qr = qrcode::QrCode::new(uri.as_bytes()) - .and_then(|code| { - Ok::<_, qrcode::types::QrError>( - code.render::() - .min_dimensions(200, 200) - .build(), - ) + .map(|code| { + code.render::() + .min_dimensions(200, 200) + .build() }) .map_err(|e| topcoat::Error::from(std::io::Error::other(format!("qr: {e}"))))?; let manual = im_core::totp::display_secret(&secret); @@ -432,7 +436,7 @@ async fn enroll(cx: &Cx) -> Result { cx =>
- (wordmark(cx).await?) + (wordmark(cx).await?.first().await?)
(t(lang, Key::EnrollTitle))
@@ -465,7 +469,9 @@ async fn enroll(cx: &Cx) -> Result {
}; - shell(cx, t(lang, Key::TitleEnroll), Some(&user), stage) + shell(cx, t(lang, Key::TitleEnroll), Some(user), Child::new(stage)) + .await? + .first() .await? .into_response(cx) } @@ -648,16 +654,14 @@ fn apps_html(apps: &[im_core::oidc::ConnectedApp], lang: Lang) -> String { } rows } - -/// The signed-in landing. im is an auth service, not an app: this page is /// the proof of session, the person's profile — photo and the counts their /// identity has earned — and the way out. izlek gives a profile its own /// page under `/people`; im has exactly one signed-in screen, so the /// profile is a section of it. Six cards in one column ran twice the height /// of a window, so the landing is sectioned like the admin panel: a tab row /// under the wordmark, one section's cards at a time. -async fn signed_in(cx: &Cx, user: &im_core::model::User) -> Result { - let lang = lang_of(Some(user)); +async fn signed_in<'a>(cx: &'a Cx, user: im_core::model::User) -> Result> { + let lang = lang_of(Some(&user)); let query = current_query(cx); let section = query_value(&query, "section").unwrap_or_else(|| "profile".to_string()); let ok = query_value(&query, "ok"); @@ -692,6 +696,25 @@ async fn signed_in(cx: &Cx, user: &im_core::model::User) -> Result { ) }) .collect::(); + // The stage template moves every value it mentions, so the account's + // template data is staged here as owned values first; the markup below + // never names `user` itself. + let face_button = avatar(cx, &user).await?.first().await?; + let face_plain = avatar(cx, &user).await?.first().await?; + let theme_light = user.theme == "light"; + let theme_dark = user.theme == "dark"; + let ui_instrument = user.ui == "instrument"; + let ui_ledger = user.ui == "ledger"; + let lang_en = user.language == "en"; + let lang_tr = user.language == "tr"; + let timezone_options = timezone_select(&user.timezone); + let email_form = user.email.clone(); + let email_shown = user.email.clone(); + let display_name = user.name.clone(); + let has_photo = user.has_photo; + let totp_on = user.totp_confirmed; + let is_admin = user.admin; + let public_href = format!("/people/{}", user.id); // The family lives in the chrome — the siblings' flyout under the // wordmark — and its editing in the admin panel; the landing is the // account's own page and carries no directory of its own. @@ -699,7 +722,7 @@ async fn signed_in(cx: &Cx, user: &im_core::model::User) -> Result { cx =>
- (family_wordmark(cx).await?) + (family_wordmark(cx).await?.first().await?) if let Some(code) = ok {
(ok_text(&code, lang))
@@ -733,28 +756,28 @@ async fn signed_in(cx: &Cx, user: &im_core::model::User) -> Result { Result { // label wraps the hidden input, which autosubmits // on change (avatar_script) — no buttons at all. }
-
(user.name.clone())
+
(display_name)
- if user.totp_confirmed { + if totp_on { (t(lang, Key::TwoFaOn)) } else { (t(lang, Key::TwoFaOff)) } - if user.admin { + if is_admin { (t(lang, Key::AdminChip)) }
@@ -894,18 +917,18 @@ async fn signed_in(cx: &Cx, user: &im_core::model::User) -> Result {
(t(lang, Key::EmailLabel))
-
(user.email.clone())
+
(email_shown)
(t(lang, Key::MemberSinceLabel))
(joined)
- (t(lang, Key::PublicProfileLink)) - if !user.totp_confirmed { + (t(lang, Key::PublicProfileLink)) + if !totp_on { (t(lang, Key::Activate2fa)) } - if user.admin { + if is_admin { (t(lang, Key::AdminPanelLink)) } // Both forms carry no visible chrome of their own: the @@ -917,7 +940,7 @@ async fn signed_in(cx: &Cx, user: &im_core::model::User) -> Result { action="/api/profile_photo" enctype="multipart/form-data" > - if user.has_photo { + if has_photo {
Result {
- (crate::layout::avatar_script(cx, lang).await?) + (crate::layout::avatar_script(cx, lang).await?.first().await?) }; - shell(cx, "im", Some(user), stage).await + shell(cx, "im", Some(user), Child::new(stage)).await.map(ViewExt::boxed) } /// "Forgot it?" — the self-serve reset ask. It answers the same whether the /// address has an account: one quiet note, the same one for every address. #[page("/forgot")] -async fn forgot(cx: &Cx) -> Result { +async fn forgot(cx: &Cx) -> Result { let lang = Lang::En; let query = current_query(cx); let error = query_value(&query, "error"); @@ -962,7 +985,7 @@ async fn forgot(cx: &Cx) -> Result { cx =>
- (wordmark(cx).await?) + (wordmark(cx).await?.first().await?)
(t(lang, Key::ForgotTitle))
@@ -995,7 +1018,7 @@ async fn forgot(cx: &Cx) -> Result {
}; - shell(cx, t(lang, Key::TitleForgot), None, stage).await + shell(cx, t(lang, Key::TitleForgot), None, Child::new(stage)).await } /// The reset link's destination: a new password, twice. A dead link never @@ -1013,7 +1036,7 @@ async fn reset_page(cx: &Cx) -> Result { cx =>
- (wordmark(cx).await?) + (wordmark(cx).await?.first().await?)
(t(lang, Key::ResetTitle))
@@ -1055,7 +1078,9 @@ async fn reset_page(cx: &Cx) -> Result {
}; - shell(cx, t(lang, Key::TitleReset), None, stage) + shell(cx, t(lang, Key::TitleReset), None, Child::new(stage)) + .await? + .first() .await? .into_response(cx) } @@ -1075,7 +1100,7 @@ async fn email_change_page(cx: &Cx) -> Result { cx =>
- (wordmark(cx).await?) + (wordmark(cx).await?.first().await?)
(t(lang, Key::EmailConfirmTitle))
@@ -1094,7 +1119,9 @@ async fn email_change_page(cx: &Cx) -> Result {
}; - shell(cx, t(lang, Key::EmailConfirmTitle), None, stage) + shell(cx, t(lang, Key::EmailConfirmTitle), None, Child::new(stage)) + .await? + .first() .await? .into_response(cx) } diff --git a/crates/im-web/src/people.rs b/crates/im-web/src/people.rs index 0cfa099..3d7876e 100644 --- a/crates/im-web/src/people.rs +++ b/crates/im-web/src/people.rs @@ -9,7 +9,7 @@ use topcoat::Result; use topcoat::context::Cx; use topcoat::router::error::not_found; use topcoat::router::{page, path_param}; -use topcoat::view::view; +use topcoat::view::{Child, View, ViewExt, view}; use im_core::accounts; @@ -21,7 +21,7 @@ path_param!(user_id); /// A person's page. `/people/{user_id}`. #[page("/people/{user_id}")] -async fn people_page(cx: &Cx) -> Result { +async fn people_page(cx: &Cx) -> Result { let Some(viewer) = server::current_user(cx).await else { return Err(not_found().into()); }; @@ -35,31 +35,42 @@ async fn people_page(cx: &Cx) -> Result { let mine = person.id == viewer.id; let stats = im_core::stats::profile_stats(&store, &person.id).await?; let joined = person.created_at.date().to_string(); + // The stage template moves every value it mentions, so the account's + // template data is staged here as owned values first; the markup below + // never names `person` itself. + let face_button = avatar(cx, &person).await?.first().await?; + let face_plain = avatar(cx, &person).await?.first().await?; + let display_name = person.name.clone(); + let email_shown = person.email.clone(); + let has_photo = person.has_photo; + let totp_on = person.totp_confirmed; + let is_admin = person.admin; + let profile_title = format!("{} · im", person.name); let stage = view! { cx =>
- (family_wordmark(cx).await?) + (family_wordmark(cx).await?.first().await?)
- if person.has_photo { + if has_photo { // The face opens the viewer here too — same as // the landing, same as iz's person page. } else { - (avatar(cx, &person).await?) + (face_plain) }
-
(person.name.clone())
+
(display_name)
- if person.totp_confirmed { + if totp_on { (t(lang, Key::TwoFaOn)) } else { (t(lang, Key::TwoFaOff)) } - if person.admin { + if is_admin { (t(lang, Key::AdminChip)) }
@@ -68,7 +79,7 @@ async fn people_page(cx: &Cx) -> Result {
(t(lang, Key::EmailLabel))
-
(person.email.clone())
+
(email_shown)
(t(lang, Key::MemberSinceLabel))
@@ -98,7 +109,7 @@ async fn people_page(cx: &Cx) -> Result {
- (crate::layout::avatar_script(cx, lang).await?) + (crate::layout::avatar_script(cx, lang).await?.first().await?) }; - shell(cx, &format!("{} · im", person.name), Some(&viewer), stage).await + shell(cx, profile_title, Some(viewer), Child::new(stage)).await } diff --git a/crates/im-web/src/server.rs b/crates/im-web/src/server.rs index ae87c86..99a6f75 100644 --- a/crates/im-web/src/server.rs +++ b/crates/im-web/src/server.rs @@ -86,8 +86,8 @@ const SHOWN_TTL: Duration = Duration::from_secs(10 * 60); /// page's read takes it out (`take_shown_secret`), and a replayed or /// reloaded URL finds the shelf empty and renders no secret at all. A /// restart drops the shelf — the admin mints another, as with the CLI. -static SHOWN_SECRETS: LazyLock>> = - LazyLock::new(|| Mutex::new(HashMap::new())); +type ShownShelf = HashMap; +static SHOWN_SECRETS: LazyLock> = LazyLock::new(|| Mutex::new(HashMap::new())); /// Parks a client's fresh pair on the shelf and returns the claim ticket /// for its URL. The id travels too — it is the public half of the pair and