diff --git a/Cargo.lock b/Cargo.lock index 8dee183..773d7f9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -544,6 +544,41 @@ dependencies = [ "syn", ] +[[package]] +name = "darling" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f63b86c8a8826a49b8c21f08a2d07338eec8d900540f8630dc76284be802989" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95133861a8032aaea082871032f5815eb9e98cef03fa916ab4500513994df9e5" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn", +] + +[[package]] +name = "darling_macro" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" +dependencies = [ + "darling_core", + "quote", + "syn", +] + [[package]] name = "dashmap" version = "5.5.3" @@ -565,7 +600,7 @@ checksum = "e8566979429cf69b49a5c740c60791108e86440e8be149bbea4fe54d2c32d6e2" [[package]] name = "ddnet-account-client" -version = "0.1.0" +version = "0.2.0" dependencies = [ "anyhow", "async-trait", @@ -583,7 +618,7 @@ dependencies = [ [[package]] name = "ddnet-account-client-http-fs" -version = "0.1.0" +version = "0.2.0" dependencies = [ "anyhow", "async-trait", @@ -596,6 +631,7 @@ dependencies = [ "parking_lot", "serde", "serde_json", + "serde_with", "tempfile", "tokio", "url", @@ -604,7 +640,7 @@ dependencies = [ [[package]] name = "ddnet-account-client-reqwest" -version = "0.1.0" +version = "0.2.0" dependencies = [ "anyhow", "async-trait", @@ -616,7 +652,7 @@ dependencies = [ [[package]] name = "ddnet-account-game-server" -version = "0.2.0" +version = "0.3.0" dependencies = [ "anyhow", "async-trait", @@ -630,7 +666,7 @@ dependencies = [ [[package]] name = "ddnet-account-sql" -version = "0.2.0" +version = "0.3.0" dependencies = [ "anyhow", "async-trait", @@ -640,7 +676,7 @@ dependencies = [ [[package]] name = "ddnet-accounts" -version = "0.1.1" +version = "0.2.0" dependencies = [ "anyhow", "argon2", @@ -688,7 +724,7 @@ dependencies = [ [[package]] name = "ddnet-accounts-shared" -version = "0.1.0" +version = "0.2.0" dependencies = [ "anyhow", "argon2", @@ -762,6 +798,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" dependencies = [ "powerfmt", + "serde", ] [[package]] @@ -864,9 +901,9 @@ dependencies = [ [[package]] name = "email-encoding" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60d1d33cdaede7e24091f039632eb5d3c7469fe5b066a985281a34fc70fa317f" +checksum = "ea3d894bbbab314476b265f9b2d46bf24b123a36dd0e96b06a1b49545b9d9dcc" dependencies = [ "base64", "memchr", @@ -1229,13 +1266,19 @@ dependencies = [ "futures-core", "futures-sink", "http", - "indexmap", + "indexmap 2.6.0", "slab", "tokio", "tokio-util", "tracing", ] +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" + [[package]] name = "hashbrown" version = "0.14.5" @@ -1577,6 +1620,12 @@ dependencies = [ "syn", ] +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + [[package]] name = "idna" version = "1.0.3" @@ -1598,6 +1647,17 @@ dependencies = [ "icu_properties", ] +[[package]] +name = "indexmap" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" +dependencies = [ + "autocfg", + "hashbrown 0.12.3", + "serde", +] + [[package]] name = "indexmap" version = "2.6.0" @@ -1606,6 +1666,7 @@ checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" dependencies = [ "equivalent", "hashbrown 0.15.2", + "serde", ] [[package]] @@ -1666,10 +1727,11 @@ checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674" [[package]] name = "js-sys" -version = "0.3.72" +version = "0.3.74" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a88f1bda2bd75b0452a14784937d796722fdebfe50df998aeb3f0b7603019a9" +checksum = "a865e038f7f6ed956f788f0d7d60c541fff74c7bd74272c5d4cf15c63743e705" dependencies = [ + "once_cell", "wasm-bindgen", ] @@ -2207,9 +2269,9 @@ checksum = "2f3a9f18d041e6d0e102a0a46750538147e5e8992d3b4873aaafee2520b00ce3" [[package]] name = "portable-atomic" -version = "1.9.0" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc9c68a3f6da06753e9335d63e27f6b9754dd1920d941135b7ea8224f141adb2" +checksum = "280dc24453071f1b63954171985a0b0d30058d287960968b9b2aca264c8d4ee6" [[package]] name = "powerfmt" @@ -2246,9 +2308,9 @@ dependencies = [ [[package]] name = "psm" -version = "0.1.23" +version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa37f80ca58604976033fae9515a8a2989fc13797d953f7c04fb8fa36a11f205" +checksum = "200b9ff220857e53e184257720a14553b2f4aa02577d2ed9842d45d4b9654810" dependencies = [ "cc", ] @@ -2315,9 +2377,9 @@ dependencies = [ [[package]] name = "raw-cpuid" -version = "11.1.0" +version = "11.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb9ee317cfe3fbd54b36a511efc1edd42e216903c9cd575e686dd68a2ba90d8d" +checksum = "1ab240315c661615f2ee9f0f2cd32d5a7343a84d5ebcccb99d46e6637565e7b0" dependencies = [ "bitflags 2.6.0", ] @@ -2561,9 +2623,9 @@ dependencies = [ [[package]] name = "schannel" -version = "0.1.26" +version = "0.1.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" +checksum = "1f29ebaa345f945cec9fbbc532eb307f0fdad8161f281b6369539c8d84876b3d" dependencies = [ "windows-sys 0.59.0", ] @@ -2603,9 +2665,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.12.0" +version = "2.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" +checksum = "fa39c7303dc58b5543c94d22c1766b0d31f2ee58306363ea622b10bbc075eaa2" dependencies = [ "core-foundation-sys", "libc", @@ -2671,6 +2733,36 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_with" +version = "3.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e28bdad6db2b8340e449f7108f020b3b092e8583a9e3fb82713e1d4e71fe817" +dependencies = [ + "base64", + "chrono", + "hex", + "indexmap 1.9.3", + "indexmap 2.6.0", + "serde", + "serde_derive", + "serde_json", + "serde_with_macros", + "time", +] + +[[package]] +name = "serde_with_macros" +version = "3.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d846214a9854ef724f3da161b426242d8de7c1fc7de2f89bb1efcb154dca79d" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "sha1" version = "0.10.6" @@ -2811,7 +2903,7 @@ dependencies = [ "hashbrown 0.14.5", "hashlink", "hex", - "indexmap", + "indexmap 2.6.0", "log", "memchr", "once_cell", @@ -3503,9 +3595,9 @@ checksum = "b8dad83b4f25e74f184f64c43b150b91efe7647395b42289f38e50566d82855b" [[package]] name = "wasm-bindgen" -version = "0.2.95" +version = "0.2.97" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "128d1e363af62632b8eb57219c8fd7877144af57558fb2ef0368d0087bddeb2e" +checksum = "d15e63b4482863c109d70a7b8706c1e364eb6ea449b201a76c5b89cedcec2d5c" dependencies = [ "cfg-if", "once_cell", @@ -3514,9 +3606,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.95" +version = "0.2.97" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb6dd4d3ca0ddffd1dd1c9c04f94b868c37ff5fac97c30b97cff2d74fce3a358" +checksum = "8d36ef12e3aaca16ddd3f67922bc63e48e953f126de60bd33ccc0101ef9998cd" dependencies = [ "bumpalo", "log", @@ -3529,21 +3621,22 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.45" +version = "0.4.47" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc7ec4f8827a71586374db3e87abdb5a2bb3a15afed140221307c3ec06b1f63b" +checksum = "9dfaf8f50e5f293737ee323940c7d8b08a66a95a419223d9f41610ca08b0833d" dependencies = [ "cfg-if", "js-sys", + "once_cell", "wasm-bindgen", "web-sys", ] [[package]] name = "wasm-bindgen-macro" -version = "0.2.95" +version = "0.2.97" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e79384be7f8f5a9dd5d7167216f022090cf1f9ec128e6e6a482a2cb5c5422c56" +checksum = "705440e08b42d3e4b36de7d66c944be628d579796b8090bfa3471478a2260051" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -3551,9 +3644,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.95" +version = "0.2.97" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26c6ab57572f7a24a4985830b120de1594465e5d500f24afe89e16b4e833ef68" +checksum = "98c9ae5a76e46f4deecd0f0255cc223cfa18dc9b261213b8aa0c7b36f61b3f1d" dependencies = [ "proc-macro2", "quote", @@ -3564,15 +3657,15 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.95" +version = "0.2.97" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65fc09f10666a9f147042251e0dda9c18f166ff7de300607007e96bdebc1068d" +checksum = "6ee99da9c5ba11bd675621338ef6fa52296b76b83305e9b6e5c77d4c286d6d49" [[package]] name = "web-sys" -version = "0.3.72" +version = "0.3.74" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6488b90108c040df0fe62fa815cbdee25124641df01814dd7282749234c6112" +checksum = "a98bc3c33f0fe7e59ad7cd041b89034fa82a7c2d4365ca538dda6cdaf513863c" dependencies = [ "js-sys", "wasm-bindgen", diff --git a/Cargo.toml b/Cargo.toml index eb87ee7..5b0ab74 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ members = [ [package] name = "ddnet-accounts" -version = "0.1.1" +version = "0.2.0" edition = "2021" authors = ["Jupeyy"] license = "MIT OR Apache-2.0" @@ -24,8 +24,8 @@ name = "account-server" [dependencies] ddnet-accounts-types = { version = "0.1.0", path = "lib/ddnet-accounts-types" } -ddnet-accounts-shared = { version = "0.1.0", path = "lib/ddnet-accounts-shared" } -ddnet-account-sql = { version = "0.2.0", path = "lib/ddnet-account-sql", features = ["mysql"] } +ddnet-accounts-shared = { version = "0.2.0", path = "lib/ddnet-accounts-shared" } +ddnet-account-sql = { version = "0.3.0", path = "lib/ddnet-account-sql", features = ["mysql"] } tokio = { version = "1.41.1", features = ["rt-multi-thread", "sync", "fs", "time", "macros"] } axum = "0.7.9" @@ -62,10 +62,10 @@ either = "1.13.0" notify = { version = "7.0.0", default-features = false, features = ["macos_kqueue"] } [dev-dependencies] -ddnet-account-client = { version = "0.1.0", path = "lib/ddnet-account-client" } -ddnet-account-game-server = { version = "0.2.0", path = "lib/ddnet-account-game-server" } -ddnet-account-client-http-fs = { version = "0.1.0", path = "lib/ddnet-account-client-http-fs" } -ddnet-account-client-reqwest = { version = "0.1.0", path = "lib/ddnet-account-client-reqwest" } +ddnet-account-client = { version = "0.2.0", path = "lib/ddnet-account-client" } +ddnet-account-game-server = { version = "0.3.0", path = "lib/ddnet-account-game-server" } +ddnet-account-client-http-fs = { version = "0.2.0", path = "lib/ddnet-account-client-http-fs" } +ddnet-account-client-reqwest = { version = "0.2.0", path = "lib/ddnet-account-client-reqwest" } regex = "1.11.1" tempfile = "3.14.0" diff --git a/lib/ddnet-account-client-http-fs/Cargo.toml b/lib/ddnet-account-client-http-fs/Cargo.toml index 74bdcdd..5da766c 100644 --- a/lib/ddnet-account-client-http-fs/Cargo.toml +++ b/lib/ddnet-account-client-http-fs/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ddnet-account-client-http-fs" -version = "0.1.0" +version = "0.2.0" edition = "2021" authors = ["Jupeyy"] license = "MIT OR Apache-2.0" @@ -8,9 +8,9 @@ description = "The base client implementation for accounts, assuming no HTTP cli repository = "https://github.com/ddnet/ddnet-accounts" [dependencies] -ddnet-accounts-shared = { version = "0.1.0", path = "../ddnet-accounts-shared" } +ddnet-accounts-shared = { version = "0.2.0", path = "../ddnet-accounts-shared" } ddnet-accounts-types = { version = "0.1.0", path = "../ddnet-accounts-types" } -ddnet-account-client = { version = "0.1.0", path = "../ddnet-account-client" } +ddnet-account-client = { version = "0.2.0", path = "../ddnet-account-client" } anyhow = { version = "1.0.93", features = ["backtrace"] } parking_lot = "0.12.3" @@ -19,6 +19,7 @@ url = { version = "2.5.4", features = ["serde"] } tokio = { version = "1.41.1", features = ["rt-multi-thread", "sync", "fs", "time", "macros"] } serde = { version = "1.0.215", features = ["derive"] } serde_json = "1.0.133" +serde_with = "3.11.0" email_address = { version = "0.2.9", features = ["serde"] } tempfile = "3.14.0" x509-cert = { version = "0.2.5" } diff --git a/lib/ddnet-account-client-http-fs/src/profiles.rs b/lib/ddnet-account-client-http-fs/src/profiles.rs index ca8ce63..8bdf129 100644 --- a/lib/ddnet-account-client-http-fs/src/profiles.rs +++ b/lib/ddnet-account-client-http-fs/src/profiles.rs @@ -27,15 +27,21 @@ use ddnet_accounts_types::account_id::AccountId; use either::Either; use parking_lot::Mutex; use serde::{Deserialize, Serialize}; +use serde_with::{serde_as, DefaultOnError}; use x509_cert::der::Decode; pub use x509_cert::Certificate; use crate::{client::DeleteAccountExt, fs::Fs}; +#[serde_as] #[derive(Debug, Default, Clone, Serialize, Deserialize)] pub struct ProfileData { pub name: String, + + #[serde(default)] + #[serde_as(deserialize_as = "DefaultOnError")] + pub user: HashMap, } #[derive(Debug, Default, Clone, Serialize, Deserialize)] @@ -288,11 +294,12 @@ impl< Ok(account_data.account_data) } + /// Returns the profile's name async fn login_impl( &self, display_name: &str, credential_auth_token_hex: String, - ) -> anyhow::Result<()> { + ) -> anyhow::Result { let path = self.secure_base_path.join("acc_prepare"); let account_client = Arc::new((self.factory)(path).await?); @@ -322,6 +329,7 @@ impl< cur_cert: Default::default(), profile_data: ProfileData { name: display_name.to_string(), + user: Default::default(), }, }; @@ -338,15 +346,17 @@ impl< self.signed_cert_and_key_pair().await; - Ok(()) + Ok(profile_name) } - /// try to login via credential auth token previously created with e.g. [`Self::credential_auth_email_token`] + /// Try to login via credential auth token previously created with e.g. [`Self::credential_auth_email_token`] + /// + /// Returns the profile's name pub async fn login_email( &self, email: email_address::EmailAddress, credential_auth_token_hex: String, - ) -> anyhow::Result<()> { + ) -> anyhow::Result { self.login_impl( &format!("{}'s account", email.local_part()), credential_auth_token_hex, @@ -355,11 +365,13 @@ impl< } /// try to login via credential auth token previously created with e.g. [`Self::login_steam_token`] + /// + /// Returns the profile's name pub async fn login_steam( &self, steam_user_name: String, credential_auth_token_hex: String, - ) -> anyhow::Result<()> { + ) -> anyhow::Result { self.login_impl( &format!("{}'s account", steam_user_name), credential_auth_token_hex, @@ -788,6 +800,15 @@ impl< (profiles.profiles, profiles.cur_profile) } + /// Get the currently active profile's profile data or `None`. + pub fn current_profile(&self) -> Option { + let profiles = self.profiles.lock(); + profiles + .profiles + .get(&profiles.cur_profile) + .map(|p| p.profile_data.clone()) + } + /// Set the current profile to a new one. /// Silently fails, if the new profile does not exist. pub async fn set_profile(&self, profile_name: &str) { @@ -819,6 +840,25 @@ impl< let _ = profiles_state.save(&self.fs).await; } + + /// Sets arbitrary data specified by the implementation, saved inside the profiles struct + pub async fn set_profile_user_data( + &self, + profile_name: &str, + user: HashMap, + ) { + let profiles_state; + { + let mut profiles = self.profiles.lock(); + if let Some(profile) = profiles.profiles.get_mut(profile_name) { + profile.profile_data.user = user; + } + profiles_state = Self::to_profile_states(&profiles); + drop(profiles); + } + + let _ = profiles_state.save(&self.fs).await; + } } #[derive(Debug)] diff --git a/lib/ddnet-account-client-reqwest/Cargo.toml b/lib/ddnet-account-client-reqwest/Cargo.toml index 0c6e07d..a7679c4 100644 --- a/lib/ddnet-account-client-reqwest/Cargo.toml +++ b/lib/ddnet-account-client-reqwest/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ddnet-account-client-reqwest" -version = "0.1.0" +version = "0.2.0" edition = "2021" authors = ["Jupeyy"] license = "MIT OR Apache-2.0" @@ -8,8 +8,8 @@ description = "The client implementation using reqwest as HTTP client." repository = "https://github.com/ddnet/ddnet-accounts" [dependencies] -ddnet-account-client-http-fs = { version = "0.1.0", path = "../ddnet-account-client-http-fs" } -ddnet-account-client = { version = "0.1.0", path = "../ddnet-account-client" } +ddnet-account-client-http-fs = { version = "0.2.0", path = "../ddnet-account-client-http-fs" } +ddnet-account-client = { version = "0.2.0", path = "../ddnet-account-client" } async-trait = "0.1.83" url = { version = "2.5.4", features = ["serde"] } diff --git a/lib/ddnet-account-client/Cargo.toml b/lib/ddnet-account-client/Cargo.toml index 69e8474..7953a39 100644 --- a/lib/ddnet-account-client/Cargo.toml +++ b/lib/ddnet-account-client/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ddnet-account-client" -version = "0.1.0" +version = "0.2.0" edition = "2021" authors = ["Jupeyy"] license = "MIT OR Apache-2.0" @@ -8,7 +8,7 @@ description = "The account related operations of a client, that want to manage a repository = "https://github.com/ddnet/ddnet-accounts" [dependencies] -ddnet-accounts-shared = { version = "0.1.0", path = "../ddnet-accounts-shared" } +ddnet-accounts-shared = { version = "0.2.0", path = "../ddnet-accounts-shared" } ddnet-accounts-types = { version = "0.1.0", path = "../ddnet-accounts-types" } async-trait = "0.1.83" diff --git a/lib/ddnet-account-game-server/Cargo.toml b/lib/ddnet-account-game-server/Cargo.toml index 11cb73b..a93b47c 100644 --- a/lib/ddnet-account-game-server/Cargo.toml +++ b/lib/ddnet-account-game-server/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ddnet-account-game-server" -version = "0.2.0" +version = "0.3.0" edition = "2021" authors = ["Jupeyy"] license = "MIT OR Apache-2.0" @@ -9,8 +9,8 @@ repository = "https://github.com/ddnet/ddnet-accounts" [dependencies] ddnet-accounts-types = { version = "0.1.0", path = "../ddnet-accounts-types" } -ddnet-accounts-shared = { version = "0.1.0", path = "../ddnet-accounts-shared" } -ddnet-account-sql = { version = "0.2.0", path = "../ddnet-account-sql", default-features = false } +ddnet-accounts-shared = { version = "0.2.0", path = "../ddnet-accounts-shared" } +ddnet-account-sql = { version = "0.3.0", path = "../ddnet-account-sql", default-features = false } sqlx = { version = "0.8.2", features = ["any", "runtime-tokio-rustls", "chrono"] } anyhow = { version = "1.0.93", features = ["backtrace"] } diff --git a/lib/ddnet-account-sql/Cargo.toml b/lib/ddnet-account-sql/Cargo.toml index 18dcf0e..75dd0b5 100644 --- a/lib/ddnet-account-sql/Cargo.toml +++ b/lib/ddnet-account-sql/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ddnet-account-sql" -version = "0.2.0" +version = "0.3.0" edition = "2021" authors = ["Jupeyy"] license = "MIT OR Apache-2.0" diff --git a/lib/ddnet-accounts-shared/Cargo.toml b/lib/ddnet-accounts-shared/Cargo.toml index ed115b7..531f109 100644 --- a/lib/ddnet-accounts-shared/Cargo.toml +++ b/lib/ddnet-accounts-shared/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ddnet-accounts-shared" -version = "0.1.0" +version = "0.2.0" edition = "2021" authors = ["Jupeyy"] license = "MIT OR Apache-2.0"