From 868f533395be13f413d374e3b3e76ff63efb0f7a Mon Sep 17 00:00:00 2001 From: phoenix Date: Thu, 19 Nov 2026 13:02:01 -0500 Subject: [PATCH] tsk-16: Change response of Register endpoint (#17) Closes #16 Reviewed-on: https://git.kundeng.us/phoenix/soaricarus_auth/pulls/17 --- .gitea/workflows/tag_release.yml | 4 +- .gitea/workflows/workflow.yml | 24 ++--- Cargo.lock | 170 +++++++++++++++---------------- Cargo.toml | 12 +-- Dockerfile | 9 +- src/callers/register.rs | 53 +++++----- 6 files changed, 132 insertions(+), 140 deletions(-) diff --git a/.gitea/workflows/tag_release.yml b/.gitea/workflows/tag_release.yml index dff2812..e796481 100644 --- a/.gitea/workflows/tag_release.yml +++ b/.gitea/workflows/tag_release.yml @@ -7,7 +7,7 @@ on: jobs: release: - runs-on: ubuntu-24.04 + runs-on: ubuntu-26.04 steps: - name: Checkout code uses: actions/checkout@v6 @@ -17,7 +17,7 @@ jobs: - name: Install Rust uses: actions-rs/toolchain@v1 with: - toolchain: 1.99 + toolchain: 1.99.1 components: cargo - uses: Swatinem/rust-cache@v2 diff --git a/.gitea/workflows/workflow.yml b/.gitea/workflows/workflow.yml index 99966ef..0ea7166 100644 --- a/.gitea/workflows/workflow.yml +++ b/.gitea/workflows/workflow.yml @@ -3,20 +3,20 @@ name: soaricarus_auth Build on: push: branches: - - main + - main pull_request: branches: - - main + - main jobs: check: name: Check - runs-on: ubuntu-24.04 + runs-on: ubuntu-26.04 steps: - uses: actions/checkout@v6 - uses: actions-rust-lang/setup-rust-toolchain@v1 with: - toolchain: 1.99 + toolchain: 1.99.1 - uses: Swatinem/rust-cache@v2 - run: | mkdir -p ~/.ssh @@ -31,7 +31,7 @@ jobs: test: name: Test Suite - runs-on: ubuntu-24.04 + runs-on: ubuntu-26.04 services: postgres: image: postgres:18.6-alpine @@ -49,7 +49,7 @@ jobs: - uses: actions/checkout@v6 - uses: actions-rust-lang/setup-rust-toolchain@v1 with: - toolchain: 1.99 + toolchain: 1.99.1 - uses: Swatinem/rust-cache@v2 - name: Verify Docker Environment run: | @@ -83,12 +83,12 @@ jobs: fmt: name: Rustfmt - runs-on: ubuntu-24.04 + runs-on: ubuntu-26.04 steps: - uses: actions/checkout@v6 - uses: actions-rust-lang/setup-rust-toolchain@v1 with: - toolchain: 1.99 + toolchain: 1.99.1 - uses: Swatinem/rust-cache@v2 - run: rustup component add rustfmt - run: | @@ -103,12 +103,12 @@ jobs: clippy: name: Clippy - runs-on: ubuntu-24.04 + runs-on: ubuntu-26.04 steps: - uses: actions/checkout@v6 - uses: actions-rust-lang/setup-rust-toolchain@v1 with: - toolchain: 1.99 + toolchain: 1.99.1 - uses: Swatinem/rust-cache@v2 - run: rustup component add clippy - run: | @@ -123,12 +123,12 @@ jobs: build: name: build - runs-on: ubuntu-24.04 + runs-on: ubuntu-26.04 steps: - uses: actions/checkout@v6 - uses: actions-rust-lang/setup-rust-toolchain@v1 with: - toolchain: 1.99 + toolchain: 1.99.1 - uses: Swatinem/rust-cache@v2 - run: | mkdir -p ~/.ssh diff --git a/Cargo.lock b/Cargo.lock index 91033f1..340871b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -37,7 +37,7 @@ checksum = "134c52ddac6d63c576bef8168db10c83c49c26444ecbc68060fef078925a901c" dependencies = [ "base64ct", "blake2", - "cpufeatures 0.3.1", + "cpufeatures", "password-hash", ] @@ -147,16 +147,7 @@ version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b5d4d889834ee8ecfc0f8426ad30faf7cdcb10f741a8e6d7224d95325479f6f" dependencies = [ - "digest 0.11.3", -] - -[[package]] -name = "block-buffer" -version = "0.10.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" -dependencies = [ - "generic-array", + "digest", ] [[package]] @@ -215,7 +206,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "65c35e4b699c7e15ccbe7ee35c005e4fc0a278d22238a2857e6ce2dadeda1b06" dependencies = [ "cfg-if", - "cpufeatures 0.3.1", + "cpufeatures", "rand_core", ] @@ -262,15 +253,6 @@ version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" -[[package]] -name = "cpufeatures" -version = "0.2.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" -dependencies = [ - "libc", -] - [[package]] name = "cpufeatures" version = "0.3.1" @@ -319,16 +301,6 @@ version = "0.8.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a31eee39dddec8330830986fcd7625edb5a24ec90ea038215273bbc3adb08ac6" -[[package]] -name = "crypto-common" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" -dependencies = [ - "generic-array", - "typenum", -] - [[package]] name = "crypto-common" version = "0.2.2" @@ -356,24 +328,14 @@ dependencies = [ "serde_core", ] -[[package]] -name = "digest" -version = "0.10.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" -dependencies = [ - "block-buffer 0.10.4", - "crypto-common 0.1.6", -] - [[package]] name = "digest" version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1dd6dbb5841937940781866fa1281a1ff7bd3bf827091440879f9994983d5c2" dependencies = [ - "block-buffer 0.12.1", - "crypto-common 0.2.2", + "block-buffer", + "crypto-common", "ctutils", ] @@ -661,7 +623,7 @@ version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6303bc9732ae41b04cb554b844a762b4115a61bfaa81e3e83050991eeb56863f" dependencies = [ - "digest 0.11.3", + "digest", ] [[package]] @@ -929,6 +891,15 @@ version = "0.2.191" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a" +[[package]] +name = "libredox" +version = "0.1.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61ff90caf6077a803a240f62fdbe88645a890bbca49ef8174c3cb0404362171d" +dependencies = [ + "libc", +] + [[package]] name = "libsqlite3-sys" version = "0.37.0" @@ -979,7 +950,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "69b6441f590336821bb897fb28fc622898ccceb1d6cea3fde5ea86b090c4de98" dependencies = [ "cfg-if", - "digest 0.11.3", + "digest", ] [[package]] @@ -1078,6 +1049,24 @@ dependencies = [ "autocfg", ] +[[package]] +name = "objc2-core-foundation" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a180dd8642fa45cdb7dd721cd4c11b1cadd4929ce112ebd8b9f5803cc79d536" +dependencies = [ + "bitflags", +] + +[[package]] +name = "objc2-system-configuration" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7216bd11cbda54ccabcab84d523dc93b858ec75ecfb3a7d89513fa22464da396" +dependencies = [ + "objc2-core-foundation", +] + [[package]] name = "once_cell" version = "1.21.4" @@ -1248,9 +1237,9 @@ checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" [[package]] name = "rand" -version = "0.10.3" +version = "0.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65c9fb96cbc91e3478eaae79a69fcd3f1ae4ad052e471fe6732fff548984b4af" +checksum = "8f6fa277c67e6ea590466f04c3fe82cb509f0864fe470643e5570de9514a9b11" dependencies = [ "chacha20", "getrandom", @@ -1439,19 +1428,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aacc4cc499359472b4abe1bf11d0b12e688af9a805fa5e3016f9a386dc2d0214" dependencies = [ "cfg-if", - "cpufeatures 0.3.1", - "digest 0.11.3", -] - -[[package]] -name = "sha2" -version = "0.10.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" -dependencies = [ - "cfg-if", - "cpufeatures 0.2.17", - "digest 0.10.7", + "cpufeatures", + "digest", ] [[package]] @@ -1461,8 +1439,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "47d7069beb7d6ac7b9acd1039986e73443f24234f41074da099d6f994ac9ad19" dependencies = [ "cfg-if", - "cpufeatures 0.3.1", - "digest 0.11.3", + "cpufeatures", + "digest", ] [[package]] @@ -1482,8 +1460,8 @@ checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba" [[package]] name = "sienvy" -version = "0.8.3" -source = "git+ssh://git@git.kundeng.us/phoenix/sienvy.git?tag=v0.8.3#71544fd2e8d217eac5fc51b14bb062c302465718" +version = "0.8.4" +source = "git+ssh://git@git.kundeng.us/phoenix/sienvy.git?tag=v0.8.4#8c2ae68be954a7fb197de89b42c0f838ca381843" dependencies = [ "const_format", "dotenvy", @@ -1497,8 +1475,8 @@ checksum = "3a219298ac11a56ea9a6d2120044824d6f01aeb034955e7af7bc16858527deea" [[package]] name = "simodels" -version = "0.11.9" -source = "git+ssh://git@git.kundeng.us/phoenix/simodels.git?tag=v0.11.9#8e91af657e2e1f124bbba9547ee7e6936f6bb249" +version = "0.11.20" +source = "git+ssh://git@git.kundeng.us/phoenix/simodels.git?tag=v0.11.20#6ec7c4e21240de90e5222be5921e9e596ebf7ef8" dependencies = [ "josekit", "rand", @@ -1526,7 +1504,7 @@ dependencies = [ [[package]] name = "soaricarus_auth" -version = "0.8.9" +version = "0.8.10" dependencies = [ "argon2", "axum", @@ -1571,9 +1549,9 @@ dependencies = [ [[package]] name = "sqlx" -version = "0.9.0" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "378620ccc25c62c89d8be1c819e76a88d59bdcc3304733330788948e619bfd71" +checksum = "edb1dddfbdfe5fb99dba0541a87b2edb8adbd59e45815db22d32d4fbbb8813dd" dependencies = [ "sqlx-core", "sqlx-macros", @@ -1584,9 +1562,9 @@ dependencies = [ [[package]] name = "sqlx-core" -version = "0.9.0" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05b44e85bf579a8eeb4ceaa77a3a523baf2bf0e9bac7e40f405d537b5d2d5ccb" +checksum = "c08f9787cc5aff062567dea2205f8ae37a617b04342633ab4f74944858ea6072" dependencies = [ "base64 0.22.1", "bytes", @@ -1608,7 +1586,7 @@ dependencies = [ "percent-encoding", "serde", "serde_json", - "sha2 0.10.9", + "sha2", "smallvec", "thiserror", "time", @@ -1621,9 +1599,9 @@ dependencies = [ [[package]] name = "sqlx-macros" -version = "0.9.0" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd2b84f2bc39a5705ef27ec785a11c934a41bbd4a24941e257927cddc26b60bf" +checksum = "bf62c58a1e7fd6031ee684eee21d07572f5aebe71c273a01ae4f04eeeba47c47" dependencies = [ "proc-macro2", "quote", @@ -1634,9 +1612,9 @@ dependencies = [ [[package]] name = "sqlx-macros-core" -version = "0.9.0" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb8d96de5fdc85a5c4ec813432b523ec637e80ba98f046555f75f7908ddac7c3" +checksum = "c1ff75c9d609ac84aa8a3e0d92b5c0c54bf541a7f70db492fb40c9a4bea792c8" dependencies = [ "cfg-if", "dotenvy", @@ -1647,7 +1625,7 @@ dependencies = [ "quote", "serde", "serde_json", - "sha2 0.10.9", + "sha2", "sqlx-core", "sqlx-mysql", "sqlx-postgres", @@ -1660,15 +1638,15 @@ dependencies = [ [[package]] name = "sqlx-mysql" -version = "0.9.0" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90b8020fe17c5f2c245bfa2505d7ef59c5604839527c740266ad2214acebea27" +checksum = "19eeb93b96eb10a3a59dfb436f3daf87d2fc41168ed9e9dc153ec8257dd6a761" dependencies = [ "bitflags", "byteorder", "bytes", "crc", - "digest 0.11.3", + "digest", "dotenvy", "either", "futures-core", @@ -1678,7 +1656,7 @@ dependencies = [ "percent-encoding", "serde", "sha1", - "sha2 0.11.1", + "sha2", "sqlx-core", "thiserror", "time", @@ -1688,9 +1666,9 @@ dependencies = [ [[package]] name = "sqlx-postgres" -version = "0.9.0" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87a2bdd6e83f6b3ea525ca9fee568030508b58355a43d0b2c1674d5f79dcd65e" +checksum = "b0e9e02f764a1fe640eeefc8eb33eeddd274204654ec9f2db8ff851a1dee2364" dependencies = [ "atoi", "base64 0.22.1", @@ -1712,7 +1690,7 @@ dependencies = [ "rand", "serde", "serde_json", - "sha2 0.11.1", + "sha2", "smallvec", "sqlx-core", "stringprep", @@ -1725,9 +1703,9 @@ dependencies = [ [[package]] name = "sqlx-sqlite" -version = "0.9.0" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "488e99c397a62007e4229aec669a179816339afc6d2620ca6fa420dbee2e982c" +checksum = "88b6b78a34ddcb1db4046d462db8f79cee811019d7297b99fca8fac5de26672e" dependencies = [ "atoi", "flume", @@ -2170,9 +2148,9 @@ dependencies = [ [[package]] name = "uuid" -version = "1.29.0" +version = "1.29.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a0e2d11620c50695fe12bbbfde96b3477fe606e7284c22d505c12ce51214514" +checksum = "3c14b15dffa2f4bd712103e857140aa04a4f2ff6e955c77d7eb8e53ee02a3b64" dependencies = [ "getrandom", "js-sys", @@ -2248,11 +2226,27 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "web-sys" +version = "0.3.107" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7d179596ff5ec0f6de4db64d54011bde6289cc49603d3a6e4ce3f329207ab88" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + [[package]] name = "whoami" version = "2.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "626c4bac6755d76ffc12cb01b2eac751db1996b9e0041de9aa02c8c211ddc82c" +dependencies = [ + "libc", + "libredox", + "objc2-system-configuration", + "web-sys", +] [[package]] name = "windows-link" diff --git a/Cargo.toml b/Cargo.toml index cd1fb3e..ad433c3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "soaricarus_auth" -version = "0.8.9" +version = "0.8.10" edition = "2024" rust-version = "1.95" license = "MIT" @@ -15,16 +15,16 @@ tokio = { version = "1.54.1", features = ["rt-multi-thread"] } tracing-subscriber = { version = "0.3.23" } tower = { version = "0.5.3", features = ["full"] } tower-http = { version = "0.7.1", features = ["cors"] } -sqlx = { version = "0.9.0", features = ["postgres", "runtime-tokio", "tls-native-tls", "time", "uuid"] } -uuid = { version = "1.29.0", features = ["v4", "serde"] } +sqlx = { version = "0.9.1", features = ["postgres", "runtime-tokio", "tls-native-tls", "time", "uuid"] } +uuid = { version = "1.29.3", features = ["v4", "serde"] } argon2 = { version = "0.6.0", features = ["alloc", "getrandom", "rand_core"] } time = { version = "0.3.55", features = ["macros", "serde"] } josekit = { version = "0.10.3" } utoipa = { version = "6.0.0", features = ["axum_extras", "uuid", "time"] } utoipa-swagger-ui = { version = "10.0.2", features = ["axum"] } -rand = { version = "0.10.3" } -simodels = { git = "ssh://git@git.kundeng.us/phoenix/simodels.git", tag = "v0.11.9", features = ["auth"] } -sienvy = { git = "ssh://git@git.kundeng.us/phoenix/sienvy.git", tag = "v0.8.3" } +rand = { version = "0.10.4" } +simodels = { git = "ssh://git@git.kundeng.us/phoenix/simodels.git", tag = "v0.11.20", features = ["auth"] } +sienvy = { git = "ssh://git@git.kundeng.us/phoenix/sienvy.git", tag = "v0.8.4" } [dev-dependencies] http-body-util = { version = "0.1.5" } diff --git a/Dockerfile b/Dockerfile index a116cc7..02ad434 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM rust:1.99 as builder +FROM rust:1.99.1 as builder # Set the working directory inside the container WORKDIR /usr/src/app @@ -22,7 +22,6 @@ RUN --mount=type=ssh mkdir src && \ rm -rf src target/release/deps/soaricarus_auth* COPY src ./src -# If you have other directories like `templates` or `static`, copy them too COPY .env ./.env COPY migrations ./migrations @@ -31,22 +30,16 @@ RUN --mount=type=ssh \ FROM debian:trixie-slim -# Install runtime dependencies if needed (e.g., SSL certificates) RUN apt-get update && apt-get install -y ca-certificates libssl-dev libssl3 && rm -rf /var/lib/apt/lists/* -# Set the working directory WORKDIR /usr/local/bin # Copy the compiled binary from the builder stage COPY --from=builder /usr/src/app/target/release/soaricarus_auth . -# Copy other necessary files like .env (if used for runtime config) or static assets -# It's generally better to configure via environment variables in Docker though COPY --from=builder /usr/src/app/.env . COPY --from=builder /usr/src/app/migrations ./migrations EXPOSE 8001 -# Set the command to run your application -# Ensure this matches the binary name copied above CMD ["./soaricarus_auth"] diff --git a/src/callers/register.rs b/src/callers/register.rs index 6adba69..d215c8b 100644 --- a/src/callers/register.rs +++ b/src/callers/register.rs @@ -29,7 +29,7 @@ pub mod response { #[derive(Deserialize, Serialize, utoipa::ToSchema)] pub struct Response { pub message: String, - pub data: Vec, + pub data: Vec, } } @@ -59,7 +59,7 @@ pub async fn register_user( return ( axum::http::StatusCode::INTERNAL_SERVER_ERROR, Json(response::Response { - message: String::from("Registration check failed"), + message: "Registration check failed".to_string(), data: Vec::new(), }), ); @@ -67,19 +67,7 @@ pub async fn register_user( }; if registration_enabled { - let mut user = simodels::user::User { - username: payload.username.clone(), - password: payload.password.clone(), - email: payload.email.clone(), - phone: payload.phone.clone(), - firstname: payload.firstname.clone(), - lastname: payload.lastname.clone(), - status: String::from("Active"), - email_verified: true, - ..Default::default() - }; - - match repo::user::exists(&pool, &user.username).await { + match repo::user::exists(&pool, &payload.username).await { Ok(res) => { if res { ( @@ -95,20 +83,37 @@ pub async fn register_user( let generated_salt = salt_string; salt.salt = generated_salt.to_string().clone(); salt.id = repo::salt::insert(&pool, &salt).await.unwrap(); - user.salt_id = salt.id; let hashed_password = - hashing::hash_password(&user.password, &generated_salt).unwrap(); - user.password = hashed_password; + hashing::hash_password(&payload.password, &generated_salt).unwrap(); + let user = simodels::user::User { + username: payload.username, + password: hashed_password, + email: payload.email, + phone: payload.phone, + firstname: payload.firstname, + lastname: payload.lastname, + status: "Active".to_string(), + salt_id: salt.id, + email_verified: true, + ..Default::default() + }; match repo::user::insert(&pool, &user).await { Ok((id, date_created)) => { - user.id = id; - user.date_created = date_created; + let user_id = id; + let register_user = simodels::register_result::RegisterResult { + id: user_id, + username: user.username, + email: user.email, + firstname: user.firstname, + lastname: user.lastname, + date_created, + }; ( StatusCode::CREATED, Json(response::Response { - message: String::from("User created"), - data: vec![user], + message: "User created".to_string(), + data: vec![register_user], }), ) } @@ -116,7 +121,7 @@ pub async fn register_user( StatusCode::BAD_REQUEST, Json(response::Response { message: err.to_string(), - data: vec![user], + data: vec![], }), ), } @@ -126,7 +131,7 @@ pub async fn register_user( StatusCode::BAD_REQUEST, Json(response::Response { message: err.to_string(), - data: vec![user], + data: vec![], }), ), }