Compare commits

..
2 Commits
Author SHA1 Message Date
phoenix 868f533395 tsk-16: Change response of Register endpoint (#17)
soaricarus_auth Build / Rustfmt (push) Successful in 1m18s
Release Tagging / release (push) Successful in 1m31s
soaricarus_auth Build / Check (push) Successful in 1m34s
soaricarus_auth Build / Clippy (push) Successful in 1m41s
soaricarus_auth Build / Test Suite (push) Successful in 1m46s
soaricarus_auth Build / build (push) Successful in 1m57s
Closes #16

Reviewed-on: #17
2026-11-19 13:02:01 -05:00
phoenix e82a62dec4 tsk-14: Update user profile (#15)
Release Tagging / release (push) Successful in 16s
soaricarus_auth Build / build (push) Successful in 1m5s
soaricarus_auth Build / Rustfmt (push) Successful in 1m10s
soaricarus_auth Build / Check (push) Successful in 1m16s
soaricarus_auth Build / Clippy (push) Successful in 1m19s
soaricarus_auth Build / Test Suite (push) Successful in 1m19s
soaricarus_auth Build / Test Suite (pull_request) Successful in 1m11s
soaricarus_auth Build / Rustfmt (pull_request) Successful in 1m13s
soaricarus_auth Build / Clippy (pull_request) Successful in 1m13s
soaricarus_auth Build / Check (pull_request) Successful in 1m15s
soaricarus_auth Build / build (pull_request) Successful in 1m20s
Closes #14

Reviewed-on: http://git.kundeng.us/phoenix/soaricarus_auth/pulls/15
2026-11-11 13:13:49 -05:00
11 changed files with 550 additions and 286 deletions

No files matched your search

+2 -2
View File
@@ -7,7 +7,7 @@ on:
jobs: jobs:
release: release:
runs-on: ubuntu-24.04 runs-on: ubuntu-26.04
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v6 uses: actions/checkout@v6
@@ -17,7 +17,7 @@ jobs:
- name: Install Rust - name: Install Rust
uses: actions-rs/toolchain@v1 uses: actions-rs/toolchain@v1
with: with:
toolchain: 1.99 toolchain: 1.99.1
components: cargo components: cargo
- uses: Swatinem/rust-cache@v2 - uses: Swatinem/rust-cache@v2
+12 -12
View File
@@ -3,20 +3,20 @@ name: soaricarus_auth Build
on: on:
push: push:
branches: branches:
- main - main
pull_request: pull_request:
branches: branches:
- main - main
jobs: jobs:
check: check:
name: Check name: Check
runs-on: ubuntu-24.04 runs-on: ubuntu-26.04
steps: steps:
- uses: actions/checkout@v6 - uses: actions/checkout@v6
- uses: actions-rust-lang/setup-rust-toolchain@v1 - uses: actions-rust-lang/setup-rust-toolchain@v1
with: with:
toolchain: 1.99 toolchain: 1.99.1
- uses: Swatinem/rust-cache@v2 - uses: Swatinem/rust-cache@v2
- run: | - run: |
mkdir -p ~/.ssh mkdir -p ~/.ssh
@@ -31,7 +31,7 @@ jobs:
test: test:
name: Test Suite name: Test Suite
runs-on: ubuntu-24.04 runs-on: ubuntu-26.04
services: services:
postgres: postgres:
image: postgres:18.6-alpine image: postgres:18.6-alpine
@@ -49,7 +49,7 @@ jobs:
- uses: actions/checkout@v6 - uses: actions/checkout@v6
- uses: actions-rust-lang/setup-rust-toolchain@v1 - uses: actions-rust-lang/setup-rust-toolchain@v1
with: with:
toolchain: 1.99 toolchain: 1.99.1
- uses: Swatinem/rust-cache@v2 - uses: Swatinem/rust-cache@v2
- name: Verify Docker Environment - name: Verify Docker Environment
run: | run: |
@@ -83,12 +83,12 @@ jobs:
fmt: fmt:
name: Rustfmt name: Rustfmt
runs-on: ubuntu-24.04 runs-on: ubuntu-26.04
steps: steps:
- uses: actions/checkout@v6 - uses: actions/checkout@v6
- uses: actions-rust-lang/setup-rust-toolchain@v1 - uses: actions-rust-lang/setup-rust-toolchain@v1
with: with:
toolchain: 1.99 toolchain: 1.99.1
- uses: Swatinem/rust-cache@v2 - uses: Swatinem/rust-cache@v2
- run: rustup component add rustfmt - run: rustup component add rustfmt
- run: | - run: |
@@ -103,12 +103,12 @@ jobs:
clippy: clippy:
name: Clippy name: Clippy
runs-on: ubuntu-24.04 runs-on: ubuntu-26.04
steps: steps:
- uses: actions/checkout@v6 - uses: actions/checkout@v6
- uses: actions-rust-lang/setup-rust-toolchain@v1 - uses: actions-rust-lang/setup-rust-toolchain@v1
with: with:
toolchain: 1.99 toolchain: 1.99.1
- uses: Swatinem/rust-cache@v2 - uses: Swatinem/rust-cache@v2
- run: rustup component add clippy - run: rustup component add clippy
- run: | - run: |
@@ -123,12 +123,12 @@ jobs:
build: build:
name: build name: build
runs-on: ubuntu-24.04 runs-on: ubuntu-26.04
steps: steps:
- uses: actions/checkout@v6 - uses: actions/checkout@v6
- uses: actions-rust-lang/setup-rust-toolchain@v1 - uses: actions-rust-lang/setup-rust-toolchain@v1
with: with:
toolchain: 1.99 toolchain: 1.99.1
- uses: Swatinem/rust-cache@v2 - uses: Swatinem/rust-cache@v2
- run: | - run: |
mkdir -p ~/.ssh mkdir -p ~/.ssh
Generated
+82 -88
View File
@@ -37,7 +37,7 @@ checksum = "134c52ddac6d63c576bef8168db10c83c49c26444ecbc68060fef078925a901c"
dependencies = [ dependencies = [
"base64ct", "base64ct",
"blake2", "blake2",
"cpufeatures 0.3.1", "cpufeatures",
"password-hash", "password-hash",
] ]
@@ -147,16 +147,7 @@ version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b5d4d889834ee8ecfc0f8426ad30faf7cdcb10f741a8e6d7224d95325479f6f" checksum = "5b5d4d889834ee8ecfc0f8426ad30faf7cdcb10f741a8e6d7224d95325479f6f"
dependencies = [ dependencies = [
"digest 0.11.3", "digest",
]
[[package]]
name = "block-buffer"
version = "0.10.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71"
dependencies = [
"generic-array",
] ]
[[package]] [[package]]
@@ -215,7 +206,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "65c35e4b699c7e15ccbe7ee35c005e4fc0a278d22238a2857e6ce2dadeda1b06" checksum = "65c35e4b699c7e15ccbe7ee35c005e4fc0a278d22238a2857e6ce2dadeda1b06"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"cpufeatures 0.3.1", "cpufeatures",
"rand_core", "rand_core",
] ]
@@ -262,15 +253,6 @@ version = "0.8.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"
[[package]]
name = "cpufeatures"
version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280"
dependencies = [
"libc",
]
[[package]] [[package]]
name = "cpufeatures" name = "cpufeatures"
version = "0.3.1" version = "0.3.1"
@@ -319,16 +301,6 @@ version = "0.8.23"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a31eee39dddec8330830986fcd7625edb5a24ec90ea038215273bbc3adb08ac6" 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]] [[package]]
name = "crypto-common" name = "crypto-common"
version = "0.2.2" version = "0.2.2"
@@ -356,24 +328,14 @@ dependencies = [
"serde_core", "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]] [[package]]
name = "digest" name = "digest"
version = "0.11.3" version = "0.11.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1dd6dbb5841937940781866fa1281a1ff7bd3bf827091440879f9994983d5c2" checksum = "f1dd6dbb5841937940781866fa1281a1ff7bd3bf827091440879f9994983d5c2"
dependencies = [ dependencies = [
"block-buffer 0.12.1", "block-buffer",
"crypto-common 0.2.2", "crypto-common",
"ctutils", "ctutils",
] ]
@@ -661,7 +623,7 @@ version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6303bc9732ae41b04cb554b844a762b4115a61bfaa81e3e83050991eeb56863f" checksum = "6303bc9732ae41b04cb554b844a762b4115a61bfaa81e3e83050991eeb56863f"
dependencies = [ dependencies = [
"digest 0.11.3", "digest",
] ]
[[package]] [[package]]
@@ -929,6 +891,15 @@ version = "0.2.191"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a" checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a"
[[package]]
name = "libredox"
version = "0.1.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "61ff90caf6077a803a240f62fdbe88645a890bbca49ef8174c3cb0404362171d"
dependencies = [
"libc",
]
[[package]] [[package]]
name = "libsqlite3-sys" name = "libsqlite3-sys"
version = "0.37.0" version = "0.37.0"
@@ -979,7 +950,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "69b6441f590336821bb897fb28fc622898ccceb1d6cea3fde5ea86b090c4de98" checksum = "69b6441f590336821bb897fb28fc622898ccceb1d6cea3fde5ea86b090c4de98"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"digest 0.11.3", "digest",
] ]
[[package]] [[package]]
@@ -1078,6 +1049,24 @@ dependencies = [
"autocfg", "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]] [[package]]
name = "once_cell" name = "once_cell"
version = "1.21.4" version = "1.21.4"
@@ -1248,9 +1237,9 @@ checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf"
[[package]] [[package]]
name = "rand" name = "rand"
version = "0.10.3" version = "0.10.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "65c9fb96cbc91e3478eaae79a69fcd3f1ae4ad052e471fe6732fff548984b4af" checksum = "8f6fa277c67e6ea590466f04c3fe82cb509f0864fe470643e5570de9514a9b11"
dependencies = [ dependencies = [
"chacha20", "chacha20",
"getrandom", "getrandom",
@@ -1439,19 +1428,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aacc4cc499359472b4abe1bf11d0b12e688af9a805fa5e3016f9a386dc2d0214" checksum = "aacc4cc499359472b4abe1bf11d0b12e688af9a805fa5e3016f9a386dc2d0214"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"cpufeatures 0.3.1", "cpufeatures",
"digest 0.11.3", "digest",
]
[[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",
] ]
[[package]] [[package]]
@@ -1461,8 +1439,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "47d7069beb7d6ac7b9acd1039986e73443f24234f41074da099d6f994ac9ad19" checksum = "47d7069beb7d6ac7b9acd1039986e73443f24234f41074da099d6f994ac9ad19"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"cpufeatures 0.3.1", "cpufeatures",
"digest 0.11.3", "digest",
] ]
[[package]] [[package]]
@@ -1482,8 +1460,8 @@ checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba"
[[package]] [[package]]
name = "sienvy" name = "sienvy"
version = "0.8.3" version = "0.8.4"
source = "git+ssh://git@git.kundeng.us/phoenix/sienvy.git?tag=v0.8.3#71544fd2e8d217eac5fc51b14bb062c302465718" source = "git+ssh://git@git.kundeng.us/phoenix/sienvy.git?tag=v0.8.4#8c2ae68be954a7fb197de89b42c0f838ca381843"
dependencies = [ dependencies = [
"const_format", "const_format",
"dotenvy", "dotenvy",
@@ -1497,8 +1475,8 @@ checksum = "3a219298ac11a56ea9a6d2120044824d6f01aeb034955e7af7bc16858527deea"
[[package]] [[package]]
name = "simodels" name = "simodels"
version = "0.11.9" version = "0.11.20"
source = "git+ssh://git@git.kundeng.us/phoenix/simodels.git?tag=v0.11.9#8e91af657e2e1f124bbba9547ee7e6936f6bb249" source = "git+ssh://git@git.kundeng.us/phoenix/simodels.git?tag=v0.11.20#6ec7c4e21240de90e5222be5921e9e596ebf7ef8"
dependencies = [ dependencies = [
"josekit", "josekit",
"rand", "rand",
@@ -1526,7 +1504,7 @@ dependencies = [
[[package]] [[package]]
name = "soaricarus_auth" name = "soaricarus_auth"
version = "0.8.8" version = "0.8.10"
dependencies = [ dependencies = [
"argon2", "argon2",
"axum", "axum",
@@ -1571,9 +1549,9 @@ dependencies = [
[[package]] [[package]]
name = "sqlx" name = "sqlx"
version = "0.9.0" version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "378620ccc25c62c89d8be1c819e76a88d59bdcc3304733330788948e619bfd71" checksum = "edb1dddfbdfe5fb99dba0541a87b2edb8adbd59e45815db22d32d4fbbb8813dd"
dependencies = [ dependencies = [
"sqlx-core", "sqlx-core",
"sqlx-macros", "sqlx-macros",
@@ -1584,9 +1562,9 @@ dependencies = [
[[package]] [[package]]
name = "sqlx-core" name = "sqlx-core"
version = "0.9.0" version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "05b44e85bf579a8eeb4ceaa77a3a523baf2bf0e9bac7e40f405d537b5d2d5ccb" checksum = "c08f9787cc5aff062567dea2205f8ae37a617b04342633ab4f74944858ea6072"
dependencies = [ dependencies = [
"base64 0.22.1", "base64 0.22.1",
"bytes", "bytes",
@@ -1608,7 +1586,7 @@ dependencies = [
"percent-encoding", "percent-encoding",
"serde", "serde",
"serde_json", "serde_json",
"sha2 0.10.9", "sha2",
"smallvec", "smallvec",
"thiserror", "thiserror",
"time", "time",
@@ -1621,9 +1599,9 @@ dependencies = [
[[package]] [[package]]
name = "sqlx-macros" name = "sqlx-macros"
version = "0.9.0" version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd2b84f2bc39a5705ef27ec785a11c934a41bbd4a24941e257927cddc26b60bf" checksum = "bf62c58a1e7fd6031ee684eee21d07572f5aebe71c273a01ae4f04eeeba47c47"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@@ -1634,9 +1612,9 @@ dependencies = [
[[package]] [[package]]
name = "sqlx-macros-core" name = "sqlx-macros-core"
version = "0.9.0" version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fb8d96de5fdc85a5c4ec813432b523ec637e80ba98f046555f75f7908ddac7c3" checksum = "c1ff75c9d609ac84aa8a3e0d92b5c0c54bf541a7f70db492fb40c9a4bea792c8"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"dotenvy", "dotenvy",
@@ -1647,7 +1625,7 @@ dependencies = [
"quote", "quote",
"serde", "serde",
"serde_json", "serde_json",
"sha2 0.10.9", "sha2",
"sqlx-core", "sqlx-core",
"sqlx-mysql", "sqlx-mysql",
"sqlx-postgres", "sqlx-postgres",
@@ -1660,15 +1638,15 @@ dependencies = [
[[package]] [[package]]
name = "sqlx-mysql" name = "sqlx-mysql"
version = "0.9.0" version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "90b8020fe17c5f2c245bfa2505d7ef59c5604839527c740266ad2214acebea27" checksum = "19eeb93b96eb10a3a59dfb436f3daf87d2fc41168ed9e9dc153ec8257dd6a761"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"byteorder", "byteorder",
"bytes", "bytes",
"crc", "crc",
"digest 0.11.3", "digest",
"dotenvy", "dotenvy",
"either", "either",
"futures-core", "futures-core",
@@ -1678,7 +1656,7 @@ dependencies = [
"percent-encoding", "percent-encoding",
"serde", "serde",
"sha1", "sha1",
"sha2 0.11.1", "sha2",
"sqlx-core", "sqlx-core",
"thiserror", "thiserror",
"time", "time",
@@ -1688,9 +1666,9 @@ dependencies = [
[[package]] [[package]]
name = "sqlx-postgres" name = "sqlx-postgres"
version = "0.9.0" version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87a2bdd6e83f6b3ea525ca9fee568030508b58355a43d0b2c1674d5f79dcd65e" checksum = "b0e9e02f764a1fe640eeefc8eb33eeddd274204654ec9f2db8ff851a1dee2364"
dependencies = [ dependencies = [
"atoi", "atoi",
"base64 0.22.1", "base64 0.22.1",
@@ -1712,7 +1690,7 @@ dependencies = [
"rand", "rand",
"serde", "serde",
"serde_json", "serde_json",
"sha2 0.11.1", "sha2",
"smallvec", "smallvec",
"sqlx-core", "sqlx-core",
"stringprep", "stringprep",
@@ -1725,9 +1703,9 @@ dependencies = [
[[package]] [[package]]
name = "sqlx-sqlite" name = "sqlx-sqlite"
version = "0.9.0" version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "488e99c397a62007e4229aec669a179816339afc6d2620ca6fa420dbee2e982c" checksum = "88b6b78a34ddcb1db4046d462db8f79cee811019d7297b99fca8fac5de26672e"
dependencies = [ dependencies = [
"atoi", "atoi",
"flume", "flume",
@@ -2170,9 +2148,9 @@ dependencies = [
[[package]] [[package]]
name = "uuid" name = "uuid"
version = "1.29.0" version = "1.29.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4a0e2d11620c50695fe12bbbfde96b3477fe606e7284c22d505c12ce51214514" checksum = "3c14b15dffa2f4bd712103e857140aa04a4f2ff6e955c77d7eb8e53ee02a3b64"
dependencies = [ dependencies = [
"getrandom", "getrandom",
"js-sys", "js-sys",
@@ -2248,11 +2226,27 @@ dependencies = [
"unicode-ident", "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]] [[package]]
name = "whoami" name = "whoami"
version = "2.1.3" version = "2.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "626c4bac6755d76ffc12cb01b2eac751db1996b9e0041de9aa02c8c211ddc82c" checksum = "626c4bac6755d76ffc12cb01b2eac751db1996b9e0041de9aa02c8c211ddc82c"
dependencies = [
"libc",
"libredox",
"objc2-system-configuration",
"web-sys",
]
[[package]] [[package]]
name = "windows-link" name = "windows-link"
+6 -6
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "soaricarus_auth" name = "soaricarus_auth"
version = "0.8.8" version = "0.8.10"
edition = "2024" edition = "2024"
rust-version = "1.95" rust-version = "1.95"
license = "MIT" license = "MIT"
@@ -15,16 +15,16 @@ tokio = { version = "1.54.1", features = ["rt-multi-thread"] }
tracing-subscriber = { version = "0.3.23" } tracing-subscriber = { version = "0.3.23" }
tower = { version = "0.5.3", features = ["full"] } tower = { version = "0.5.3", features = ["full"] }
tower-http = { version = "0.7.1", features = ["cors"] } tower-http = { version = "0.7.1", features = ["cors"] }
sqlx = { version = "0.9.0", features = ["postgres", "runtime-tokio", "tls-native-tls", "time", "uuid"] } sqlx = { version = "0.9.1", features = ["postgres", "runtime-tokio", "tls-native-tls", "time", "uuid"] }
uuid = { version = "1.29.0", features = ["v4", "serde"] } uuid = { version = "1.29.3", features = ["v4", "serde"] }
argon2 = { version = "0.6.0", features = ["alloc", "getrandom", "rand_core"] } argon2 = { version = "0.6.0", features = ["alloc", "getrandom", "rand_core"] }
time = { version = "0.3.55", features = ["macros", "serde"] } time = { version = "0.3.55", features = ["macros", "serde"] }
josekit = { version = "0.10.3" } josekit = { version = "0.10.3" }
utoipa = { version = "6.0.0", features = ["axum_extras", "uuid", "time"] } utoipa = { version = "6.0.0", features = ["axum_extras", "uuid", "time"] }
utoipa-swagger-ui = { version = "10.0.2", features = ["axum"] } utoipa-swagger-ui = { version = "10.0.2", features = ["axum"] }
rand = { version = "0.10.3" } rand = { version = "0.10.4" }
simodels = { git = "ssh://git@git.kundeng.us/phoenix/simodels.git", tag = "v0.11.9", features = ["auth"] } 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.3" } sienvy = { git = "ssh://git@git.kundeng.us/phoenix/sienvy.git", tag = "v0.8.4" }
[dev-dependencies] [dev-dependencies]
http-body-util = { version = "0.1.5" } http-body-util = { version = "0.1.5" }
+1 -8
View File
@@ -1,4 +1,4 @@
FROM rust:1.99 as builder FROM rust:1.99.1 as builder
# Set the working directory inside the container # Set the working directory inside the container
WORKDIR /usr/src/app WORKDIR /usr/src/app
@@ -22,7 +22,6 @@ RUN --mount=type=ssh mkdir src && \
rm -rf src target/release/deps/soaricarus_auth* rm -rf src target/release/deps/soaricarus_auth*
COPY src ./src COPY src ./src
# If you have other directories like `templates` or `static`, copy them too
COPY .env ./.env COPY .env ./.env
COPY migrations ./migrations COPY migrations ./migrations
@@ -31,22 +30,16 @@ RUN --mount=type=ssh \
FROM debian:trixie-slim 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/* 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 WORKDIR /usr/local/bin
# Copy the compiled binary from the builder stage # Copy the compiled binary from the builder stage
COPY --from=builder /usr/src/app/target/release/soaricarus_auth . 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/.env .
COPY --from=builder /usr/src/app/migrations ./migrations COPY --from=builder /usr/src/app/migrations ./migrations
EXPOSE 8001 EXPOSE 8001
# Set the command to run your application
# Ensure this matches the binary name copied above
CMD ["./soaricarus_auth"] CMD ["./soaricarus_auth"]
+104
View File
@@ -43,6 +43,23 @@ pub mod request {
} }
} }
} }
pub mod update_user_profile {
use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, Serialize, utoipa::ToSchema)]
pub struct UpdateUserProfileRequest {
pub user_id: uuid::Uuid,
pub firstname: String,
pub lastname: String,
}
impl UpdateUserProfileRequest {
pub fn is_valid(&self) -> bool {
!self.user_id.is_nil() && !self.firstname.is_empty() && !self.lastname.is_empty()
}
}
}
} }
pub mod response { pub mod response {
@@ -89,6 +106,16 @@ pub mod response {
pub data: Vec<simodels::user::UserProfile>, pub data: Vec<simodels::user::UserProfile>,
} }
} }
pub mod update_user_profile {
use serde::{Deserialize, Serialize};
#[derive(Default, Deserialize, Serialize, utoipa::ToSchema)]
pub struct UpdateUserProfileResponse {
pub message: String,
pub data: Vec<simodels::user::UserProfile>,
}
}
} }
/// Module for login endpoints /// Module for login endpoints
@@ -446,4 +473,81 @@ pub mod endpoint {
} }
} }
} }
#[utoipa::path(
put,
path = super::super::endpoints::UPDATE_USER_PROFILE,
request_body(
content = super::request::update_user_profile::UpdateUserProfileRequest,
description = "Update user profile",
content_type = "application/json"
),
responses(
(status = 200, description = "User profile updated successfully", body = super::response::update_user_profile::UpdateUserProfileResponse),
(status = 400, description = "Invalid", body = super::response::update_user_profile::UpdateUserProfileResponse),
(status = 500, description = "Failure", body = super::response::update_user_profile::UpdateUserProfileResponse)
)
)]
pub async fn update_user_profile(
axum::Extension(pool): axum::Extension<sqlx::PgPool>,
axum::Json(payload): axum::Json<
super::request::update_user_profile::UpdateUserProfileRequest,
>,
) -> (
axum::http::StatusCode,
axum::Json<super::response::update_user_profile::UpdateUserProfileResponse>,
) {
let mut response =
super::response::update_user_profile::UpdateUserProfileResponse::default();
if !payload.is_valid() {
response.message = "Invalid".to_string();
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
} else {
let user_id = payload.user_id;
match repo::user::get_with_id(&pool, &user_id).await {
Ok(user) => {
let firstname = payload.firstname;
let lastname = payload.lastname;
if firstname == user.firstname && lastname == user.lastname {
(axum::http::StatusCode::NOT_MODIFIED, axum::Json(response))
} else {
match repo::user::update_user_profile(
&pool, &user_id, &firstname, &lastname,
)
.await
{
Ok(_) => {
let user_profile = simodels::user::UserProfile {
firstname,
lastname,
username: user.username,
email: user.email,
};
response.message = "SUCCESSFUL".to_string();
response.data.push(user_profile);
(axum::http::StatusCode::OK, axum::Json(response))
}
Err(err) => {
eprintln!("Error: {err:?}");
response.message = "ERROR - Updating user profile".to_string();
(
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
axum::Json(response),
)
}
}
}
}
Err(err) => {
eprintln!("Error: {err:?}");
response.message = "ERROR".to_string();
(
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
axum::Json(response),
)
}
}
}
}
} }
+1
View File
@@ -11,4 +11,5 @@ pub mod endpoints {
pub const SERVICE_LOGIN: &str = "/api/v2/service/login"; pub const SERVICE_LOGIN: &str = "/api/v2/service/login";
pub const REFRESH_TOKEN: &str = "/api/v2/token/refresh"; pub const REFRESH_TOKEN: &str = "/api/v2/token/refresh";
pub const GET_USER_PROFILE: &str = "/api/v2/user/profile/{id}"; pub const GET_USER_PROFILE: &str = "/api/v2/user/profile/{id}";
pub const UPDATE_USER_PROFILE: &str = "/api/v2/user/profile/update";
} }
+29 -24
View File
@@ -29,7 +29,7 @@ pub mod response {
#[derive(Deserialize, Serialize, utoipa::ToSchema)] #[derive(Deserialize, Serialize, utoipa::ToSchema)]
pub struct Response { pub struct Response {
pub message: String, pub message: String,
pub data: Vec<simodels::user::User>, pub data: Vec<simodels::register_result::RegisterResult>,
} }
} }
@@ -59,7 +59,7 @@ pub async fn register_user(
return ( return (
axum::http::StatusCode::INTERNAL_SERVER_ERROR, axum::http::StatusCode::INTERNAL_SERVER_ERROR,
Json(response::Response { Json(response::Response {
message: String::from("Registration check failed"), message: "Registration check failed".to_string(),
data: Vec::new(), data: Vec::new(),
}), }),
); );
@@ -67,19 +67,7 @@ pub async fn register_user(
}; };
if registration_enabled { if registration_enabled {
let mut user = simodels::user::User { match repo::user::exists(&pool, &payload.username).await {
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 {
Ok(res) => { Ok(res) => {
if res { if res {
( (
@@ -95,20 +83,37 @@ pub async fn register_user(
let generated_salt = salt_string; let generated_salt = salt_string;
salt.salt = generated_salt.to_string().clone(); salt.salt = generated_salt.to_string().clone();
salt.id = repo::salt::insert(&pool, &salt).await.unwrap(); salt.id = repo::salt::insert(&pool, &salt).await.unwrap();
user.salt_id = salt.id;
let hashed_password = let hashed_password =
hashing::hash_password(&user.password, &generated_salt).unwrap(); hashing::hash_password(&payload.password, &generated_salt).unwrap();
user.password = hashed_password; 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 { match repo::user::insert(&pool, &user).await {
Ok((id, date_created)) => { Ok((id, date_created)) => {
user.id = id; let user_id = id;
user.date_created = date_created; 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, StatusCode::CREATED,
Json(response::Response { Json(response::Response {
message: String::from("User created"), message: "User created".to_string(),
data: vec![user], data: vec![register_user],
}), }),
) )
} }
@@ -116,7 +121,7 @@ pub async fn register_user(
StatusCode::BAD_REQUEST, StatusCode::BAD_REQUEST,
Json(response::Response { Json(response::Response {
message: err.to_string(), message: err.to_string(),
data: vec![user], data: vec![],
}), }),
), ),
} }
@@ -126,7 +131,7 @@ pub async fn register_user(
StatusCode::BAD_REQUEST, StatusCode::BAD_REQUEST,
Json(response::Response { Json(response::Response {
message: err.to_string(), message: err.to_string(),
data: vec![user], data: vec![],
}), }),
), ),
} }
+144
View File
@@ -0,0 +1,144 @@
pub mod callers;
pub mod config;
pub mod db;
pub mod hashing;
pub mod repo;
pub mod token_stuff;
pub mod init {
use axum::{
Router,
routing::{get, patch, post, put},
};
use utoipa::OpenApi;
use super::callers;
use callers::common as common_callers;
use callers::login as login_caller;
use callers::register as register_caller;
use login_caller::endpoint as login_endpoints;
use login_caller::response as login_responses;
use register_caller::response as register_responses;
#[derive(utoipa::OpenApi)]
#[openapi(
paths(
common_callers::endpoint::db_ping, common_callers::endpoint::root,
register_caller::register_user,
login_endpoints::login, login_endpoints::update_password, login_endpoints::service_login, login_endpoints::refresh_token, login_endpoints::get_user_profile,
),
components(schemas(common_callers::response::TestResult,
register_responses::Response,
login_responses::Response, login_responses::service_login::Response, login_responses::update_password::Response, login_responses::refresh_token::Response, login_responses::get_user_profile::GetUserProfileResponse)),
tags(
(name = "soaricarus Auth API", description = "Auth API for soaricarus API")
)
)]
struct ApiDoc;
mod cors {
pub async fn configure_cors() -> tower_http::cors::CorsLayer {
let cors = tower_http::cors::CorsLayer::new()
.allow_methods([
axum::http::Method::GET,
axum::http::Method::PATCH,
axum::http::Method::POST,
axum::http::Method::PUT,
axum::http::Method::DELETE,
])
.allow_headers([
axum::http::header::CONTENT_TYPE,
axum::http::header::AUTHORIZATION,
])
.allow_credentials(true)
.max_age(std::time::Duration::from_secs(3600));
// Dynamically set the allowed origin based on the environment
match std::env::var(sienvy::keys::APP_ENV).as_deref() {
Ok("production") => {
let allowed_origins_env = sienvy::environment::get_allowed_origins();
match sienvy::utility::delimitize(&allowed_origins_env) {
Ok(alwd) => {
let allowed_origins: Vec<axum::http::HeaderValue> = alwd
.into_iter()
.map(|s| s.parse::<axum::http::HeaderValue>().unwrap())
.collect();
cors.allow_origin(allowed_origins)
}
Err(err) => {
eprintln!(
"Could not parse out allowed origins from env: Error: {err:?}"
);
std::process::exit(-1);
}
}
}
_ => {
// Development (default): Allow localhost origins
cors.allow_origin(vec![
"http://localhost:4200".parse().unwrap(),
"http://127.0.0.1:4200".parse().unwrap(),
])
}
}
}
}
pub async fn routes() -> Router {
// build our application with a route
Router::new()
.route(
callers::endpoints::DBTEST,
get(callers::common::endpoint::db_ping),
)
.route(
callers::endpoints::ROOT,
get(callers::common::endpoint::root),
)
.route(
callers::endpoints::REGISTER,
post(callers::register::register_user),
)
.route(
callers::endpoints::LOGIN,
post(callers::login::endpoint::login),
)
.route(
callers::endpoints::UPDATE_PASSWORD,
patch(callers::login::endpoint::update_password),
)
.route(
callers::endpoints::SERVICE_LOGIN,
post(callers::login::endpoint::service_login),
)
.route(
callers::endpoints::REFRESH_TOKEN,
post(callers::login::endpoint::refresh_token),
)
.route(
callers::endpoints::GET_USER_PROFILE,
get(callers::login::endpoint::get_user_profile),
)
.route(
callers::endpoints::UPDATE_USER_PROFILE,
put(callers::login::endpoint::update_user_profile),
)
.layer(cors::configure_cors().await)
}
pub async fn app() -> Router {
let pool = super::db::init::create_pool()
.await
.expect("Failed to create pool");
super::db::init::migrations(&pool).await;
routes()
.await
.merge(
utoipa_swagger_ui::SwaggerUi::new("/swagger-ui")
.url("/api-docs/openapi.json", ApiDoc::openapi()),
)
.layer(axum::Extension(pool))
}
}
+141 -146
View File
@@ -1,9 +1,4 @@
pub mod callers; use soaricarus_auth::{config, init};
pub mod config;
pub mod db;
pub mod hashing;
pub mod repo;
pub mod token_stuff;
#[tokio::main] #[tokio::main]
async fn main() { async fn main() {
@@ -18,143 +13,11 @@ async fn main() {
axum::serve(listener, app).await.unwrap(); axum::serve(listener, app).await.unwrap();
} }
mod init {
use axum::{
Router,
routing::{get, patch, post},
};
use utoipa::OpenApi;
use super::callers;
use callers::common as common_callers;
use callers::login as login_caller;
use callers::register as register_caller;
use login_caller::endpoint as login_endpoints;
use login_caller::response as login_responses;
use register_caller::response as register_responses;
#[derive(utoipa::OpenApi)]
#[openapi(
paths(
common_callers::endpoint::db_ping, common_callers::endpoint::root,
register_caller::register_user,
login_endpoints::login, login_endpoints::update_password, login_endpoints::service_login, login_endpoints::refresh_token, login_endpoints::get_user_profile,
),
components(schemas(common_callers::response::TestResult,
register_responses::Response,
login_responses::Response, login_responses::service_login::Response, login_responses::update_password::Response, login_responses::refresh_token::Response, login_responses::get_user_profile::GetUserProfileResponse)),
tags(
(name = "soaricarus Auth API", description = "Auth API for soaricarus API")
)
)]
struct ApiDoc;
mod cors {
pub async fn configure_cors() -> tower_http::cors::CorsLayer {
let cors = tower_http::cors::CorsLayer::new()
.allow_methods([
axum::http::Method::GET,
axum::http::Method::PATCH,
axum::http::Method::POST,
axum::http::Method::PUT,
axum::http::Method::DELETE,
])
.allow_headers([
axum::http::header::CONTENT_TYPE,
axum::http::header::AUTHORIZATION,
])
.allow_credentials(true)
.max_age(std::time::Duration::from_secs(3600));
// Dynamically set the allowed origin based on the environment
match std::env::var(sienvy::keys::APP_ENV).as_deref() {
Ok("production") => {
let allowed_origins_env = sienvy::environment::get_allowed_origins();
match sienvy::utility::delimitize(&allowed_origins_env) {
Ok(alwd) => {
let allowed_origins: Vec<axum::http::HeaderValue> = alwd
.into_iter()
.map(|s| s.parse::<axum::http::HeaderValue>().unwrap())
.collect();
cors.allow_origin(allowed_origins)
}
Err(err) => {
eprintln!(
"Could not parse out allowed origins from env: Error: {err:?}"
);
std::process::exit(-1);
}
}
}
_ => {
// Development (default): Allow localhost origins
cors.allow_origin(vec![
"http://localhost:4200".parse().unwrap(),
"http://127.0.0.1:4200".parse().unwrap(),
])
}
}
}
}
pub async fn routes() -> Router {
// build our application with a route
Router::new()
.route(
callers::endpoints::DBTEST,
get(callers::common::endpoint::db_ping),
)
.route(
callers::endpoints::ROOT,
get(callers::common::endpoint::root),
)
.route(
callers::endpoints::REGISTER,
post(callers::register::register_user),
)
.route(
callers::endpoints::LOGIN,
post(callers::login::endpoint::login),
)
.route(
callers::endpoints::UPDATE_PASSWORD,
patch(callers::login::endpoint::update_password),
)
.route(
callers::endpoints::SERVICE_LOGIN,
post(callers::login::endpoint::service_login),
)
.route(
callers::endpoints::REFRESH_TOKEN,
post(callers::login::endpoint::refresh_token),
)
.route(
callers::endpoints::GET_USER_PROFILE,
get(callers::login::endpoint::get_user_profile),
)
.layer(cors::configure_cors().await)
}
pub async fn app() -> Router {
let pool = super::db::init::create_pool()
.await
.expect("Failed to create pool");
super::db::init::migrations(&pool).await;
routes()
.await
.merge(
utoipa_swagger_ui::SwaggerUi::new("/swagger-ui")
.url("/api-docs/openapi.json", ApiDoc::openapi()),
)
.layer(axum::Extension(pool))
}
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use soaricarus_auth;
use soaricarus_auth::{callers, db};
use axum::{ use axum::{
body::Body, body::Body,
@@ -265,6 +128,9 @@ mod tests {
pub mod test_data { pub mod test_data {
use serde_json::json; use serde_json::json;
pub const UPDATED_FIRSTNAME: &str = "Bolt";
pub const UPDATED_LASTNAME: &str = "Thunder";
pub fn get_updated_password(user_id: &uuid::Uuid) -> serde_json::Value { pub fn get_updated_password(user_id: &uuid::Uuid) -> serde_json::Value {
json!({ json!({
"username": "somethingsss", "username": "somethingsss",
@@ -274,9 +140,22 @@ mod tests {
"confirmed_password": "SpeakWithUrChest22!" "confirmed_password": "SpeakWithUrChest22!"
}) })
} }
pub fn update_user_profile(
user_id: &uuid::Uuid,
firstname: &str,
lastname: &str,
) -> serde_json::Value {
json!({
"firstname": firstname,
"lastname": lastname,
"user_id": user_id
})
}
} }
pub mod requests { pub mod requests {
use soaricarus_auth::callers;
use tower::ServiceExt; // for `call`, `oneshot`, and `ready` use tower::ServiceExt; // for `call`, `oneshot`, and `ready`
pub async fn register( pub async fn register(
@@ -286,7 +165,7 @@ mod tests {
let payload = super::get_test_register_payload(&usr); let payload = super::get_test_register_payload(&usr);
let req = axum::http::Request::builder() let req = axum::http::Request::builder()
.method(axum::http::Method::POST) .method(axum::http::Method::POST)
.uri(crate::callers::endpoints::REGISTER) .uri(callers::endpoints::REGISTER)
.header(axum::http::header::CONTENT_TYPE, "application/json") .header(axum::http::header::CONTENT_TYPE, "application/json")
.body(axum::body::Body::from(payload.to_string())) .body(axum::body::Body::from(payload.to_string()))
.unwrap(); .unwrap();
@@ -301,7 +180,7 @@ mod tests {
let payload = super::get_test_login_payload(&usr); let payload = super::get_test_login_payload(&usr);
let req = axum::http::Request::builder() let req = axum::http::Request::builder()
.method(axum::http::Method::POST) .method(axum::http::Method::POST)
.uri(crate::callers::endpoints::LOGIN) .uri(callers::endpoints::LOGIN)
.header(axum::http::header::CONTENT_TYPE, "application/json") .header(axum::http::header::CONTENT_TYPE, "application/json")
.body(axum::body::Body::from(payload.to_string())) .body(axum::body::Body::from(payload.to_string()))
.unwrap(); .unwrap();
@@ -316,7 +195,7 @@ mod tests {
let payload = super::test_data::get_updated_password(user_id); let payload = super::test_data::get_updated_password(user_id);
let req = axum::http::Request::builder() let req = axum::http::Request::builder()
.method(axum::http::Method::PATCH) .method(axum::http::Method::PATCH)
.uri(crate::callers::endpoints::UPDATE_PASSWORD) .uri(callers::endpoints::UPDATE_PASSWORD)
.header(axum::http::header::CONTENT_TYPE, "application/json") .header(axum::http::header::CONTENT_TYPE, "application/json")
.body(axum::body::Body::from(payload.to_string())) .body(axum::body::Body::from(payload.to_string()))
.unwrap(); .unwrap();
@@ -328,7 +207,7 @@ mod tests {
app: &axum::Router, app: &axum::Router,
user_id: &uuid::Uuid, user_id: &uuid::Uuid,
) -> Result<axum::response::Response, std::convert::Infallible> { ) -> Result<axum::response::Response, std::convert::Infallible> {
let raw_uri = String::from(crate::callers::endpoints::GET_USER_PROFILE); let raw_uri = String::from(callers::endpoints::GET_USER_PROFILE);
let end_index = raw_uri.len() - 4; let end_index = raw_uri.len() - 4;
let uri = format!("{}{user_id}", (&raw_uri[..end_index]).to_string()); let uri = format!("{}{user_id}", (&raw_uri[..end_index]).to_string());
@@ -340,6 +219,28 @@ mod tests {
.unwrap(); .unwrap();
app.clone().oneshot(req).await app.clone().oneshot(req).await
} }
pub async fn update_user_profile(
app: &axum::Router,
user_id: &uuid::Uuid,
firstname: &str,
lastname: &str,
) -> Result<axum::response::Response, std::convert::Infallible> {
let payload = super::test_data::update_user_profile(user_id, firstname, lastname);
let req = axum::http::Request::builder()
.method(axum::http::Method::PUT)
.uri(callers::endpoints::UPDATE_USER_PROFILE)
.header(axum::http::header::CONTENT_TYPE, "application/json")
.body(axum::body::Body::from(payload.to_string()))
.unwrap();
app.clone().oneshot(req).await
}
}
pub mod responses {
pub use soaricarus_auth::callers::login::response as login_responses;
pub use soaricarus_auth::callers::register::response as register_responses;
} }
#[tokio::test] #[tokio::test]
@@ -575,7 +476,7 @@ mod tests {
let id = uuid::Uuid::parse_str("22f9c775-cce9-457a-a147-9dafbb801f61").unwrap(); let id = uuid::Uuid::parse_str("22f9c775-cce9-457a-a147-9dafbb801f61").unwrap();
let key = sienvy::environment::get_secret_key().value; let key = sienvy::environment::get_secret_key().value;
match token_stuff::create_service_token(&key, &id) { match soaricarus_auth::token_stuff::create_service_token(&key, &id) {
Ok((token, _expire)) => { Ok((token, _expire)) => {
let payload = serde_json::json!({ let payload = serde_json::json!({
"access_token": token "access_token": token
@@ -771,7 +672,8 @@ mod tests {
let body = axum::body::to_bytes(resp.into_body(), usize::MAX) let body = axum::body::to_bytes(resp.into_body(), usize::MAX)
.await .await
.unwrap(); .unwrap();
let parsed_body: callers::login::response::get_user_profile::GetUserProfileResponse =
let parsed_body: responses::login_responses::get_user_profile::GetUserProfileResponse =
serde_json::from_slice(&body).unwrap(); serde_json::from_slice(&body).unwrap();
let user_profile = &parsed_body.data[0]; let user_profile = &parsed_body.data[0];
assert!( assert!(
@@ -791,4 +693,97 @@ mod tests {
let _ = db_mgr::drop_database(&tm_pool, &db_name).await; let _ = db_mgr::drop_database(&tm_pool, &db_name).await;
} }
#[tokio::test]
async fn test_update_user_profile() {
let tm_pool = db_mgr::get_pool().await.unwrap();
let db_name = db_mgr::generate_db_name().await;
match db_mgr::create_database(&tm_pool, &db_name).await {
Ok(_) => {
println!("Success");
}
Err(e) => {
assert!(false, "Error: {:?}", e.to_string());
}
}
let pool = db_mgr::connect_to_db(&db_name).await.unwrap();
db::init::migrations(&pool).await;
let app = init::routes().await.layer(axum::Extension(pool));
let usr = get_test_register_request();
let response = requests::register(&app, &usr).await;
match response {
Ok(resp) => {
assert_eq!(
resp.status(),
StatusCode::CREATED,
"Message: {:?} {:?}",
resp,
usr.username
);
let body = axum::body::to_bytes(resp.into_body(), usize::MAX)
.await
.unwrap();
let parsed_body: responses::register_responses::Response =
serde_json::from_slice(&body).unwrap();
let returned_usr = &parsed_body.data[0];
let user_id = returned_usr.id;
assert_eq!(false, user_id.is_nil(), "Id is not populated");
assert_eq!(
usr.username, returned_usr.username,
"Usernames do not match"
);
assert!(returned_usr.date_created.is_some(), "Date Created is empty");
let updated_firstname = test_data::UPDATED_FIRSTNAME;
let updated_lastname = test_data::UPDATED_LASTNAME;
match requests::update_user_profile(
&app,
&user_id,
&updated_firstname,
&updated_lastname,
)
.await
{
Ok(resp) => {
assert_eq!(StatusCode::OK, resp.status(), "Status is not right");
let body = axum::body::to_bytes(resp.into_body(), usize::MAX)
.await
.unwrap();
let parsed_body: responses::login_responses::update_user_profile::UpdateUserProfileResponse =
serde_json::from_slice(&body).unwrap();
let user_profile = &parsed_body.data[0];
assert_eq!(
updated_firstname, user_profile.firstname,
"Firstname has not been updated"
);
assert_eq!(
updated_lastname, user_profile.lastname,
"Lastname has not been updated"
);
}
Err(err) => {
assert!(false, "Error: {:?}", err.to_string());
}
}
}
Err(err) => {
assert!(false, "Error: {:?}", err.to_string());
}
};
let _ = db_mgr::drop_database(&tm_pool, &db_name).await;
}
} }
+28
View File
@@ -132,6 +132,34 @@ pub mod user {
} }
} }
pub async fn update_user_profile(
pool: &sqlx::PgPool,
id: &uuid::Uuid,
firstname: &str,
lastname: &str,
) -> Result<bool, sqlx::Error> {
match sqlx::query(
r#"
UPDATE "user" SET firstname = $1, lastname = $2 WHERE id = $3
"#,
)
.bind(firstname)
.bind(lastname)
.bind(id)
.execute(pool)
.await
{
Ok(r) => {
if r.rows_affected() > 0 {
Ok(true)
} else {
Ok(false)
}
}
Err(err) => Err(err),
}
}
pub async fn update_last_login( pub async fn update_last_login(
pool: &sqlx::PgPool, pool: &sqlx::PgPool,
user: &simodels::user::User, user: &simodels::user::User,