From 314f12f5d9093c445c85c7d585ca41fd41992ed8 Mon Sep 17 00:00:00 2001 From: Hannes Klinckaert Date: Wed, 28 Aug 2024 16:17:13 +0200 Subject: [PATCH 01/31] vingo: yeet and rust login flow --- vingo/.air.toml | 51 -- vingo/.gitignore | 7 +- vingo/.tool-versions | 1 - vingo/Cargo.lock | 1560 +++++++++++++++++++++++++++++++++ vingo/Cargo.toml | 16 + vingo/Dockerfile.dev | 10 - vingo/README.md | 19 - vingo/database/cards.go | 38 - vingo/database/days.go | 46 - vingo/database/db.go | 41 - vingo/database/models.go | 81 -- vingo/database/scans.go | 127 --- vingo/database/seasons.go | 11 - vingo/database/settings.go | 26 - vingo/database/users.go | 26 - vingo/dev.env | 11 - vingo/go.mod | 38 - vingo/go.sum | 68 -- vingo/handlers/access.go | 19 - vingo/handlers/auth.go | 139 --- vingo/handlers/cards.go | 72 -- vingo/handlers/leaderboard.go | 33 - vingo/handlers/public.go | 18 - vingo/handlers/scans.go | 76 -- vingo/handlers/seasons.go | 36 - vingo/handlers/settings.go | 38 - vingo/handlers/store.go | 55 -- vingo/handlers/users.go | 9 - vingo/main.go | 155 ---- vingo/src/main.rs | 34 + vingo/src/routes/auth.rs | 101 +++ vingo/template.env | 11 - 32 files changed, 1716 insertions(+), 1257 deletions(-) delete mode 100644 vingo/.air.toml delete mode 100644 vingo/.tool-versions create mode 100644 vingo/Cargo.lock create mode 100644 vingo/Cargo.toml delete mode 100644 vingo/Dockerfile.dev delete mode 100644 vingo/README.md delete mode 100644 vingo/database/cards.go delete mode 100644 vingo/database/days.go delete mode 100644 vingo/database/db.go delete mode 100644 vingo/database/models.go delete mode 100644 vingo/database/scans.go delete mode 100644 vingo/database/seasons.go delete mode 100644 vingo/database/settings.go delete mode 100644 vingo/database/users.go delete mode 100644 vingo/dev.env delete mode 100644 vingo/go.mod delete mode 100644 vingo/go.sum delete mode 100644 vingo/handlers/access.go delete mode 100644 vingo/handlers/auth.go delete mode 100644 vingo/handlers/cards.go delete mode 100644 vingo/handlers/leaderboard.go delete mode 100644 vingo/handlers/public.go delete mode 100644 vingo/handlers/scans.go delete mode 100644 vingo/handlers/seasons.go delete mode 100644 vingo/handlers/settings.go delete mode 100644 vingo/handlers/store.go delete mode 100644 vingo/handlers/users.go delete mode 100644 vingo/main.go create mode 100644 vingo/src/main.rs create mode 100644 vingo/src/routes/auth.rs delete mode 100644 vingo/template.env diff --git a/vingo/.air.toml b/vingo/.air.toml deleted file mode 100644 index 58fff2a..0000000 --- a/vingo/.air.toml +++ /dev/null @@ -1,51 +0,0 @@ -root = "." -testdata_dir = "testdata" -tmp_dir = "tmp" - -[build] - args_bin = [] - bin = "./tmp/main" - cmd = "go build -o ./tmp/main ." - delay = 1000 - exclude_dir = ["assets", "tmp", "vendor", "testdata"] - exclude_file = [] - exclude_regex = ["_test.go"] - exclude_unchanged = false - follow_symlink = false - full_bin = "" - include_dir = [] - include_ext = ["go", "tpl", "tmpl", "html"] - include_file = [] - kill_delay = "0s" - log = "build-errors.log" - poll = false - poll_interval = 0 - post_cmd = [] - pre_cmd = [] - rerun = false - rerun_delay = 500 - send_interrupt = false - stop_on_error = false - -[color] - app = "" - build = "yellow" - main = "magenta" - runner = "green" - watcher = "cyan" - -[log] - main_only = false - time = false - -[misc] - clean_on_exit = false - -[proxy] - app_port = 0 - enabled = false - proxy_port = 0 - -[screen] - clear_on_rebuild = false - keep_scroll = true diff --git a/vingo/.gitignore b/vingo/.gitignore index a703a4a..563d32f 100644 --- a/vingo/.gitignore +++ b/vingo/.gitignore @@ -1,2 +1,5 @@ -.env -tmp/ +debug/ +target/ + +**/*.rs.bk +*.pdb \ No newline at end of file diff --git a/vingo/.tool-versions b/vingo/.tool-versions deleted file mode 100644 index 6bc74c5..0000000 --- a/vingo/.tool-versions +++ /dev/null @@ -1 +0,0 @@ -golang 1.22.1 diff --git a/vingo/Cargo.lock b/vingo/Cargo.lock new file mode 100644 index 0000000..11d2e7f --- /dev/null +++ b/vingo/Cargo.lock @@ -0,0 +1,1560 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "async-trait" +version = "0.1.81" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e0c28dcc82d7c8ead5cb13beb15405b57b8546e93215673ff8ca0349a028107" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "axum" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a6c9af12842a67734c9a2e355436e5d03b22383ed60cf13cd0c18fbfe3dcbcf" +dependencies = [ + "async-trait", + "axum-core", + "bytes", + "futures-util", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-util", + "itoa", + "matchit", + "memchr", + "mime", + "percent-encoding", + "pin-project-lite", + "rustversion", + "serde", + "serde_urlencoded", + "sync_wrapper 1.0.1", + "tokio", + "tower", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "axum-core" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a15c63fd72d41492dc4f497196f5da1fb04fb7529e631d73630d1b491e47a2e3" +dependencies = [ + "async-trait", + "bytes", + "futures-util", + "http", + "http-body", + "http-body-util", + "mime", + "pin-project-lite", + "rustversion", + "sync_wrapper 0.1.2", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "backtrace" +version = "0.3.73" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50" + +[[package]] +name = "cc" +version = "1.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57b6a275aa2903740dc87da01c62040406b8812552e97129a63ea8850a17c6e6" +dependencies = [ + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "cookie" +version = "0.18.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ddef33a339a91ea89fb53151bd0a4689cfce27055c291dfa69945475d22c747" +dependencies = [ + "percent-encoding", + "time", + "version_check", +] + +[[package]] +name = "deranged" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" +dependencies = [ + "powerfmt", + "serde", +] + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-core", + "futures-macro", + "futures-sink", + "futures-task", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "gimli" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "http" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http-body" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" +dependencies = [ + "bytes", + "http", +] + +[[package]] +name = "http-body-util" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" +dependencies = [ + "bytes", + "futures-util", + "http", + "http-body", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fcc0b4a115bf80b728eb8ea024ad5bd707b615bfed49e0665b6e0f86fd082d9" + +[[package]] +name = "httpdate" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" + +[[package]] +name = "hyper" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50dfd22e0e76d0f662d429a5f80fcaf3855009297eab6a0a9f8543834744ba05" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", +] + +[[package]] +name = "hyper-rustls" +version = "0.27.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ee4be2c948921a1a5320b629c4193916ed787a7f7f293fd3f7f5a6c9de74155" +dependencies = [ + "futures-util", + "http", + "hyper", + "hyper-util", + "rustls", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", + "webpki-roots", +] + +[[package]] +name = "hyper-util" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cde7055719c54e36e95e8719f95883f22072a48ede39db7fc17a4e1d5281e9b9" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "pin-project-lite", + "socket2", + "tokio", + "tower", + "tower-service", + "tracing", +] + +[[package]] +name = "idna" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "ipnet" +version = "2.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "js-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + +[[package]] +name = "libc" +version = "0.2.158" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", + "serde", +] + +[[package]] +name = "log" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "matchit" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e7465ac9959cc2b1404e8e2367b43684a6d13790fe23056cc8c6c5a6b7bcb94" + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "miniz_oxide" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80e04d1dcff3aae0704555fe5fee3bcfaf3d1fdf8a7e521d5b9d2b42acb52cec" +dependencies = [ + "hermit-abi", + "libc", + "wasi", + "windows-sys", +] + +[[package]] +name = "nu-ansi-term" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" +dependencies = [ + "overload", + "winapi", +] + +[[package]] +name = "num-conv" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" + +[[package]] +name = "object" +version = "0.36.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "27b64972346851a39438c60b341ebc01bba47464ae329e55cf343eb93964efd9" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "overload" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" + +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets", +] + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "pin-project" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6bf43b791c5b9e34c3d182969b4abb522f9343702850a2e57f460d00d09b4b3" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "proc-macro2" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quinn" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b22d8e7369034b9a7132bc2008cac12f2013c8132b45e0554e6e20e2617f2156" +dependencies = [ + "bytes", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror", + "tokio", + "tracing", +] + +[[package]] +name = "quinn-proto" +version = "0.11.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba92fb39ec7ad06ca2582c0ca834dfeadcaf06ddfc8e635c80aa7e1c05315fdd" +dependencies = [ + "bytes", + "rand", + "ring", + "rustc-hash", + "rustls", + "slab", + "thiserror", + "tinyvec", + "tracing", +] + +[[package]] +name = "quinn-udp" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bffec3605b73c6f1754535084a85229fa8a30f86014e6c81aeec4abb68b0285" +dependencies = [ + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "redox_syscall" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a908a6e00f1fdd0dfd9c0eb08ce85126f6d8bbda50017e74bc4a4b7d4a926a4" +dependencies = [ + "bitflags", +] + +[[package]] +name = "reqwest" +version = "0.12.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8f4955649ef5c38cc7f9e8aa41761d48fb9677197daea9984dc54f56aad5e63" +dependencies = [ + "base64", + "bytes", + "futures-core", + "futures-util", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-util", + "ipnet", + "js-sys", + "log", + "mime", + "once_cell", + "percent-encoding", + "pin-project-lite", + "quinn", + "rustls", + "rustls-pemfile", + "rustls-pki-types", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper 1.0.1", + "tokio", + "tokio-rustls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "webpki-roots", + "windows-registry", +] + +[[package]] +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "spin", + "untrusted", + "windows-sys", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "rustc-hash" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" + +[[package]] +name = "rustls" +version = "0.23.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a218f0f6d05669de4eabfb24f31ce802035c952429d037507b4a4a39f0e60c5b" +dependencies = [ + "once_cell", + "ring", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pemfile" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29993a25686778eb88d4189742cd713c9bce943bc54251a33509dc63cbacf73d" +dependencies = [ + "base64", + "rustls-pki-types", +] + +[[package]] +name = "rustls-pki-types" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "976295e77ce332211c0d24d92c0e83e50f5c5f046d11082cea19f3df13a3562d" + +[[package]] +name = "rustls-webpki" +version = "0.102.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff448f7e92e913c4b7d4c6d8e4540a1724b319b4152b8aef6d4cf8339712b33e" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "rustversion" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "955d28af4278de8121b7ebeb796b6a45735dc01436d898801014aced2773a3d6" + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "serde" +version = "1.0.209" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99fce0ffe7310761ca6bf9faf5115afbc19688edd00171d81b1bb1b116c63e09" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.209" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5831b979fd7b5439637af1752d535ff49f4860c0f341d1baeb6faf0f4242170" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.127" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8043c06d9f82bd7271361ed64f415fe5e12a77fdb52e573e7f06a516dea329ad" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sharded-slab" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.76" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "578e081a14e0cefc3279b0472138c513f37b41a08d5a3cca9b6e4e8ceb6cd525" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" + +[[package]] +name = "sync_wrapper" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +dependencies = [ + "futures-core", +] + +[[package]] +name = "thiserror" +version = "1.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "thread_local" +version = "1.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b9ef9bad013ada3808854ceac7b46812a6465ba368859a37e2100283d2d719c" +dependencies = [ + "cfg-if", + "once_cell", +] + +[[package]] +name = "time" +version = "0.3.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885" +dependencies = [ + "deranged", + "itoa", + "num-conv", + "powerfmt", + "serde", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" + +[[package]] +name = "time-macros" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f252a68540fde3a3877aeea552b832b40ab9a69e318efd078774a01ddee1ccf" +dependencies = [ + "num-conv", + "time-core", +] + +[[package]] +name = "tinyvec" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.39.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9babc99b9923bfa4804bd74722ff02c0381021eafa4db9949217e3be8e84fff5" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "pin-project-lite", + "socket2", + "tokio-macros", + "windows-sys", +] + +[[package]] +name = "tokio-macros" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" +dependencies = [ + "rustls", + "rustls-pki-types", + "tokio", +] + +[[package]] +name = "tower" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" +dependencies = [ + "futures-core", + "futures-util", + "pin-project", + "pin-project-lite", + "tokio", + "tower-layer", + "tower-service", +] + +[[package]] +name = "tower-cookies" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fd0118512cf0b3768f7fcccf0bef1ae41d68f2b45edc1e77432b36c97c56c6d" +dependencies = [ + "async-trait", + "axum-core", + "cookie", + "futures-util", + "http", + "parking_lot", + "pin-project-lite", + "tower-layer", + "tower-service", +] + +[[package]] +name = "tower-http" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e9cd434a998747dd2c4276bc96ee2e0c7a2eadf3cae88e52be55a05fa9053f5" +dependencies = [ + "bitflags", + "bytes", + "http", + "http-body", + "http-body-util", + "pin-project-lite", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "tower-layer" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tower-sessions" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50571505955aaa8b73f2f40489953d92b4d7ff9eb9b2a8b4e11fee0dcdb2760e" +dependencies = [ + "async-trait", + "http", + "time", + "tokio", + "tower-cookies", + "tower-layer", + "tower-service", + "tower-sessions-core", + "tower-sessions-memory-store", + "tracing", +] + +[[package]] +name = "tower-sessions-core" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6293bf33f1977d5ef422c2e02f909eb2c3d7bf921d93557c40d4f1b130b84aa4" +dependencies = [ + "async-trait", + "axum-core", + "base64", + "futures", + "http", + "parking_lot", + "rand", + "serde", + "serde_json", + "thiserror", + "time", + "tokio", + "tracing", +] + +[[package]] +name = "tower-sessions-memory-store" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cec5f88eeef0f036e6900217034efbce733cbdf0528a85204eaaed90bc34c354" +dependencies = [ + "async-trait", + "time", + "tokio", + "tower-sessions-core", +] + +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "log", + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", + "valuable", +] + +[[package]] +name = "tracing-log" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" +dependencies = [ + "log", + "once_cell", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b" +dependencies = [ + "nu-ansi-term", + "sharded-slab", + "smallvec", + "thread_local", + "tracing-core", + "tracing-log", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "unicode-bidi" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-normalization" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "valuable" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "vingo" +version = "0.1.0" +dependencies = [ + "axum", + "rand", + "reqwest", + "serde", + "tokio", + "tower-http", + "tower-sessions", + "tracing", + "tracing-subscriber", +] + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" +dependencies = [ + "cfg-if", + "once_cell", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e9300f63a621e96ed275155c108eb6f843b6a26d053f122ab69724559dc8ed" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" + +[[package]] +name = "web-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "webpki-roots" +version = "0.26.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c452ad30530b54a4d8e71952716a212b08efd0f3562baa66c29a618b07da7c3" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-registry" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e400001bb720a623c1c69032f8e3e4cf09984deec740f007dd2b03ec864804b0" +dependencies = [ + "windows-result", + "windows-strings", + "windows-targets", +] + +[[package]] +name = "windows-result" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-strings" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" +dependencies = [ + "windows-result", + "windows-targets", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/vingo/Cargo.toml b/vingo/Cargo.toml new file mode 100644 index 0000000..3a68e17 --- /dev/null +++ b/vingo/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "vingo" +version = "0.1.0" +edition = "2021" + +[dependencies] +axum = { version = "0.7.5", default-features = false, features = ["tokio", "http1", "tracing", "query" ] } +rand = { version = "0.8.5", default-features = false } +reqwest = { version = "0.12.7", default-features = false, features = [ "json", "rustls-tls" ] } +serde = { version = "1.0.209", default-features = false, features = ["derive"] } +tokio = { version = "1.39.3", default-features = false, features = ["rt-multi-thread", "macros", "net"] } +tower-http = { version = "0.5.2", default-features = false, features = ["trace"] } +tower-sessions = { version = "0.12.3", default-features = false, features = ["memory-store", "axum-core"] } + +tracing = "0.1.37" +tracing-subscriber = "0.3.16" diff --git a/vingo/Dockerfile.dev b/vingo/Dockerfile.dev deleted file mode 100644 index 94460f4..0000000 --- a/vingo/Dockerfile.dev +++ /dev/null @@ -1,10 +0,0 @@ -FROM golang:1.22.1-alpine3.19 - -WORKDIR /backend - -RUN go install github.com/air-verse/air@latest -COPY .air.toml . - -COPY go.mod go.sum ./ - -CMD go mod tidy && air -c .air.toml diff --git a/vingo/README.md b/vingo/README.md deleted file mode 100644 index cf1231e..0000000 --- a/vingo/README.md +++ /dev/null @@ -1,19 +0,0 @@ -# Vingo - -The webserver that keeps track of the scans :D - -Register a scan by posting `card_serial;scan_key` to the `/scans` endpoint. -`scan_key` is a pre-shared key with the scanner (vinscant) so only the scanner can register a scan. - -To register a card, click the "Start registering a new card" button in the cards view, after which the server will register the next scanned card for the user that initiated the request. Only 1 user can register a card at a time. - -## Environment variables - -- CORS_ALLOW_ORIGINS (string) | Allowed CORS -- DEVELOPMENT (bool) | Whether the program is run in development mode -- ZAUTH_URL (string) | URL of zauth -- ZAUTH_CALLBACK_PATH (string) | Callback path after the zauth authentication (should go to the backend) -- ZAUTH_CLIENT_ID (string) | ID of the zauth client -- ZAUTH_CLIENT_SECRET (string) | Secret of the zauth client -- ZAUTH_REDIRECT_URI (string) | Redirect URI after the zauth authentication is complete in the backend (should go to the frontend) -- POSTGRES_CONNECTION_STRING (string) | Connection string for the database diff --git a/vingo/database/cards.go b/vingo/database/cards.go deleted file mode 100644 index b589711..0000000 --- a/vingo/database/cards.go +++ /dev/null @@ -1,38 +0,0 @@ -package database - -func CreateCard(serial string, user_id int) error { - return gorm_db.Create(&Card{Serial: serial, UserId: user_id}).Error -} - -func GetCardsForUser(user_id int) ([]Card, error) { - var cards []Card - result := gorm_db.Where("user_id = ?", user_id).Find(&cards) - return cards, result.Error -} - -func GetCardsAndStatsForUser(user_id int) ([]CardAPI, error) { - rows, err := db.Query(` - SELECT cards.id, cards.created_at, serial, name, COUNT(scans.id), (select MAX(scan_time) from scans where card_serial = cards.serial) - FROM cards - LEFT JOIN scans on scans.card_serial = serial - WHERE user_id = $1 - GROUP BY cards.id, cards.created_at, cards.serial, cards.name; - `, user_id) - - if err != nil { - return nil, err - } - - cards := []CardAPI{} - for rows.Next() { - var item CardAPI - _ = rows.Scan(&item.Id, &item.CreatedAt, &item.Serial, &item.Name, &item.AmountUsed, &item.LastUsed) - cards = append(cards, item) - } - - return cards, nil -} - -func UpdateCardName(id int, name string, user_id int) error { - return gorm_db.Model(&Card{}).Where("id = ? AND user_id = ?", id, user_id).Update("name", name).Error -} diff --git a/vingo/database/days.go b/vingo/database/days.go deleted file mode 100644 index 73daecc..0000000 --- a/vingo/database/days.go +++ /dev/null @@ -1,46 +0,0 @@ -package database - -import ( - "time" - - "gorm.io/gorm" -) - -func CreateDays(first_day time.Time, last_day time.Time) error { - err := gorm_db.Transaction(func(tx *gorm.DB) error { - for d := first_day; !d.After(last_day); d = d.AddDate(0, 0, 1) { - // Ignore weekends - if d.Weekday() == time.Saturday || d.Weekday() == time.Sunday { - continue - } - - if err := tx.Create(&StreakDay{Date: d}).Error; err != nil { - return err - } - } - - return nil - }) - - if err != nil { - return err - } - - return nil -} - -func GetDays() ([]StreakDay, error) { - var days []StreakDay - err := gorm_db.Find(&days).Error - - return days, err -} - -func DeleteDay(dayId string) error { - _, err := db.Exec("DELETE FROM streak_days WHERE id = $1;", dayId) - if err != nil { - return err - } - - return nil -} diff --git a/vingo/database/db.go b/vingo/database/db.go deleted file mode 100644 index f8dd8c5..0000000 --- a/vingo/database/db.go +++ /dev/null @@ -1,41 +0,0 @@ -package database - -import ( - "database/sql" - "log" - - "gorm.io/driver/postgres" - "gorm.io/gorm" -) - -var ( - db *sql.DB - gorm_db *gorm.DB -) - -func Get() *sql.DB { - return db -} - -func OpenDatabase(db_string string) { - new_db, err := gorm.Open(postgres.Open(db_string), &gorm.Config{}) - if err != nil { - log.Println("Error opening database connection") - log.Fatal(err) - } - - err = new_db.AutoMigrate() - if err != nil { - log.Println("Error migrating database") - log.Fatal(err) - } - - err = new_db.AutoMigrate(&User{}, &Card{}, &Scan{}, &StreakDay{}, &Settings{}, &Season{}) - if err != nil { - log.Println("Error migrating database") - log.Fatal(err) - } - - gorm_db = new_db - db, _ = new_db.DB() -} diff --git a/vingo/database/models.go b/vingo/database/models.go deleted file mode 100644 index aa581d4..0000000 --- a/vingo/database/models.go +++ /dev/null @@ -1,81 +0,0 @@ -package database - -import ( - "time" - - "gorm.io/gorm" -) - -type BaseModel struct { - Id int `json:"id" gorm:"primarykey"` - CreatedAt time.Time `json:"created_at"` - UpdatedAt time.Time `json:"-"` - DeletedAt gorm.DeletedAt `json:"-" gorm:"index"` -} - -type User struct { - BaseModel - Username string `json:"username"` - Admin bool `json:"admin"` - SettingsId int - Settings Settings `json:"settings"` - Cards []Card `json:"-" gorm:"foreignKey:UserId;references:Id"` -} - -type Settings struct { - BaseModel - ScanInOut bool `json:"scan_in_out"` - Leaderboard bool `json:"leaderboard"` - Public bool `json:"public"` -} - -type Card struct { - BaseModel - Serial string `gorm:"uniqueIndex"` - Name string - UserId int - User User - Scans []Scan `gorm:"foreignKey:CardSerial;references:Serial"` -} - -func Card_to_API(card Card) CardAPI { - var lastUsed time.Time = card.CreatedAt - if len(card.Scans) != 0 { - lastUsed = card.Scans[len(card.Scans)-1].ScanTime - } - - return CardAPI{ - Id: card.Id, - Serial: card.Serial, - Name: card.Name, - LastUsed: lastUsed, - AmountUsed: len(card.Scans), - } -} - -type CardAPI struct { - Id int `json:"id"` - CreatedAt time.Time `json:"created_at"` - Serial string `json:"serial"` - Name string `json:"name"` - LastUsed time.Time `json:"last_used"` - AmountUsed int `json:"amount_used"` -} - -type Scan struct { - BaseModel - ScanTime time.Time `json:"scan_time"` - CardSerial string `json:"card_serial" gorm:"index"` - Card Card `json:"-" gorm:"foreignKey:CardSerial;references:Serial"` -} - -type Season struct { - BaseModel - StartDate time.Time `json:"startDate"` - EndDate time.Time `json:"endDate"` -} - -type StreakDay struct { - BaseModel - Date time.Time `json:"date"` -} diff --git a/vingo/database/scans.go b/vingo/database/scans.go deleted file mode 100644 index e07ca9c..0000000 --- a/vingo/database/scans.go +++ /dev/null @@ -1,127 +0,0 @@ -package database - -import ( - "time" -) - -type Present struct { - Date time.Time - Present bool - StreakDay bool -} - -type LeaderboardItem struct { - Position int `json:"position"` - UserId int `json:"user_id"` - Username string `json:"username"` - TotalDays int `json:"total_days"` - PositionChange int `json:"position_change"` -} - -type AnonymousScan struct { - Id int `json:"id"` - ScanTime time.Time `json:"scan_time"` -} - -func CreateScan(card_serial string) error { - return gorm_db.Create(&Scan{ScanTime: time.Now(), CardSerial: card_serial}).Error -} - -func GetScansForUser(user_id int) ([]Scan, error) { - var user User - result := gorm_db.Preload("Cards.Scans").First(&user, user_id) - if result.Error != nil { - return nil, result.Error - } - - var scans []Scan - for _, card := range user.Cards { - scans = append(scans, card.Scans...) - } - - return scans, result.Error -} - -func GetPresenceHistory(user_id int) ([]Present, error) { - rows, err := db.Query(` - WITH date_series AS ( - SELECT generate_series(CURRENT_DATE AT TIME ZONE 'Europe/Brussels' - INTERVAL '6 days', CURRENT_DATE AT TIME ZONE 'Europe/Brussels', '1 day')::date AS date - ) - SELECT - ds.date, - CASE WHEN scans.scan_date IS NOT NULL THEN TRUE ELSE FALSE END AS present, - CASE WHEN days.date IS NOT NULL THEN TRUE ELSE FALSE END AS streak_day - FROM date_series ds - LEFT JOIN ( - SELECT DISTINCT ((scan_time - INTERVAL '4 hours') AT TIME ZONE 'Europe/Brussels')::date AS scan_date - FROM scans - LEFT JOIN cards - ON card_serial = serial - WHERE user_id = $1 - ) scans - ON ds.date = scans.scan_date - LEFT JOIN days - ON ds.date = days.date - ORDER BY ds.date DESC; - `, user_id) - if err != nil { - return nil, err - } - - presences := []Present{} - for rows.Next() { - var present Present - _ = rows.Scan(&present.Date, &present.Present, &present.StreakDay) - - presences = append(presences, present) - } - - return presences, nil -} - -func TotalDaysPerUser(before_time time.Time) ([]LeaderboardItem, error) { - rows, err := db.Query(` - SELECT user_id, count, username, RANK() OVER (ORDER BY count desc) AS position - FROM (SELECT COUNT(DISTINCT ((scan_time - INTERVAL '4 hours') AT TIME ZONE 'Europe/Brussels')::date), username, users.id as user_id - FROM scans - LEFT JOIN cards ON card_serial = serial - LEFT JOIN users ON user_id = users.id - WHERE scan_time < $1 - GROUP BY username, users.id); - `, before_time) - - if err != nil { - return nil, err - } - - leaderboard := []LeaderboardItem{} - for rows.Next() { - var item LeaderboardItem - _ = rows.Scan(&item.UserId, &item.TotalDays, &item.Username, &item.Position) - - leaderboard = append(leaderboard, item) - } - - return leaderboard, nil -} - -func GetRecentScans() ([]AnonymousScan, error) { - scans := []AnonymousScan{} - twoWeeksAgo := time.Now().AddDate(0, 0, -14) - - subQuery := gorm_db. - Table("scans"). - Select("scans.id, scans.scan_time, users.id as user_id"). - Joins("INNER JOIN cards ON cards.serial = scans.card_serial"). - Joins("INNER JOIN users ON users.id = cards.user_id"). - Where("scans.scan_time >= ?", twoWeeksAgo) - - err := gorm_db. - Table("(?) as scans", subQuery). - Select("DISTINCT ON (user_id, DATE(scan_time)) id, scan_time"). - Order("user_id, DATE(scan_time), id"). - Scan(&scans). - Error - - return scans, err -} diff --git a/vingo/database/seasons.go b/vingo/database/seasons.go deleted file mode 100644 index 4cd36ab..0000000 --- a/vingo/database/seasons.go +++ /dev/null @@ -1,11 +0,0 @@ -package database - -func (Season) GetAll() ([]Season, error) { - var seasons []Season - result := gorm_db.Find(&seasons) - return seasons, result.Error -} - -func (s Season) Create() error { - return gorm_db.Create(s).Error -} diff --git a/vingo/database/settings.go b/vingo/database/settings.go deleted file mode 100644 index b3d284e..0000000 --- a/vingo/database/settings.go +++ /dev/null @@ -1,26 +0,0 @@ -package database - -import "log" - -func GetSettings(user_id int) (*Settings, error) { - var user User - result := gorm_db.Preload("Settings").First(&user, user_id) - log.Println(user) - return &user.Settings, result.Error -} - -func UpdateSettings(user_id int, settings Settings) error { - var user User - if err := gorm_db.Preload("Settings").First(&user, user_id).Error; err != nil { - return err - } - - user.Settings.ScanInOut = settings.ScanInOut - user.Settings.Leaderboard = settings.Leaderboard - user.Settings.Public = settings.Public - if err := gorm_db.Save(&user.Settings).Error; err != nil { - return err - } - - return nil -} diff --git a/vingo/database/users.go b/vingo/database/users.go deleted file mode 100644 index c46c9b7..0000000 --- a/vingo/database/users.go +++ /dev/null @@ -1,26 +0,0 @@ -package database - -import ( - "time" -) - -func CreateUserIfNew(user_id int, username string) error { - var user = &User{Username: username, Settings: Settings{ScanInOut: false, Leaderboard: true, Public: false}} - user.Id = user_id - user.Settings.CreatedAt = time.Now() - user.Settings.UpdatedAt = time.Now() - result := gorm_db.FirstOrCreate(&user) - return result.Error -} - -func GetUser(user_id int) (*User, error) { - var user User - result := gorm_db.Preload("Settings").First(&user, user_id) - return &user, result.Error -} - -func GetUserFromCard(card_serial string) (*User, error) { - var card Card - result := gorm_db.First(&card, "serial = ?", card_serial) - return &card.User, result.Error -} diff --git a/vingo/dev.env b/vingo/dev.env deleted file mode 100644 index 474eefb..0000000 --- a/vingo/dev.env +++ /dev/null @@ -1,11 +0,0 @@ -CORS_ALLOW_ORIGINS="http://localhost:5173" -DEVELOPMENT=true - -ZAUTH_URL="https://zauth.zeus.gent" -ZAUTH_CALLBACK_PATH="/api/auth/callback" -ZAUTH_CLIENT_ID="tomtest" -ZAUTH_CLIENT_SECRET="blargh" -ZAUTH_REDIRECT_URI="http://localhost:5173" -SCAN_KEY="bad_key" - -POSTGRES_CONNECTION_STRING="postgres://postgres:zess@host.docker.internal/zess?sslmode=disable" diff --git a/vingo/go.mod b/vingo/go.mod deleted file mode 100644 index 5c1a039..0000000 --- a/vingo/go.mod +++ /dev/null @@ -1,38 +0,0 @@ -module vingo - -go 1.22.1 - -require ( - github.com/gofiber/fiber/v2 v2.52.5 - github.com/joho/godotenv v1.5.1 - github.com/lib/pq v1.10.9 - gorm.io/driver/postgres v1.5.9 - gorm.io/gorm v1.25.11 -) - -require ( - github.com/jackc/pgpassfile v1.0.0 // indirect - github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect - github.com/jackc/pgx/v5 v5.6.0 // indirect - github.com/jackc/puddle/v2 v2.2.1 // indirect - github.com/jinzhu/inflection v1.0.0 // indirect - github.com/jinzhu/now v1.1.5 // indirect - golang.org/x/crypto v0.25.0 // indirect - golang.org/x/sync v0.7.0 // indirect - golang.org/x/text v0.16.0 // indirect -) - -require ( - github.com/andybalholm/brotli v1.1.0 // indirect - github.com/google/uuid v1.6.0 // indirect - github.com/klauspost/compress v1.17.9 // indirect - github.com/mattn/go-colorable v0.1.13 // indirect - github.com/mattn/go-isatty v0.0.20 // indirect - github.com/mattn/go-runewidth v0.0.15 // indirect - github.com/rivo/uniseg v0.4.7 // indirect - github.com/stretchr/testify v1.8.4 // indirect - github.com/valyala/bytebufferpool v1.0.0 // indirect - github.com/valyala/fasthttp v1.55.0 // indirect - github.com/valyala/tcplisten v1.0.0 // indirect - golang.org/x/sys v0.22.0 // indirect -) diff --git a/vingo/go.sum b/vingo/go.sum deleted file mode 100644 index 5fce104..0000000 --- a/vingo/go.sum +++ /dev/null @@ -1,68 +0,0 @@ -github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M= -github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/gofiber/fiber/v2 v2.52.5 h1:tWoP1MJQjGEe4GB5TUGOi7P2E0ZMMRx5ZTG4rT+yGMo= -github.com/gofiber/fiber/v2 v2.52.5/go.mod h1:KEOE+cXMhXG0zHc9d8+E38hoX+ZN7bhOtgeF2oT6jrQ= -github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= -github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM= -github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg= -github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo= -github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= -github.com/jackc/pgx/v5 v5.6.0 h1:SWJzexBzPL5jb0GEsrPMLIsi/3jOo7RHlzTjcAeDrPY= -github.com/jackc/pgx/v5 v5.6.0/go.mod h1:DNZ/vlrUnhWCoFGxHAG8U2ljioxukquj7utPDgtQdTw= -github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk= -github.com/jackc/puddle/v2 v2.2.1/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4= -github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= -github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= -github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ= -github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= -github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= -github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= -github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA= -github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= -github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw= -github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= -github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= -github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= -github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= -github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= -github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= -github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U= -github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= -github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= -github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= -github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= -github.com/valyala/fasthttp v1.55.0 h1:Zkefzgt6a7+bVKHnu/YaYSOPfNYNisSVBo/unVCf8k8= -github.com/valyala/fasthttp v1.55.0/go.mod h1:NkY9JtkrpPKmgwV3HTaS2HWaJss9RSIsRVfcxxoHiOM= -github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8= -github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc= -golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30= -golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M= -golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= -golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= -golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI= -golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= -golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gorm.io/driver/postgres v1.5.9 h1:DkegyItji119OlcaLjqN11kHoUgZ/j13E0jkJZgD6A8= -gorm.io/driver/postgres v1.5.9/go.mod h1:DX3GReXH+3FPWGrrgffdvCk3DQ1dwDPdmbenSkweRGI= -gorm.io/gorm v1.25.11 h1:/Wfyg1B/je1hnDx3sMkX+gAlxrlZpn6X0BXRlwXlvHg= -gorm.io/gorm v1.25.11/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ= diff --git a/vingo/handlers/access.go b/vingo/handlers/access.go deleted file mode 100644 index e1ed9d0..0000000 --- a/vingo/handlers/access.go +++ /dev/null @@ -1,19 +0,0 @@ -package handlers - -import "github.com/gofiber/fiber/v2" - -func IsLoggedIn(c *fiber.Ctx) error { - if getUserFromStore(c) == nil { - return c.Status(401).SendString("Unauthorized") - } - - return c.Next() -} - -func IsAdmin(c *fiber.Ctx) error { - if !isAdmin(c) { - return c.Status(403).SendString("Forbidden") - } - - return c.Next() -} diff --git a/vingo/handlers/auth.go b/vingo/handlers/auth.go deleted file mode 100644 index b49bb7e..0000000 --- a/vingo/handlers/auth.go +++ /dev/null @@ -1,139 +0,0 @@ -package handlers - -import ( - "crypto/rand" - "fmt" - "math/big" - "vingo/database" - - "github.com/gofiber/fiber/v2" -) - -var ( - ZauthURL = "" - ZauthCallbackPath = "" - ZauthClientId = "" - ZauthClientSecret = "" - ZauthRedirectUri = "" -) - -func SetZauth(url string, callback_path string, client_id string, client_secret string, redirect_uri string) { - ZauthURL = url - ZauthCallbackPath = callback_path - ZauthClientId = client_id - ZauthClientSecret = client_secret - ZauthRedirectUri = redirect_uri -} - -func Login(c *fiber.Ctx) error { - sess, err := store.Get(c) - if err != nil { - logger.Println("login:", err) - return c.Status(500).SendString("Session error") - } - - state, _ := rand.Int(rand.Reader, big.NewInt(1000000000)) - sess.Set(ZAUTH_STATE, state.String()) - sess.Save() - - callback_url := c.BaseURL() + ZauthCallbackPath - return c.Status(200).Redirect(fmt.Sprintf("%s/oauth/authorize?client_id=%s&response_type=code&state=%s&redirect_uri=%s", ZauthURL, ZauthClientId, state.String(), callback_url)) -} - -func Logout(c *fiber.Ctx) error { - sess, err := store.Get(c) - if err != nil { - logger.Println("logout:", err) - return c.Status(500).SendString("Session error") - } - - sess.Destroy() - return c.Status(200).Redirect(ZauthRedirectUri) -} - -// Zauth access token -type ZauthToken struct { - AccessToken string `json:"access_token"` - TokenType string `json:"token_type"` - ExpiresIn int `json:"expires_in"` -} - -// Zauth user info -type ZauthUser struct { - Id int `json:"id"` - Username string `json:"username"` -} - -// oauth -func Callback(c *fiber.Ctx) error { - sess, err := store.Get(c) - if err != nil { - logger.Println(err) - return c.Status(500).SendString("Session error") - } - - // Check if saved state matches the one returned by Zauth - expected_state := sess.Get(ZAUTH_STATE).(string) - received_state := c.Query("state") - if expected_state != received_state { - logger.Println("State mismatch: got", received_state, "expected", expected_state) - return c.Status(400).SendString("State mismatch") - } - - code := c.Query("code") - - args := fiber.AcquireArgs() - defer fiber.ReleaseArgs(args) - args.Set("grant_type", "authorization_code") - args.Set("code", code) - args.Set("redirect_uri", c.BaseURL()+ZauthCallbackPath) - - // Convert callback code into access token - zauth_token := new(ZauthToken) - status, _, errs := fiber. - Post(ZauthURL+"/oauth/token"). - BasicAuth(ZauthClientId, ZauthClientSecret). - Form(args). - Struct(zauth_token) - - if len(errs) > 0 || status != 200 { - logger.Println("Error callback code -> access token from Zauth") - logger.Println(status) - logger.Println(errs) - return c.Status(500).SendString("Error fetching token") - } - - // Get user info using access token - zauth_user := new(ZauthUser) - status, _, errs = fiber. - Get(ZauthURL+"/current_user"). - Set("Authorization", "Bearer "+zauth_token.AccessToken). - Struct(zauth_user) - - if len(errs) > 0 || status != 200 { - logger.Println("Error fetching user info from Zauth") - logger.Println(status) - logger.Println(errs) - return c.Status(500).SendString("Error fetching user") - } - - // Insert user into database using the Zauth id - err = database.CreateUserIfNew(zauth_user.Id, zauth_user.Username) - if err != nil { - logger.Println("Insert user:", err) - return c.Status(500).SendString("Error inserting user") - } - - user, err := database.GetUser(zauth_user.Id) - if err != nil { - logger.Println("Get user:", err) - return c.Status(500).SendString("Error fetching user") - } - - // Regenerate the session to set a new key - sess.Regenerate() - sess.Set(STORE_USER, &user) - sess.Save() - - return c.Status(200).Redirect(ZauthRedirectUri) -} diff --git a/vingo/handlers/cards.go b/vingo/handlers/cards.go deleted file mode 100644 index 1d4bd1d..0000000 --- a/vingo/handlers/cards.go +++ /dev/null @@ -1,72 +0,0 @@ -package handlers - -import ( - "strconv" - "time" - "vingo/database" - - "github.com/gofiber/fiber/v2" -) - -var register_timeout = time.Minute - -type Cards struct{} - -func (Cards) StartRegister(c *fiber.Ctx) error { - user := getUserFromStore(c) - - if time.Now().Before(registering_end) { - // true if current user is already registering - return c.Status(503).JSON(map[string]bool{"isCurrentUser": registering_user == user.Id}) - } - - registering_user = user.Id - registering_end = time.Now().Add(register_timeout) - registering_success = false - - logger.Println("Card registration started by user", registering_user) - - return c.SendStatus(200) -} - -func (Cards) Get(c *fiber.Ctx) error { - user := getUserFromStore(c) - cards, err := database.GetCardsAndStatsForUser(user.Id) - if err != nil { - logger.Println("", err) - return c.Status(500).SendString("Error getting cards") - } - - return c.JSON(cards) -} - -func (Cards) RegisterStatus(c *fiber.Ctx) error { - user := getUserFromStore(c) - register_ongoing := time.Now().Before(registering_end) - is_current_user := registering_user == user.Id - time_remaining := time.Until(registering_end).Seconds() - time_percentage := time_remaining / register_timeout.Seconds() - return c.JSON(map[string]interface{}{"registering": register_ongoing, "isCurrentUser": is_current_user, "success": registering_success, "timeRemaining": time_remaining, "timePercentage": time_percentage}) -} - -func (Cards) Update(c *fiber.Ctx) error { - user := getUserFromStore(c) - card_id, err := strconv.Atoi(c.Params("id")) - if err != nil { - logger.Println(err) - return c.Status(400).SendString("Invalid card id") - } - - payload := struct { - Name string `json:"name"` - }{} - c.BodyParser(&payload) - - err = database.UpdateCardName(card_id, payload.Name, user.Id) - if err != nil { - logger.Println(err) - return c.Status(500).SendString("Error updating card name") - } - - return c.SendStatus(200) -} diff --git a/vingo/handlers/leaderboard.go b/vingo/handlers/leaderboard.go deleted file mode 100644 index 486dd04..0000000 --- a/vingo/handlers/leaderboard.go +++ /dev/null @@ -1,33 +0,0 @@ -package handlers - -import ( - "time" - "vingo/database" - - "github.com/gofiber/fiber/v2" -) - -func Leaderboard(c *fiber.Ctx) error { - users, err := database.TotalDaysPerUser(time.Now()) - if err != nil { - logger.Println("Error getting leaderboard:", err) - return c.Status(500).SendString("Error getting leaderboard") - } - - users_last_week, err := database.TotalDaysPerUser(time.Now().AddDate(0, 0, -7)) - if err != nil { - logger.Println("Error getting leaderboard:", err) - return c.Status(500).SendString("Error getting leaderboard") - } - - for i, user := range users { - for _, user_last_week := range users_last_week { - if user.UserId == user_last_week.UserId { - users[i].PositionChange = user_last_week.Position - user.Position - break - } - } - } - - return c.JSON(users) -} diff --git a/vingo/handlers/public.go b/vingo/handlers/public.go deleted file mode 100644 index df3f8d7..0000000 --- a/vingo/handlers/public.go +++ /dev/null @@ -1,18 +0,0 @@ -package handlers - -import ( - "vingo/database" - - "github.com/gofiber/fiber/v2" -) - -func PublicRecentScans(c *fiber.Ctx) error { - scans, err := database.GetRecentScans() - - if err != nil { - logger.Println("Error get recent scans:", err) - return c.Status(500).SendString("Error getting recent scans") - } - - return c.JSON(fiber.Map{"scans": scans}) -} diff --git a/vingo/handlers/scans.go b/vingo/handlers/scans.go deleted file mode 100644 index bf68858..0000000 --- a/vingo/handlers/scans.go +++ /dev/null @@ -1,76 +0,0 @@ -package handlers - -import ( - "strings" - "time" - "vingo/database" - - "github.com/gofiber/fiber/v2" -) - -var ( - scan_key = "" -) - -func SetScanKey(key string) { - scan_key = key -} - -func ScanRegister(c *fiber.Ctx) error { - // Check if the key is correct - data := c.Body() - s_data := strings.Split(string(data), ";") - if len(s_data) != 2 { - return c.Status(400).SendString("Invalid format: card_id;key") - } - - card_serial := s_data[0] - key := s_data[1] - if key != scan_key { - return c.Status(401).SendString("Invalid key") - } - - // if card registering session is active, register the card instead of scanning - if time.Now().Before(registering_end) { - logger.Println("Registering card", card_serial, "for user", registering_user) - - err := database.CreateCard(card_serial, registering_user) - // error or not, end registering session - registering_user = 0 - registering_end = time.Now() - - if err != nil { - logger.Println(err) - return c.Status(500).SendString("Error registering card") - } - registering_success = true - return c.SendString("Card registered") - } - - // add scan to database - err := database.CreateScan(card_serial) - if err != nil { - logger.Println(err) - // technically only when error is foreign key constraint - return c.Status(404).SendString("Card doesn't exist") - } - - user, err := database.GetUserFromCard(card_serial) - if err != nil { - logger.Println(err) - return c.Status(404).SendString("Card doesn't exist") - } - - return c.SendString(user.Username) -} - -func Scans(c *fiber.Ctx) error { - user := getUserFromStore(c) - scans, err := database.GetScansForUser(user.Id) - if err != nil { - logger.Println("Error get scans:", err) - return c.Status(500).SendString("Error getting scans") - } - - return c.JSON(scans) -} diff --git a/vingo/handlers/seasons.go b/vingo/handlers/seasons.go deleted file mode 100644 index bcfed09..0000000 --- a/vingo/handlers/seasons.go +++ /dev/null @@ -1,36 +0,0 @@ -package handlers - -import ( - "vingo/database" - - "github.com/gofiber/fiber/v2" -) - -type Seasons struct{} - -func (Seasons) Get(c *fiber.Ctx) error { - seasons, err := database.Season{}.GetAll() - if err != nil { - logger.Println(err) - return c.Status(500).SendString("Error getting seasons") - } - - return c.JSON(seasons) -} - -func (Seasons) Create(c *fiber.Ctx) error { - season := database.Season{} - err := c.BodyParser(&season) - if err != nil { - logger.Println(err) - return c.Status(400).SendString("Invalid payload") - } - - err = season.Create() - if err != nil { - logger.Println(err) - return c.Status(500).SendString("Error creating season") - } - - return c.SendStatus(200) -} diff --git a/vingo/handlers/settings.go b/vingo/handlers/settings.go deleted file mode 100644 index 9cccef5..0000000 --- a/vingo/handlers/settings.go +++ /dev/null @@ -1,38 +0,0 @@ -package handlers - -import ( - "vingo/database" - - "github.com/gofiber/fiber/v2" -) - -type Settings struct{} - -func (Settings) Update(c *fiber.Ctx) error { - user := getUserFromStore(c) - - settings := database.Settings{} - err := c.BodyParser(&settings) - if err != nil { - logger.Println(err) - return c.Status(400).SendString("Invalid payload") - } - - err = database.UpdateSettings(user.Id, settings) - if err != nil { - logger.Println(err) - return c.Status(500).SendString("Error updating settings") - } - - sess, _ := store.Get(c) - user, _ = database.GetUser(user.Id) - sess.Set(STORE_USER, &user) - sess.Save() - - return c.SendStatus(200) -} - -func (Settings) Get(c *fiber.Ctx) error { - user := getUserFromStore(c) - return c.JSON(user.Settings) -} diff --git a/vingo/handlers/store.go b/vingo/handlers/store.go deleted file mode 100644 index d611854..0000000 --- a/vingo/handlers/store.go +++ /dev/null @@ -1,55 +0,0 @@ -package handlers - -import ( - "log" - "os" - "time" - "vingo/database" - - "github.com/gofiber/fiber/v2" - "github.com/gofiber/fiber/v2/middleware/session" -) - -var ( - store = session.New() - logger = log.New(os.Stdout, "", log.Ldate|log.Ltime|log.Lshortfile) - - // State for registering a new card - registering_user = 0 - registering_end = time.Now() - registering_success = false -) - -const ( - STORE_USER = "store_user" - USER_ID = "user_id" - USERNAME = "username" - ZAUTH_STATE = "zauth_state" -) - -func getUserFromStore(c *fiber.Ctx) *database.User { - sess, err := store.Get(c) - if err != nil { - logger.Println(err) - return nil - } - - user := sess.Get(STORE_USER) - if user == nil { - return nil - } - - databaseUser := user.(database.User) - logger.Println("User from store:", databaseUser.Id) - return &databaseUser -} - -func isAdmin(c *fiber.Ctx) bool { - user := getUserFromStore(c) - logger.Println("Is admin:", user) - if user == nil { - return false - } - - return user.Admin -} diff --git a/vingo/handlers/users.go b/vingo/handlers/users.go deleted file mode 100644 index 0190a08..0000000 --- a/vingo/handlers/users.go +++ /dev/null @@ -1,9 +0,0 @@ -package handlers - -import "github.com/gofiber/fiber/v2" - -func User(c *fiber.Ctx) error { - user := getUserFromStore(c) - - return c.JSON(user) -} diff --git a/vingo/main.go b/vingo/main.go deleted file mode 100644 index 4de4975..0000000 --- a/vingo/main.go +++ /dev/null @@ -1,155 +0,0 @@ -package main - -import ( - "encoding/gob" - "os" - "strconv" - "vingo/database" - "vingo/handlers" - - "log" - - "github.com/gofiber/fiber/v2" - "github.com/gofiber/fiber/v2/middleware/cors" - "github.com/joho/godotenv" - _ "github.com/lib/pq" -) - -var ( - corsAllowOrigins string - development bool -) - -func main() { - gob.Register(database.User{}) - gob.Register(database.Settings{}) - - setupFromEnv() - - db := database.Get() - defer db.Close() - - app := fiber.New(fiber.Config{}) - - if development { - app.Use(cors.New(cors.Config{ - AllowOrigins: corsAllowOrigins, - AllowHeaders: "Origin, Content-Type, Accept, Access-Control-Allow-Origin", - AllowCredentials: true, - })) - } else { - app.Static("/", "./public") - } - - api := app.Group("/api") - - { - // Public routes - api.Post("/login", handlers.Login) - api.Get("/auth/callback", handlers.Callback) - - api.Post("/scans", handlers.ScanRegister) - - api.Get("/recent_scans", handlers.PublicRecentScans) - - // Protected routes - authed := api.Group("", handlers.IsLoggedIn) - { - authed.Post("/logout", handlers.Logout) - authed.Get("/user", handlers.User) - authed.Get("/leaderboard", handlers.Leaderboard) - authed.Get("/scans", handlers.Scans) - - authed.Get("/cards", handlers.Cards{}.Get) - authed.Patch("/cards/:id", handlers.Cards{}.Update) - authed.Get("/cards/register", handlers.Cards{}.RegisterStatus) - authed.Post("/cards/register", handlers.Cards{}.StartRegister) - - authed.Get("/settings", handlers.Settings{}.Get) - authed.Patch("/settings", handlers.Settings{}.Update) - - // Admin routes - admin := authed.Group("/admin", handlers.IsAdmin) - { - admin.Get("/days", handlers.Days{}.All) - admin.Post("/days", handlers.Days{}.CreateMultiple) - admin.Delete("/days/:id", handlers.Days{}.Delete) - } - } - } - - // Catch-all route leading to the frontend - app.Get("*", func(c *fiber.Ctx) error { - return c.SendFile("./public/index.html") - }) - - log.Println(app.Listen(":4000")) -} - -func setupFromEnv() { - err := godotenv.Load() - if err != nil { - log.Fatal("Error loading .env file") - } - - cors_allow_origins, origins_ok := os.LookupEnv("CORS_ALLOW_ORIGINS") - if !origins_ok { - log.Fatal("CORS_ALLOW_ORIGINS environment variable not set") - } - corsAllowOrigins = cors_allow_origins - - dev, dev_ok := os.LookupEnv("DEVELOPMENT") - if !dev_ok { - log.Fatal("DEVELOPMENT environment variable not set") - } - dev_value, dev_value_err := strconv.ParseBool(dev) - if dev_value_err != nil { - log.Fatal("DEVELOPMENT environment variable is not a valid boolean") - } - development = dev_value - - // stuff for Zauth oauth flow - - zauth_url, url_ok := os.LookupEnv("ZAUTH_URL") - if !url_ok { - log.Fatal("ZAUTH_URL environment variable not set") - } - - zauth_callback_path, callback_ok := os.LookupEnv("ZAUTH_CALLBACK_PATH") - if !callback_ok { - log.Fatal("ZAUTH_CALLBACK_PATH environment variable not set") - } - - zauth_client_id, id_ok := os.LookupEnv("ZAUTH_CLIENT_ID") - if !id_ok { - log.Fatal("ZAUTH_CLIENT_ID environment variable not set") - } - - zauth_client_secret, secret_ok := os.LookupEnv("ZAUTH_CLIENT_SECRET") - if !secret_ok { - log.Fatal("ZAUTH_CLIENT_SECRET environment variable not set") - } - - zauth_redirect_uri, redirect_ok := os.LookupEnv("ZAUTH_REDIRECT_URI") - if !redirect_ok { - log.Fatal("ZAUTH_REDIRECT_URI environment variable not set") - } - - handlers.SetZauth(zauth_url, zauth_callback_path, zauth_client_id, zauth_client_secret, zauth_redirect_uri) - - // PSK that will authorize the scanner - scan_key, key_ok := os.LookupEnv("SCAN_KEY") - if !key_ok { - log.Fatal("SCAN_KEY environment variable not set") - } - - handlers.SetScanKey(scan_key) - - // Database - database_string, db_ok := os.LookupEnv("POSTGRES_CONNECTION_STRING") - if !db_ok { - log.Fatal("POSTGRES_CONNECTION_STRING environment variable not set") - } - - database.OpenDatabase(database_string) -} diff --git a/vingo/src/main.rs b/vingo/src/main.rs new file mode 100644 index 0000000..13c55d5 --- /dev/null +++ b/vingo/src/main.rs @@ -0,0 +1,34 @@ +mod routes { + pub mod auth; +} + +use routes::auth; + +use axum::{routing::get, Router}; +use tower_http::trace::TraceLayer; +use tower_sessions::{cookie::SameSite, MemoryStore, SessionManagerLayer}; + +#[tokio::main] +async fn main() { + tracing_subscriber::fmt() + .with_max_level(tracing::Level::DEBUG) + .init(); + + let sess_store = MemoryStore::default(); + let sess_mw = SessionManagerLayer::new(sess_store).with_same_site(SameSite::Lax); + + // build our application with a route + let app = Router::new() + .route("/login", get(auth::login)) + .route("/state", get(auth::logout)) + .route("/api/auth/callback", get(auth::callback)) + .layer(sess_mw) + .layer(TraceLayer::new_for_http()); + + // run it + let listener = tokio::net::TcpListener::bind("127.0.0.1:4000") + .await + .unwrap(); + println!("listening on {}", listener.local_addr().unwrap()); + axum::serve(listener, app).await.unwrap(); +} diff --git a/vingo/src/routes/auth.rs b/vingo/src/routes/auth.rs new file mode 100644 index 0000000..738b22f --- /dev/null +++ b/vingo/src/routes/auth.rs @@ -0,0 +1,101 @@ +use std::borrow::Borrow; + +use axum::extract::Query; +use axum::response::{Html, IntoResponse, Redirect}; +use rand::distributions::{Alphanumeric, DistString}; +use reqwest::StatusCode; +use serde::{Deserialize, Serialize}; +use tower_sessions::Session; + +const ZAUTH_URL: &str = "http://localhost:8000"; + +pub async fn login(session: Session) -> impl IntoResponse { + let state = Alphanumeric.sample_string(&mut rand::thread_rng(), 16); + session.insert("state", state.clone()).await.unwrap(); + Redirect::to(&format!("{ZAUTH_URL}/oauth/authorize?client_id=zess&response_type=code&state={state}&redirect_uri=http://localhost:4000/api/auth/callback")) +} + +#[derive(Deserialize, Debug)] +pub struct Callback { + state: String, + code: String, +} + +#[derive(Deserialize, Debug)] +pub struct ZauthToken { + access_token: String, + token_type: String, + expires_in: u64, +} + +#[derive(Serialize, Deserialize, Debug)] +pub struct ZauthUser { + id: u64, + username: String, +} + +pub async fn callback( + Query(params): Query, + session: Session, +) -> Result, StatusCode> { + let state = session + .get::("state") + .await + .unwrap() + .ok_or(StatusCode::INTERNAL_SERVER_ERROR)?; + if state != params.state { + return Err(StatusCode::UNAUTHORIZED); + } + + let client = reqwest::Client::new(); + let form = [ + ("grant_type", "authorization_code"), + ("code", ¶ms.code), + ( + "redirect_uri", + &format!("http://localhost:4000/api/auth/callback"), + ), + ]; + + let token = client + .post(&format!("{ZAUTH_URL}/oauth/token")) + .basic_auth( + "zess", + Some("9KZu9ddJG1Z86BnOqBF4jnTQpUUHA3PYZMKhxRLq2euBvYiM8mtR6SN4EbrycnHw"), + ) + .form(&form) + .send() + .await + .unwrap() + .error_for_status() + .unwrap() + .json::() + .await + .unwrap(); + + let user = client + .get(format!("{ZAUTH_URL}/current_user")) + .header("Authorization", "Bearer ".to_owned() + &token.access_token) + .send() + .await + .unwrap() + .error_for_status() + .unwrap() + .json::() + .await + .unwrap(); + + let username = user.username.clone(); + session.insert("user", user).await.unwrap(); + + Ok(Html(format!("Logged in as {}", username))) +} + +pub async fn logout(session: Session) -> Result, StatusCode> { + let state = session + .get::("state") + .await + .unwrap() + .ok_or(StatusCode::INTERNAL_SERVER_ERROR)?; + Ok(Html(state)) +} diff --git a/vingo/template.env b/vingo/template.env deleted file mode 100644 index 94f1cba..0000000 --- a/vingo/template.env +++ /dev/null @@ -1,11 +0,0 @@ -CORS_ALLOW_ORIGINS= -DEVELOPMENT - -ZAUTH_URL= -ZAUTH_CALLBACK_PATH= -ZAUTH_CLIENT_ID= -ZAUTH_CLIENT_SECRET= -ZAUTH_REDIRECT_URI= -SCAN_KEY= - -POSTGRES_CONNECTION_STRING= From d39ca50f3198a9b9483fa7bb49c4c5549249eecf Mon Sep 17 00:00:00 2001 From: Hannes Klinckaert Date: Wed, 28 Aug 2024 21:56:27 +0200 Subject: [PATCH 02/31] vingo: nest routes under /api --- vingo/src/main.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/vingo/src/main.rs b/vingo/src/main.rs index 13c55d5..1dd49e1 100644 --- a/vingo/src/main.rs +++ b/vingo/src/main.rs @@ -19,9 +19,7 @@ async fn main() { // build our application with a route let app = Router::new() - .route("/login", get(auth::login)) - .route("/state", get(auth::logout)) - .route("/api/auth/callback", get(auth::callback)) + .nest("/api", routes()) .layer(sess_mw) .layer(TraceLayer::new_for_http()); @@ -32,3 +30,10 @@ async fn main() { println!("listening on {}", listener.local_addr().unwrap()); axum::serve(listener, app).await.unwrap(); } + +fn routes() -> Router { + Router::new() + .route("/login", get(auth::login)) + .route("/logout", get(auth::logout)) + .route("/auth/callback", get(auth::callback)) +} From 53a55eaa51572b0346931212666a806cf985d82b Mon Sep 17 00:00:00 2001 From: Hannes Klinckaert Date: Wed, 28 Aug 2024 21:57:00 +0200 Subject: [PATCH 03/31] vingo: cleanup --- vingo/src/routes/auth.rs | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/vingo/src/routes/auth.rs b/vingo/src/routes/auth.rs index 738b22f..c5e8c27 100644 --- a/vingo/src/routes/auth.rs +++ b/vingo/src/routes/auth.rs @@ -7,12 +7,13 @@ use reqwest::StatusCode; use serde::{Deserialize, Serialize}; use tower_sessions::Session; -const ZAUTH_URL: &str = "http://localhost:8000"; +const ZAUTH_URL: &str = "https://zauth.zeus.gent"; +const CALLBACK_URL: &str = "http://localhost:4000/api/auth/callback"; pub async fn login(session: Session) -> impl IntoResponse { let state = Alphanumeric.sample_string(&mut rand::thread_rng(), 16); session.insert("state", state.clone()).await.unwrap(); - Redirect::to(&format!("{ZAUTH_URL}/oauth/authorize?client_id=zess&response_type=code&state={state}&redirect_uri=http://localhost:4000/api/auth/callback")) + Redirect::to(&format!("{ZAUTH_URL}/oauth/authorize?client_id=tomtest&response_type=code&state={state}&redirect_uri={CALLBACK_URL}")) } #[derive(Deserialize, Debug)] @@ -53,15 +54,15 @@ pub async fn callback( ("code", ¶ms.code), ( "redirect_uri", - &format!("http://localhost:4000/api/auth/callback"), + CALLBACK_URL, ), ]; let token = client .post(&format!("{ZAUTH_URL}/oauth/token")) .basic_auth( - "zess", - Some("9KZu9ddJG1Z86BnOqBF4jnTQpUUHA3PYZMKhxRLq2euBvYiM8mtR6SN4EbrycnHw"), + "tomtest", + Some("blargh"), ) .form(&form) .send() @@ -86,16 +87,19 @@ pub async fn callback( .unwrap(); let username = user.username.clone(); - session.insert("user", user).await.unwrap(); + session.clear().await; + session.insert("user", &username).await.unwrap(); Ok(Html(format!("Logged in as {}", username))) } pub async fn logout(session: Session) -> Result, StatusCode> { - let state = session - .get::("state") + let username = session + .get::("user") .await .unwrap() .ok_or(StatusCode::INTERNAL_SERVER_ERROR)?; - Ok(Html(state)) + + session.clear().await; + Ok(Html("logged out as ".to_owned() + &username)) } From 4fe073144761ee00111ecebec640125f0b4395df Mon Sep 17 00:00:00 2001 From: Hannes Klinckaert Date: Wed, 28 Aug 2024 22:17:18 +0200 Subject: [PATCH 04/31] vingo: add database to state --- vingo/Cargo.lock | 990 ++++++++++++++++++++++++++++++++++++--- vingo/Cargo.toml | 1 + vingo/src/main.rs | 16 +- vingo/src/routes/auth.rs | 42 +- 4 files changed, 973 insertions(+), 76 deletions(-) diff --git a/vingo/Cargo.lock b/vingo/Cargo.lock index 11d2e7f..0698083 100644 --- a/vingo/Cargo.lock +++ b/vingo/Cargo.lock @@ -17,6 +17,53 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "getrandom", + "once_cell", + "version_check", + "zerocopy", +] + +[[package]] +name = "aliasable" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "250f629c0161ad8107cf89319e990051fae62832fd343083bea452d93e2205fd" + +[[package]] +name = "allocator-api2" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" + +[[package]] +name = "async-stream" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd56dd203fef61ac097dd65721a419ddccb106b2d2b70ba60a6b529f03961a51" +dependencies = [ + "async-stream-impl", + "futures-core", + "pin-project-lite", +] + +[[package]] +name = "async-stream-impl" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.76", +] + [[package]] name = "async-trait" version = "0.1.81" @@ -25,7 +72,16 @@ checksum = "6e0c28dcc82d7c8ead5cb13beb15405b57b8546e93215673ff8ca0349a028107" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.76", +] + +[[package]] +name = "atoi" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f28d99ec8bfea296261ca1af174f24225171fea9664ba9003cbebee704810528" +dependencies = [ + "num-traits", ] [[package]] @@ -102,18 +158,39 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base64" +version = "0.21.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" + [[package]] name = "base64" version = "0.22.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + [[package]] name = "bitflags" version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + [[package]] name = "bumpalo" version = "3.16.0" @@ -158,6 +235,55 @@ dependencies = [ "version_check", ] +[[package]] +name = "cpufeatures" +version = "0.2.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51e852e6dc9a5bed1fae92dd2375037bf2b768725bf3be87811edee3249d09ad" +dependencies = [ + "libc", +] + +[[package]] +name = "crc" +version = "3.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69e6e4d7b33a94f0991c26729976b10ebde1d34c3ee82408fb536164fa10d636" +dependencies = [ + "crc-catalog", +] + +[[package]] +name = "crc-catalog" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19d374276b40fb8bbdee95aef7c7fa6b5316ec764510eb64b8dd0e2ed0d7e7f5" + +[[package]] +name = "crossbeam-queue" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df0346b5d5e76ac2fe4e327c5fd1118d6be7c51dfb18f9b7922923f287471e35" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" + +[[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 = "deranged" version = "0.3.11" @@ -168,6 +294,103 @@ dependencies = [ "serde", ] +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "crypto-common", + "subtle", +] + +[[package]] +name = "dotenvy" +version = "0.15.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b" + +[[package]] +name = "educe" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4bd92664bf78c4d3dba9b7cdafce6fa15b13ed3ed16175218196942e99168a8" +dependencies = [ + "enum-ordinalize", + "proc-macro2", + "quote", + "syn 2.0.76", +] + +[[package]] +name = "either" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" +dependencies = [ + "serde", +] + +[[package]] +name = "enum-ordinalize" +version = "4.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fea0dcfa4e54eeb516fe454635a95753ddd39acda650ce703031c6973e315dd5" +dependencies = [ + "enum-ordinalize-derive", +] + +[[package]] +name = "enum-ordinalize-derive" +version = "4.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d28318a75d4aead5c4db25382e8ef717932d0346600cacae6357eb5941bc5ff" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.76", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "etcetera" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "136d1b5283a1ab77bd9257427ffd09d8667ced0570b6f938942bc7568ed5b943" +dependencies = [ + "cfg-if", + "home", + "windows-sys 0.48.0", +] + +[[package]] +name = "event-listener" +version = "2.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" + +[[package]] +name = "fastrand" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" + [[package]] name = "fnv" version = "1.0.7" @@ -213,6 +436,17 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" +[[package]] +name = "futures-intrusive" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d930c203dd0b6ff06e0201a4a2fe9149b43c684fd4420555b26d21b1a02956f" +dependencies = [ + "futures-core", + "lock_api", + "parking_lot", +] + [[package]] name = "futures-io" version = "0.3.30" @@ -227,7 +461,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.76", ] [[package]] @@ -248,15 +482,28 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" dependencies = [ + "futures-channel", "futures-core", + "futures-io", "futures-macro", "futures-sink", "futures-task", + "memchr", "pin-project-lite", "pin-utils", "slab", ] +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + [[package]] name = "getrandom" version = "0.2.15" @@ -274,12 +521,73 @@ version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" +[[package]] +name = "hashbrown" +version = "0.14.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" +dependencies = [ + "ahash", + "allocator-api2", +] + +[[package]] +name = "hashlink" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8094feaf31ff591f651a2664fb9cfd92bba7a60ce3197265e9482ebe753c8f7" +dependencies = [ + "hashbrown", +] + +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" +dependencies = [ + "unicode-segmentation", +] + [[package]] name = "hermit-abi" version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "hkdf" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b5f8eb2ad728638ea2c7d47a21db23b7b58a72ed6a38256b8a1849f15fbbdf7" +dependencies = [ + "hmac", +] + +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest", +] + +[[package]] +name = "home" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" +dependencies = [ + "windows-sys 0.52.0", +] + [[package]] name = "http" version = "1.1.0" @@ -356,12 +664,12 @@ dependencies = [ "http", "hyper", "hyper-util", - "rustls", + "rustls 0.23.12", "rustls-pki-types", "tokio", "tokio-rustls", "tower-service", - "webpki-roots", + "webpki-roots 0.26.3", ] [[package]] @@ -394,6 +702,27 @@ dependencies = [ "unicode-normalization", ] +[[package]] +name = "indexmap" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93ead53efc7ea8ed3cfb0c79fc8023fbb782a5432b52830b6518941cebe6505c" +dependencies = [ + "equivalent", + "hashbrown", +] + +[[package]] +name = "inherent" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0122b7114117e64a63ac49f752a5ca4624d534c7b1c7de796ac196381cd2d947" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.76", +] + [[package]] name = "ipnet" version = "2.9.0" @@ -427,6 +756,12 @@ version = "0.2.158" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + [[package]] name = "lock_api" version = "0.4.12" @@ -450,6 +785,16 @@ version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0e7465ac9959cc2b1404e8e2367b43684a6d13790fe23056cc8c6c5a6b7bcb94" +[[package]] +name = "md-5" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d89e7ee0cfbedfc4da3340218492196241d89eefb6dab27de5df917a6d2e78cf" +dependencies = [ + "cfg-if", + "digest", +] + [[package]] name = "memchr" version = "2.7.4" @@ -462,6 +807,12 @@ version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + [[package]] name = "miniz_oxide" version = "0.7.4" @@ -480,7 +831,17 @@ dependencies = [ "hermit-abi", "libc", "wasi", - "windows-sys", + "windows-sys 0.52.0", +] + +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", ] [[package]] @@ -499,6 +860,15 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + [[package]] name = "object" version = "0.36.3" @@ -514,6 +884,39 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +[[package]] +name = "ordered-float" +version = "3.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1e1c390732d15f1d48471625cd92d154e66db2c56645e29a9cd26f4699f72dc" +dependencies = [ + "num-traits", +] + +[[package]] +name = "ouroboros" +version = "0.17.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2ba07320d39dfea882faa70554b4bd342a5f273ed59ba7c1c6b4c840492c954" +dependencies = [ + "aliasable", + "ouroboros_macro", + "static_assertions", +] + +[[package]] +name = "ouroboros_macro" +version = "0.17.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec4c6225c69b4ca778c0aea097321a64c421cf4577b331c61b229267edabb6f8" +dependencies = [ + "heck", + "proc-macro-error", + "proc-macro2", + "quote", + "syn 2.0.76", +] + [[package]] name = "overload" version = "0.1.1" @@ -538,11 +941,17 @@ checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" dependencies = [ "cfg-if", "libc", - "redox_syscall", + "redox_syscall 0.5.3", "smallvec", - "windows-targets", + "windows-targets 0.52.6", ] +[[package]] +name = "paste" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" + [[package]] name = "percent-encoding" version = "2.3.1" @@ -566,7 +975,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.76", ] [[package]] @@ -596,6 +1005,30 @@ dependencies = [ "zerocopy", ] +[[package]] +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn 1.0.109", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote", + "version_check", +] + [[package]] name = "proc-macro2" version = "1.0.86" @@ -616,7 +1049,7 @@ dependencies = [ "quinn-proto", "quinn-udp", "rustc-hash", - "rustls", + "rustls 0.23.12", "socket2", "thiserror", "tokio", @@ -633,7 +1066,7 @@ dependencies = [ "rand", "ring", "rustc-hash", - "rustls", + "rustls 0.23.12", "slab", "thiserror", "tinyvec", @@ -650,7 +1083,7 @@ dependencies = [ "once_cell", "socket2", "tracing", - "windows-sys", + "windows-sys 0.52.0", ] [[package]] @@ -692,13 +1125,22 @@ dependencies = [ "getrandom", ] +[[package]] +name = "redox_syscall" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" +dependencies = [ + "bitflags 1.3.2", +] + [[package]] name = "redox_syscall" version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a908a6e00f1fdd0dfd9c0eb08ce85126f6d8bbda50017e74bc4a4b7d4a926a4" dependencies = [ - "bitflags", + "bitflags 2.6.0", ] [[package]] @@ -707,7 +1149,7 @@ version = "0.12.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8f4955649ef5c38cc7f9e8aa41761d48fb9677197daea9984dc54f56aad5e63" dependencies = [ - "base64", + "base64 0.22.1", "bytes", "futures-core", "futures-util", @@ -725,8 +1167,8 @@ dependencies = [ "percent-encoding", "pin-project-lite", "quinn", - "rustls", - "rustls-pemfile", + "rustls 0.23.12", + "rustls-pemfile 2.1.3", "rustls-pki-types", "serde", "serde_json", @@ -739,7 +1181,7 @@ dependencies = [ "wasm-bindgen", "wasm-bindgen-futures", "web-sys", - "webpki-roots", + "webpki-roots 0.26.3", "windows-registry", ] @@ -755,7 +1197,7 @@ dependencies = [ "libc", "spin", "untrusted", - "windows-sys", + "windows-sys 0.52.0", ] [[package]] @@ -765,46 +1207,89 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] -name = "rustc-hash" -version = "2.0.0" +name = "rustc-hash" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" + +[[package]] +name = "rustix" +version = "0.38.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a85d50532239da68e9addb745ba38ff4612a242c1c7ceea689c4bc7c2f43c36f" +dependencies = [ + "bitflags 2.6.0", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustls" +version = "0.21.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" +checksum = "3f56a14d1f48b391359b22f731fd4bd7e43c97f3c50eee276f3aa09c94784d3e" +dependencies = [ + "ring", + "rustls-webpki 0.101.7", + "sct", +] [[package]] name = "rustls" -version = "0.23.9" +version = "0.23.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a218f0f6d05669de4eabfb24f31ce802035c952429d037507b4a4a39f0e60c5b" +checksum = "c58f8c84392efc0a126acce10fa59ff7b3d2ac06ab451a33f2741989b806b044" dependencies = [ "once_cell", "ring", "rustls-pki-types", - "rustls-webpki", + "rustls-webpki 0.102.7", "subtle", "zeroize", ] [[package]] name = "rustls-pemfile" -version = "2.1.2" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29993a25686778eb88d4189742cd713c9bce943bc54251a33509dc63cbacf73d" +checksum = "1c74cae0a4cf6ccbbf5f359f08efdf8ee7e1dc532573bf0db71968cb56b1448c" dependencies = [ - "base64", + "base64 0.21.7", +] + +[[package]] +name = "rustls-pemfile" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "196fe16b00e106300d3e45ecfcb764fa292a535d7326a29a5875c579c7417425" +dependencies = [ + "base64 0.22.1", "rustls-pki-types", ] [[package]] name = "rustls-pki-types" -version = "1.7.0" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc0a2ce646f8655401bb81e7927b812614bd5d91dbc968696be50603510fcaf0" + +[[package]] +name = "rustls-webpki" +version = "0.101.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "976295e77ce332211c0d24d92c0e83e50f5c5f046d11082cea19f3df13a3562d" +checksum = "8b6275d1ee7a1cd780b64aca7726599a1dbc893b1e64144529e55c3c2f745765" +dependencies = [ + "ring", + "untrusted", +] [[package]] name = "rustls-webpki" -version = "0.102.4" +version = "0.102.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff448f7e92e913c4b7d4c6d8e4540a1724b319b4152b8aef6d4cf8339712b33e" +checksum = "84678086bd54edf2b415183ed7a94d0efb049f1b646a33e22a36f3794be6ae56" dependencies = [ "ring", "rustls-pki-types", @@ -829,6 +1314,72 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +[[package]] +name = "sct" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da046153aa2352493d6cb7da4b6e5c0c057d8a1d0a9aa8560baffdd945acd414" +dependencies = [ + "ring", + "untrusted", +] + +[[package]] +name = "sea-orm" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea1fee0cf8528dbe6eda29d5798afc522a63b75e44c5b15721e6e64af9c7cc4b" +dependencies = [ + "async-stream", + "async-trait", + "futures", + "log", + "ouroboros", + "sea-orm-macros", + "sea-query", + "sea-query-binder", + "serde", + "sqlx", + "strum", + "thiserror", + "tracing", + "url", +] + +[[package]] +name = "sea-orm-macros" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8737b566799ed0444f278d13c300c4c6f1a91782f60ff5825a591852d5502030" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn 2.0.76", + "unicode-ident", +] + +[[package]] +name = "sea-query" +version = "0.31.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e5073b2cfed767511a57d18115f3b3d8bcb5690bf8c89518caec6cb22c0cd74" +dependencies = [ + "educe", + "inherent", + "ordered-float", +] + +[[package]] +name = "sea-query-binder" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "754965d4aee6145bec25d0898e5c931e6c22859789ce62fd85a42a15ed5a8ce3" +dependencies = [ + "sea-query", + "sqlx", +] + [[package]] name = "serde" version = "1.0.209" @@ -846,7 +1397,7 @@ checksum = "a5831b979fd7b5439637af1752d535ff49f4860c0f341d1baeb6faf0f4242170" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.76", ] [[package]] @@ -873,6 +1424,17 @@ dependencies = [ "serde", ] +[[package]] +name = "sha2" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + [[package]] name = "sharded-slab" version = "0.1.7" @@ -910,7 +1472,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" dependencies = [ "libc", - "windows-sys", + "windows-sys 0.52.0", ] [[package]] @@ -919,12 +1481,184 @@ version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" +[[package]] +name = "sqlformat" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f895e3734318cc55f1fe66258926c9b910c124d47520339efecbb6c59cec7c1f" +dependencies = [ + "nom", + "unicode_categories", +] + +[[package]] +name = "sqlx" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9a2ccff1a000a5a59cd33da541d9f2fdcd9e6e8229cc200565942bff36d0aaa" +dependencies = [ + "sqlx-core", + "sqlx-macros", + "sqlx-postgres", +] + +[[package]] +name = "sqlx-core" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24ba59a9342a3d9bab6c56c118be528b27c9b60e490080e9711a04dccac83ef6" +dependencies = [ + "ahash", + "atoi", + "byteorder", + "bytes", + "crc", + "crossbeam-queue", + "either", + "event-listener", + "futures-channel", + "futures-core", + "futures-intrusive", + "futures-io", + "futures-util", + "hashlink", + "hex", + "indexmap", + "log", + "memchr", + "once_cell", + "paste", + "percent-encoding", + "rustls 0.21.12", + "rustls-pemfile 1.0.4", + "serde", + "serde_json", + "sha2", + "smallvec", + "sqlformat", + "thiserror", + "tokio", + "tokio-stream", + "tracing", + "url", + "webpki-roots 0.25.4", +] + +[[package]] +name = "sqlx-macros" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ea40e2345eb2faa9e1e5e326db8c34711317d2b5e08d0d5741619048a803127" +dependencies = [ + "proc-macro2", + "quote", + "sqlx-core", + "sqlx-macros-core", + "syn 1.0.109", +] + +[[package]] +name = "sqlx-macros-core" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5833ef53aaa16d860e92123292f1f6a3d53c34ba8b1969f152ef1a7bb803f3c8" +dependencies = [ + "dotenvy", + "either", + "heck", + "hex", + "once_cell", + "proc-macro2", + "quote", + "serde", + "serde_json", + "sha2", + "sqlx-core", + "sqlx-postgres", + "syn 1.0.109", + "tempfile", + "tokio", + "url", +] + +[[package]] +name = "sqlx-postgres" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c824eb80b894f926f89a0b9da0c7f435d27cdd35b8c655b114e58223918577e" +dependencies = [ + "atoi", + "base64 0.21.7", + "bitflags 2.6.0", + "byteorder", + "crc", + "dotenvy", + "etcetera", + "futures-channel", + "futures-core", + "futures-io", + "futures-util", + "hex", + "hkdf", + "hmac", + "home", + "itoa", + "log", + "md-5", + "memchr", + "once_cell", + "rand", + "serde", + "serde_json", + "sha2", + "smallvec", + "sqlx-core", + "stringprep", + "thiserror", + "tracing", + "whoami", +] + +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + +[[package]] +name = "stringprep" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b4df3d392d81bd458a8a621b8bffbd2302a12ffe288a9d931670948749463b1" +dependencies = [ + "unicode-bidi", + "unicode-normalization", + "unicode-properties", +] + +[[package]] +name = "strum" +version = "0.26.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fec0f0aef304996cf250b31b5a10dee7980c85da9d759361292b8bca5a18f06" + [[package]] name = "subtle" version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "syn" version = "2.0.76" @@ -951,6 +1685,19 @@ dependencies = [ "futures-core", ] +[[package]] +name = "tempfile" +version = "3.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +dependencies = [ + "cfg-if", + "fastrand", + "once_cell", + "rustix", + "windows-sys 0.59.0", +] + [[package]] name = "thiserror" version = "1.0.63" @@ -968,7 +1715,7 @@ checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.76", ] [[package]] @@ -1040,7 +1787,7 @@ dependencies = [ "pin-project-lite", "socket2", "tokio-macros", - "windows-sys", + "windows-sys 0.52.0", ] [[package]] @@ -1051,7 +1798,7 @@ checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.76", ] [[package]] @@ -1060,11 +1807,22 @@ version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" dependencies = [ - "rustls", + "rustls 0.23.12", "rustls-pki-types", "tokio", ] +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + [[package]] name = "tower" version = "0.4.13" @@ -1103,7 +1861,7 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e9cd434a998747dd2c4276bc96ee2e0c7a2eadf3cae88e52be55a05fa9053f5" dependencies = [ - "bitflags", + "bitflags 2.6.0", "bytes", "http", "http-body", @@ -1152,7 +1910,7 @@ checksum = "6293bf33f1977d5ef422c2e02f909eb2c3d7bf921d93557c40d4f1b130b84aa4" dependencies = [ "async-trait", "axum-core", - "base64", + "base64 0.22.1", "futures", "http", "parking_lot", @@ -1197,7 +1955,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.76", ] [[package]] @@ -1241,6 +1999,12 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" +[[package]] +name = "typenum" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" + [[package]] name = "unicode-bidi" version = "0.3.15" @@ -1262,6 +2026,24 @@ dependencies = [ "tinyvec", ] +[[package]] +name = "unicode-properties" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52ea75f83c0137a9b98608359a5f1af8144876eb67bcb1ce837368e906a9f524" + +[[package]] +name = "unicode-segmentation" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202" + +[[package]] +name = "unicode_categories" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39ec24b3121d976906ece63c9daad25b85969647682eee313cb5779fdd69e14e" + [[package]] name = "untrusted" version = "0.9.0" @@ -1298,6 +2080,7 @@ dependencies = [ "axum", "rand", "reqwest", + "sea-orm", "serde", "tokio", "tower-http", @@ -1321,6 +2104,12 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +[[package]] +name = "wasite" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8dad83b4f25e74f184f64c43b150b91efe7647395b42289f38e50566d82855b" + [[package]] name = "wasm-bindgen" version = "0.2.93" @@ -1343,7 +2132,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn", + "syn 2.0.76", "wasm-bindgen-shared", ] @@ -1377,7 +2166,7 @@ checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.76", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -1400,13 +2189,29 @@ dependencies = [ [[package]] name = "webpki-roots" -version = "0.26.2" +version = "0.25.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f20c57d8d7db6d3b86154206ae5d8fba62dd39573114de97c2cb0578251f8e1" + +[[package]] +name = "webpki-roots" +version = "0.26.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c452ad30530b54a4d8e71952716a212b08efd0f3562baa66c29a618b07da7c3" +checksum = "bd7c23921eeb1713a4e851530e9b9756e4fb0e89978582942612524cf09f01cd" dependencies = [ "rustls-pki-types", ] +[[package]] +name = "whoami" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44ab49fad634e88f55bf8f9bb3abd2f27d7204172a112c7c9987e01c1c94ea9" +dependencies = [ + "redox_syscall 0.4.1", + "wasite", +] + [[package]] name = "winapi" version = "0.3.9" @@ -1437,7 +2242,7 @@ checksum = "e400001bb720a623c1c69032f8e3e4cf09984deec740f007dd2b03ec864804b0" dependencies = [ "windows-result", "windows-strings", - "windows-targets", + "windows-targets 0.52.6", ] [[package]] @@ -1446,7 +2251,7 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" dependencies = [ - "windows-targets", + "windows-targets 0.52.6", ] [[package]] @@ -1456,7 +2261,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" dependencies = [ "windows-result", - "windows-targets", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", ] [[package]] @@ -1465,7 +2279,31 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", ] [[package]] @@ -1474,28 +2312,46 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", ] +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + [[package]] name = "windows_aarch64_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + [[package]] name = "windows_aarch64_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + [[package]] name = "windows_i686_gnu" version = "0.52.6" @@ -1508,24 +2364,48 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + [[package]] name = "windows_i686_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + [[package]] name = "windows_x86_64_gnu" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + [[package]] name = "windows_x86_64_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + [[package]] name = "windows_x86_64_msvc" version = "0.52.6" @@ -1550,7 +2430,7 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.76", ] [[package]] diff --git a/vingo/Cargo.toml b/vingo/Cargo.toml index 3a68e17..6b3c4e0 100644 --- a/vingo/Cargo.toml +++ b/vingo/Cargo.toml @@ -7,6 +7,7 @@ edition = "2021" axum = { version = "0.7.5", default-features = false, features = ["tokio", "http1", "tracing", "query" ] } rand = { version = "0.8.5", default-features = false } reqwest = { version = "0.12.7", default-features = false, features = [ "json", "rustls-tls" ] } +sea-orm = { version = "1.0.1", default-features = false, features = [ "sqlx-postgres", "runtime-tokio-rustls" ] } serde = { version = "1.0.209", default-features = false, features = ["derive"] } tokio = { version = "1.39.3", default-features = false, features = ["rt-multi-thread", "macros", "net"] } tower-http = { version = "0.5.2", default-features = false, features = ["trace"] } diff --git a/vingo/src/main.rs b/vingo/src/main.rs index 1dd49e1..ed9d412 100644 --- a/vingo/src/main.rs +++ b/vingo/src/main.rs @@ -5,9 +5,17 @@ mod routes { use routes::auth; use axum::{routing::get, Router}; +use sea_orm::{Database, DatabaseConnection}; use tower_http::trace::TraceLayer; use tower_sessions::{cookie::SameSite, MemoryStore, SessionManagerLayer}; +const DB_URL: &str = "postgres://zess:zess@localhost/zess"; + +#[derive(Clone)] +struct AppState { + db: DatabaseConnection, +} + #[tokio::main] async fn main() { tracing_subscriber::fmt() @@ -17,11 +25,15 @@ async fn main() { let sess_store = MemoryStore::default(); let sess_mw = SessionManagerLayer::new(sess_store).with_same_site(SameSite::Lax); + let db = Database::connect(DB_URL).await.unwrap(); + let state = AppState { db }; + // build our application with a route let app = Router::new() .nest("/api", routes()) .layer(sess_mw) - .layer(TraceLayer::new_for_http()); + .layer(TraceLayer::new_for_http()) + .with_state(state); // run it let listener = tokio::net::TcpListener::bind("127.0.0.1:4000") @@ -31,7 +43,7 @@ async fn main() { axum::serve(listener, app).await.unwrap(); } -fn routes() -> Router { +fn routes() -> Router { Router::new() .route("/login", get(auth::login)) .route("/logout", get(auth::logout)) diff --git a/vingo/src/routes/auth.rs b/vingo/src/routes/auth.rs index c5e8c27..c5306b4 100644 --- a/vingo/src/routes/auth.rs +++ b/vingo/src/routes/auth.rs @@ -10,12 +10,33 @@ use tower_sessions::Session; const ZAUTH_URL: &str = "https://zauth.zeus.gent"; const CALLBACK_URL: &str = "http://localhost:4000/api/auth/callback"; +pub async fn current_user(session: Session) -> Result, StatusCode> { + let username = session + .get::("user") + .await + .unwrap() + .ok_or(StatusCode::INTERNAL_SERVER_ERROR)?; + + Ok(Html(format!("Logged in as {}", username))) +} + pub async fn login(session: Session) -> impl IntoResponse { let state = Alphanumeric.sample_string(&mut rand::thread_rng(), 16); session.insert("state", state.clone()).await.unwrap(); Redirect::to(&format!("{ZAUTH_URL}/oauth/authorize?client_id=tomtest&response_type=code&state={state}&redirect_uri={CALLBACK_URL}")) } +pub async fn logout(session: Session) -> Result, StatusCode> { + let username = session + .get::("user") + .await + .unwrap() + .ok_or(StatusCode::INTERNAL_SERVER_ERROR)?; + + session.clear().await; + Ok(Html("logged out as ".to_owned() + &username)) +} + #[derive(Deserialize, Debug)] pub struct Callback { state: String, @@ -52,18 +73,12 @@ pub async fn callback( let form = [ ("grant_type", "authorization_code"), ("code", ¶ms.code), - ( - "redirect_uri", - CALLBACK_URL, - ), + ("redirect_uri", CALLBACK_URL), ]; let token = client .post(&format!("{ZAUTH_URL}/oauth/token")) - .basic_auth( - "tomtest", - Some("blargh"), - ) + .basic_auth("tomtest", Some("blargh")) .form(&form) .send() .await @@ -92,14 +107,3 @@ pub async fn callback( Ok(Html(format!("Logged in as {}", username))) } - -pub async fn logout(session: Session) -> Result, StatusCode> { - let username = session - .get::("user") - .await - .unwrap() - .ok_or(StatusCode::INTERNAL_SERVER_ERROR)?; - - session.clear().await; - Ok(Html("logged out as ".to_owned() + &username)) -} From 40718f16b2ff093a8adbb7c42849eb5bb918271f Mon Sep 17 00:00:00 2001 From: Hannes Klinckaert Date: Thu, 29 Aug 2024 20:38:03 +0200 Subject: [PATCH 05/31] vingo: add seaorm and user table --- vingo/Cargo.lock | 1080 ++++++++++++++++- vingo/Cargo.toml | 8 +- vingo/handlers/days.go | 52 - vingo/migration/Cargo.toml | 20 + vingo/migration/README.md | 41 + vingo/migration/src/lib.rs | 12 + .../src/m20220101_000001_create_users.rs | 41 + vingo/migration/src/main.rs | 6 + vingo/src/entities/mod.rs | 5 + vingo/src/entities/prelude.rs | 3 + vingo/src/entities/user.rs | 20 + vingo/src/main.rs | 4 +- vingo/src/routes/auth.rs | 60 +- 13 files changed, 1253 insertions(+), 99 deletions(-) delete mode 100644 vingo/handlers/days.go create mode 100644 vingo/migration/Cargo.toml create mode 100644 vingo/migration/README.md create mode 100644 vingo/migration/src/lib.rs create mode 100644 vingo/migration/src/m20220101_000001_create_users.rs create mode 100644 vingo/migration/src/main.rs create mode 100644 vingo/src/entities/mod.rs create mode 100644 vingo/src/entities/prelude.rs create mode 100644 vingo/src/entities/user.rs diff --git a/vingo/Cargo.lock b/vingo/Cargo.lock index 0698083..e0f7bcc 100644 --- a/vingo/Cargo.lock +++ b/vingo/Cargo.lock @@ -30,6 +30,15 @@ dependencies = [ "zerocopy", ] +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + [[package]] name = "aliasable" version = "0.1.3" @@ -42,6 +51,218 @@ version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + +[[package]] +name = "anstream" +version = "0.6.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64e15c1ab1f89faffbf04a634d5e1962e9074f2741eef6d97f3c4e322426d526" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1" + +[[package]] +name = "anstyle-parse" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb47de1e80c2b463c735db5b217a0ddc39d612e7ac9e2e96a5aed1f57616c1cb" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d36fc52c7f6c869915e99412912f22093507da8d9e942ceaf66fe4b7c14422a" +dependencies = [ + "windows-sys 0.52.0", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5bf74e1b6e971609db8ca7a9ce79fd5768ab6ae46441c572e46cf596f59e57f8" +dependencies = [ + "anstyle", + "windows-sys 0.52.0", +] + +[[package]] +name = "async-attributes" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3203e79f4dd9bdda415ed03cf14dae5a2bf775c683a00f94e9cd1faf0f596e5" +dependencies = [ + "quote", + "syn 1.0.109", +] + +[[package]] +name = "async-channel" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81953c529336010edd6d8e358f886d9581267795c61b19475b71314bffa46d35" +dependencies = [ + "concurrent-queue", + "event-listener 2.5.3", + "futures-core", +] + +[[package]] +name = "async-channel" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89b47800b0be77592da0afd425cc03468052844aff33b84e33cc696f64e77b6a" +dependencies = [ + "concurrent-queue", + "event-listener-strategy", + "futures-core", + "pin-project-lite", +] + +[[package]] +name = "async-executor" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7ebdfa2ebdab6b1760375fa7d6f382b9f486eac35fc994625a00e89280bdbb7" +dependencies = [ + "async-task", + "concurrent-queue", + "fastrand 2.1.1", + "futures-lite 2.3.0", + "slab", +] + +[[package]] +name = "async-global-executor" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05b1b633a2115cd122d73b955eadd9916c18c8f510ec9cd1686404c60ad1c29c" +dependencies = [ + "async-channel 2.3.1", + "async-executor", + "async-io 2.3.4", + "async-lock 3.4.0", + "blocking", + "futures-lite 2.3.0", + "once_cell", + "tokio", +] + +[[package]] +name = "async-io" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fc5b45d93ef0529756f812ca52e44c221b35341892d3dcc34132ac02f3dd2af" +dependencies = [ + "async-lock 2.8.0", + "autocfg", + "cfg-if", + "concurrent-queue", + "futures-lite 1.13.0", + "log", + "parking", + "polling 2.8.0", + "rustix 0.37.27", + "slab", + "socket2 0.4.10", + "waker-fn", +] + +[[package]] +name = "async-io" +version = "2.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "444b0228950ee6501b3568d3c93bf1176a1fdbc3b758dcd9475046d30f4dc7e8" +dependencies = [ + "async-lock 3.4.0", + "cfg-if", + "concurrent-queue", + "futures-io", + "futures-lite 2.3.0", + "parking", + "polling 3.7.3", + "rustix 0.38.35", + "slab", + "tracing", + "windows-sys 0.59.0", +] + +[[package]] +name = "async-lock" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "287272293e9d8c41773cec55e365490fe034813a2f172f502d6ddcf75b2f582b" +dependencies = [ + "event-listener 2.5.3", +] + +[[package]] +name = "async-lock" +version = "3.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff6e472cdea888a4bd64f342f09b3f50e1886d32afe8df3d663c01140b811b18" +dependencies = [ + "event-listener 5.3.1", + "event-listener-strategy", + "pin-project-lite", +] + +[[package]] +name = "async-std" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62565bb4402e926b29953c785397c6dc0391b7b446e45008b0049eb43cec6f5d" +dependencies = [ + "async-attributes", + "async-channel 1.9.0", + "async-global-executor", + "async-io 1.13.0", + "async-lock 2.8.0", + "crossbeam-utils", + "futures-channel", + "futures-core", + "futures-io", + "futures-lite 1.13.0", + "gloo-timers", + "kv-log-macro", + "log", + "memchr", + "once_cell", + "pin-project-lite", + "pin-utils", + "slab", + "wasm-bindgen-futures", +] + [[package]] name = "async-stream" version = "0.3.5" @@ -64,6 +285,12 @@ dependencies = [ "syn 2.0.76", ] +[[package]] +name = "async-task" +version = "4.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b75356056920673b02621b35afd0f7dda9306d03c79a30f5c56c44cf256e3de" + [[package]] name = "async-trait" version = "0.1.81" @@ -84,6 +311,12 @@ dependencies = [ "num-traits", ] +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + [[package]] name = "autocfg" version = "1.3.0" @@ -113,6 +346,8 @@ dependencies = [ "pin-project-lite", "rustversion", "serde", + "serde_json", + "serde_path_to_error", "serde_urlencoded", "sync_wrapper 1.0.1", "tokio", @@ -170,6 +405,12 @@ version = "0.22.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" +[[package]] +name = "base64ct" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" + [[package]] name = "bitflags" version = "1.3.2" @@ -181,6 +422,9 @@ name = "bitflags" version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" +dependencies = [ + "serde", +] [[package]] name = "block-buffer" @@ -191,6 +435,19 @@ dependencies = [ "generic-array", ] +[[package]] +name = "blocking" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "703f41c54fc768e63e091340b424302bb1c29ef4aa0c7f10fe849dfb114d29ea" +dependencies = [ + "async-channel 2.3.1", + "async-task", + "futures-io", + "futures-lite 2.3.0", + "piper", +] + [[package]] name = "bumpalo" version = "3.16.0" @@ -224,6 +481,80 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "chrono" +version = "0.4.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "num-traits", + "serde", + "windows-targets 0.52.6", +] + +[[package]] +name = "clap" +version = "4.5.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed6719fffa43d0d87e5fd8caeab59be1554fb028cd30edc88fc4369b17971019" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.5.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "216aec2b177652e3846684cbfe25c9964d18ec45234f0f5da5157b207ed1aab6" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.5.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "501d359d5f3dcaf6ecdeee48833ae73ec6e42723a1e52419c79abf9507eec0a0" +dependencies = [ + "heck 0.5.0", + "proc-macro2", + "quote", + "syn 2.0.76", +] + +[[package]] +name = "clap_lex" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97" + +[[package]] +name = "colorchoice" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0" + +[[package]] +name = "concurrent-queue" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ca0197aee26d1ae37445ee532fefce43251d24cc7c166799f4d46817f1d3973" +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 = "cookie" version = "0.18.1" @@ -235,6 +566,12 @@ dependencies = [ "version_check", ] +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + [[package]] name = "cpufeatures" version = "0.2.13" @@ -284,6 +621,17 @@ dependencies = [ "typenum", ] +[[package]] +name = "der" +version = "0.7.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" +dependencies = [ + "const-oid", + "pem-rfc7468", + "zeroize", +] + [[package]] name = "deranged" version = "0.3.11" @@ -301,6 +649,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", + "const-oid", "crypto-common", "subtle", ] @@ -385,12 +734,53 @@ version = "2.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" +[[package]] +name = "event-listener" +version = "5.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6032be9bd27023a771701cc49f9f053c751055f71efb2e0ae5c15809093675ba" +dependencies = [ + "concurrent-queue", + "parking", + "pin-project-lite", +] + +[[package]] +name = "event-listener-strategy" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f214dc438f977e6d4e3500aaa277f5ad94ca83fbbd9b1a15713ce2344ccc5a1" +dependencies = [ + "event-listener 5.3.1", + "pin-project-lite", +] + +[[package]] +name = "fastrand" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e51093e27b0797c359783294ca4f0a911c270184cb10f85783b118614a1501be" +dependencies = [ + "instant", +] + [[package]] name = "fastrand" version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" +[[package]] +name = "flume" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55ac459de2512911e4b674ce33cf20befaba382d05b62b008afc1c8b57cbf181" +dependencies = [ + "futures-core", + "futures-sink", + "spin", +] + [[package]] name = "fnv" version = "1.0.7" @@ -436,6 +826,17 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + [[package]] name = "futures-intrusive" version = "0.5.0" @@ -453,6 +854,34 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" +[[package]] +name = "futures-lite" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49a9d51ce47660b1e808d3c990b4709f2f415d928835a17dfd16991515c46bce" +dependencies = [ + "fastrand 1.9.0", + "futures-core", + "futures-io", + "memchr", + "parking", + "pin-project-lite", + "waker-fn", +] + +[[package]] +name = "futures-lite" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52527eb5074e35e9339c6b4e8d12600c7128b68fb25dcb9fa9dec18f7c25f3a5" +dependencies = [ + "fastrand 2.1.1", + "futures-core", + "futures-io", + "parking", + "pin-project-lite", +] + [[package]] name = "futures-macro" version = "0.3.30" @@ -521,6 +950,24 @@ version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" +[[package]] +name = "glob" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" + +[[package]] +name = "gloo-timers" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b995a66bb87bebce9a0f4a95aed01daca4872c050bfcb21653361c03bc35e5c" +dependencies = [ + "futures-channel", + "futures-core", + "js-sys", + "wasm-bindgen", +] + [[package]] name = "hashbrown" version = "0.14.5" @@ -549,12 +996,24 @@ dependencies = [ "unicode-segmentation", ] +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + [[package]] name = "hermit-abi" version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" +[[package]] +name = "hermit-abi" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbf6a919d6cf397374f7dfeeea91d974c7c0a7221d0d0f4f20d859d329e53fcc" + [[package]] name = "hex" version = "0.4.3" @@ -685,13 +1144,36 @@ dependencies = [ "http-body", "hyper", "pin-project-lite", - "socket2", + "socket2 0.5.7", "tokio", "tower", "tower-service", "tracing", ] +[[package]] +name = "iana-time-zone" +version = "0.1.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + [[package]] name = "idna" version = "0.5.0" @@ -723,12 +1205,38 @@ dependencies = [ "syn 2.0.76", ] +[[package]] +name = "instant" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0242819d153cba4b4b05a5a8f2a7e9bbf97b6055b2a002b395c96b5ff3c0222" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "io-lifetimes" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2" +dependencies = [ + "hermit-abi 0.3.9", + "libc", + "windows-sys 0.48.0", +] + [[package]] name = "ipnet" version = "2.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" +[[package]] +name = "is_terminal_polyfill" +version = "1.70.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" + [[package]] name = "itoa" version = "1.0.11" @@ -744,11 +1252,23 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "kv-log-macro" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0de8b303297635ad57c9f5059fd9cee7a47f8e8daa09df0fcd07dd39fb22977f" +dependencies = [ + "log", +] + [[package]] name = "lazy_static" version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" +dependencies = [ + "spin", +] [[package]] name = "libc" @@ -756,6 +1276,29 @@ version = "0.2.158" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" +[[package]] +name = "libm" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" + +[[package]] +name = "libsqlite3-sys" +version = "0.27.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4e226dcd58b4be396f7bd3c20da8fdee2911400705297ba7d2d7cc2c30f716" +dependencies = [ + "cc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "linux-raw-sys" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" + [[package]] name = "linux-raw-sys" version = "0.4.14" @@ -778,6 +1321,18 @@ name = "log" version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" +dependencies = [ + "value-bag", +] + +[[package]] +name = "matchers" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" +dependencies = [ + "regex-automata 0.1.10", +] [[package]] name = "matchit" @@ -801,6 +1356,14 @@ version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" +[[package]] +name = "migration" +version = "0.1.0" +dependencies = [ + "async-std", + "sea-orm-migration", +] + [[package]] name = "mime" version = "0.3.17" @@ -828,7 +1391,7 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "80e04d1dcff3aae0704555fe5fee3bcfaf3d1fdf8a7e521d5b9d2b42acb52cec" dependencies = [ - "hermit-abi", + "hermit-abi 0.3.9", "libc", "wasi", "windows-sys 0.52.0", @@ -854,12 +1417,49 @@ dependencies = [ "winapi", ] +[[package]] +name = "num-bigint-dig" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc84195820f291c7697304f3cbdadd1cb7199c0efc917ff5eafd71225c136151" +dependencies = [ + "byteorder", + "lazy_static", + "libm", + "num-integer", + "num-iter", + "num-traits", + "rand", + "smallvec", + "zeroize", +] + [[package]] name = "num-conv" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" +[[package]] +name = "num-integer" +version = "0.1.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-iter" +version = "0.1.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1429034a0490724d0075ebb2bc9e875d6503c3cf69e235a8941aa757d83ef5bf" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + [[package]] name = "num-traits" version = "0.2.19" @@ -867,6 +1467,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", + "libm", ] [[package]] @@ -910,7 +1511,7 @@ version = "0.17.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec4c6225c69b4ca778c0aea097321a64c421cf4577b331c61b229267edabb6f8" dependencies = [ - "heck", + "heck 0.4.1", "proc-macro-error", "proc-macro2", "quote", @@ -923,6 +1524,12 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" +[[package]] +name = "parking" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb813b8af86854136c6922af0598d719255ecb2179515e6e7730d468f05c9cae" + [[package]] name = "parking_lot" version = "0.12.3" @@ -952,6 +1559,15 @@ version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" +[[package]] +name = "pem-rfc7468" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88b39c9bfcfc231068454382784bb460aae594343fb030d46e9f50a645418412" +dependencies = [ + "base64ct", +] + [[package]] name = "percent-encoding" version = "2.3.1" @@ -968,27 +1584,96 @@ dependencies = [ ] [[package]] -name = "pin-project-internal" -version = "1.1.5" +name = "pin-project-internal" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.76", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "piper" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96c8c490f422ef9a4efd2cb5b42b76c8613d7e7dfc1caf667b8a3350a5acc066" +dependencies = [ + "atomic-waker", + "fastrand 2.1.1", + "futures-io", +] + +[[package]] +name = "pkcs1" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8ffb9f10fa047879315e6625af03c164b16962a5368d724ed16323b68ace47f" +dependencies = [ + "der", + "pkcs8", + "spki", +] + +[[package]] +name = "pkcs8" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" +dependencies = [ + "der", + "spki", +] + +[[package]] +name = "pkg-config" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.76", -] +checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" [[package]] -name = "pin-project-lite" -version = "0.2.14" +name = "polling" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" +checksum = "4b2d323e8ca7996b3e23126511a523f7e62924d93ecd5ae73b333815b0eb3dce" +dependencies = [ + "autocfg", + "bitflags 1.3.2", + "cfg-if", + "concurrent-queue", + "libc", + "log", + "pin-project-lite", + "windows-sys 0.48.0", +] [[package]] -name = "pin-utils" -version = "0.1.0" +name = "polling" +version = "3.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +checksum = "cc2790cd301dec6cd3b7a025e4815cf825724a51c98dccfe6a3e55f05ffb6511" +dependencies = [ + "cfg-if", + "concurrent-queue", + "hermit-abi 0.4.0", + "pin-project-lite", + "rustix 0.38.35", + "tracing", + "windows-sys 0.59.0", +] [[package]] name = "powerfmt" @@ -1050,7 +1735,7 @@ dependencies = [ "quinn-udp", "rustc-hash", "rustls 0.23.12", - "socket2", + "socket2 0.5.7", "thiserror", "tokio", "tracing", @@ -1081,7 +1766,7 @@ checksum = "8bffec3605b73c6f1754535084a85229fa8a30f86014e6c81aeec4abb68b0285" dependencies = [ "libc", "once_cell", - "socket2", + "socket2 0.5.7", "tracing", "windows-sys 0.52.0", ] @@ -1143,6 +1828,50 @@ dependencies = [ "bitflags 2.6.0", ] +[[package]] +name = "regex" +version = "1.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata 0.4.7", + "regex-syntax 0.8.4", +] + +[[package]] +name = "regex-automata" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" +dependencies = [ + "regex-syntax 0.6.29", +] + +[[package]] +name = "regex-automata" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax 0.8.4", +] + +[[package]] +name = "regex-syntax" +version = "0.6.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" + +[[package]] +name = "regex-syntax" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" + [[package]] name = "reqwest" version = "0.12.7" @@ -1200,6 +1929,26 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "rsa" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d0e5124fcb30e76a7e79bfee683a2746db83784b86289f6251b54b7950a0dfc" +dependencies = [ + "const-oid", + "digest", + "num-bigint-dig", + "num-integer", + "num-traits", + "pkcs1", + "pkcs8", + "rand_core", + "signature", + "spki", + "subtle", + "zeroize", +] + [[package]] name = "rustc-demangle" version = "0.1.24" @@ -1212,6 +1961,20 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" +[[package]] +name = "rustix" +version = "0.37.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fea8ca367a3a01fe35e6943c400addf443c0f57670e6ec51196f71a4b8762dd2" +dependencies = [ + "bitflags 1.3.2", + "errno", + "io-lifetimes", + "libc", + "linux-raw-sys 0.3.8", + "windows-sys 0.48.0", +] + [[package]] name = "rustix" version = "0.38.35" @@ -1221,7 +1984,7 @@ dependencies = [ "bitflags 2.6.0", "errno", "libc", - "linux-raw-sys", + "linux-raw-sys 0.4.14", "windows-sys 0.52.0", ] @@ -1324,6 +2087,19 @@ dependencies = [ "untrusted", ] +[[package]] +name = "sea-bae" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3bd3534a9978d0aa7edd2808dc1f8f31c4d0ecd31ddf71d997b3c98e9f3c9114" +dependencies = [ + "heck 0.4.1", + "proc-macro-error", + "proc-macro2", + "quote", + "syn 2.0.76", +] + [[package]] name = "sea-orm" version = "1.0.1" @@ -1332,6 +2108,7 @@ checksum = "ea1fee0cf8528dbe6eda29d5798afc522a63b75e44c5b15721e6e64af9c7cc4b" dependencies = [ "async-stream", "async-trait", + "chrono", "futures", "log", "ouroboros", @@ -1346,28 +2123,65 @@ dependencies = [ "url", ] +[[package]] +name = "sea-orm-cli" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f0b8869c75cf3fbb1bd860abb025033cd2e514c5f4fa43e792697cb1fe6c882" +dependencies = [ + "chrono", + "clap", + "dotenvy", + "glob", + "regex", + "sea-schema", + "tracing", + "tracing-subscriber", + "url", +] + [[package]] name = "sea-orm-macros" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8737b566799ed0444f278d13c300c4c6f1a91782f60ff5825a591852d5502030" dependencies = [ - "heck", + "heck 0.4.1", "proc-macro2", "quote", + "sea-bae", "syn 2.0.76", "unicode-ident", ] +[[package]] +name = "sea-orm-migration" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "216643749e26ce27ab6c51d3475f2692981d4a902d34455bcd322f412900df5c" +dependencies = [ + "async-trait", + "clap", + "dotenvy", + "futures", + "sea-orm", + "sea-orm-cli", + "sea-schema", + "tracing", + "tracing-subscriber", +] + [[package]] name = "sea-query" version = "0.31.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7e5073b2cfed767511a57d18115f3b3d8bcb5690bf8c89518caec6cb22c0cd74" dependencies = [ + "chrono", "educe", "inherent", "ordered-float", + "sea-query-derive", ] [[package]] @@ -1376,10 +2190,47 @@ version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "754965d4aee6145bec25d0898e5c931e6c22859789ce62fd85a42a15ed5a8ce3" dependencies = [ + "chrono", "sea-query", "sqlx", ] +[[package]] +name = "sea-query-derive" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25a82fcb49253abcb45cdcb2adf92956060ec0928635eb21b4f7a6d8f25ab0bc" +dependencies = [ + "heck 0.4.1", + "proc-macro2", + "quote", + "syn 2.0.76", + "thiserror", +] + +[[package]] +name = "sea-schema" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad52149fc81836ea7424c3425d8f6ed8ad448dd16d2e4f6a3907ba46f3f2fd78" +dependencies = [ + "futures", + "sea-query", + "sea-schema-derive", +] + +[[package]] +name = "sea-schema-derive" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "debdc8729c37fdbf88472f97fd470393089f997a909e535ff67c544d18cfccf0" +dependencies = [ + "heck 0.4.1", + "proc-macro2", + "quote", + "syn 2.0.76", +] + [[package]] name = "serde" version = "1.0.209" @@ -1412,6 +2263,16 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_path_to_error" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af99884400da37c88f5e9146b7f1fd0fbcae8f6eec4e9da38b67d05486f814a6" +dependencies = [ + "itoa", + "serde", +] + [[package]] name = "serde_urlencoded" version = "0.7.1" @@ -1424,6 +2285,17 @@ dependencies = [ "serde", ] +[[package]] +name = "sha1" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + [[package]] name = "sha2" version = "0.10.8" @@ -1450,6 +2322,16 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" +[[package]] +name = "signature" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" +dependencies = [ + "digest", + "rand_core", +] + [[package]] name = "slab" version = "0.4.9" @@ -1465,6 +2347,16 @@ version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" +[[package]] +name = "socket2" +version = "0.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f7916fc008ca5542385b89a3d3ce689953c143e9304a9bf8beec1de48994c0d" +dependencies = [ + "libc", + "winapi", +] + [[package]] name = "socket2" version = "0.5.7" @@ -1480,6 +2372,19 @@ name = "spin" version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" +dependencies = [ + "lock_api", +] + +[[package]] +name = "spki" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" +dependencies = [ + "base64ct", + "der", +] [[package]] name = "sqlformat" @@ -1499,7 +2404,9 @@ checksum = "c9a2ccff1a000a5a59cd33da541d9f2fdcd9e6e8229cc200565942bff36d0aaa" dependencies = [ "sqlx-core", "sqlx-macros", + "sqlx-mysql", "sqlx-postgres", + "sqlx-sqlite", ] [[package]] @@ -1512,10 +2419,11 @@ dependencies = [ "atoi", "byteorder", "bytes", + "chrono", "crc", "crossbeam-queue", "either", - "event-listener", + "event-listener 2.5.3", "futures-channel", "futures-core", "futures-intrusive", @@ -1565,7 +2473,7 @@ checksum = "5833ef53aaa16d860e92123292f1f6a3d53c34ba8b1969f152ef1a7bb803f3c8" dependencies = [ "dotenvy", "either", - "heck", + "heck 0.4.1", "hex", "once_cell", "proc-macro2", @@ -1574,13 +2482,58 @@ dependencies = [ "serde_json", "sha2", "sqlx-core", + "sqlx-mysql", "sqlx-postgres", + "sqlx-sqlite", "syn 1.0.109", "tempfile", "tokio", "url", ] +[[package]] +name = "sqlx-mysql" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ed31390216d20e538e447a7a9b959e06ed9fc51c37b514b46eb758016ecd418" +dependencies = [ + "atoi", + "base64 0.21.7", + "bitflags 2.6.0", + "byteorder", + "bytes", + "chrono", + "crc", + "digest", + "dotenvy", + "either", + "futures-channel", + "futures-core", + "futures-io", + "futures-util", + "generic-array", + "hex", + "hkdf", + "hmac", + "itoa", + "log", + "md-5", + "memchr", + "once_cell", + "percent-encoding", + "rand", + "rsa", + "serde", + "sha1", + "sha2", + "smallvec", + "sqlx-core", + "stringprep", + "thiserror", + "tracing", + "whoami", +] + [[package]] name = "sqlx-postgres" version = "0.7.4" @@ -1591,6 +2544,7 @@ dependencies = [ "base64 0.21.7", "bitflags 2.6.0", "byteorder", + "chrono", "crc", "dotenvy", "etcetera", @@ -1619,6 +2573,30 @@ dependencies = [ "whoami", ] +[[package]] +name = "sqlx-sqlite" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b244ef0a8414da0bed4bb1910426e890b19e5e9bccc27ada6b797d05c55ae0aa" +dependencies = [ + "atoi", + "chrono", + "flume", + "futures-channel", + "futures-core", + "futures-executor", + "futures-intrusive", + "futures-util", + "libsqlite3-sys", + "log", + "percent-encoding", + "serde", + "sqlx-core", + "tracing", + "url", + "urlencoding", +] + [[package]] name = "static_assertions" version = "1.1.0" @@ -1636,6 +2614,12 @@ dependencies = [ "unicode-properties", ] +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + [[package]] name = "strum" version = "0.26.3" @@ -1692,9 +2676,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" dependencies = [ "cfg-if", - "fastrand", + "fastrand 2.1.1", "once_cell", - "rustix", + "rustix 0.38.35", "windows-sys 0.59.0", ] @@ -1785,7 +2769,7 @@ dependencies = [ "libc", "mio", "pin-project-lite", - "socket2", + "socket2 0.5.7", "tokio-macros", "windows-sys 0.52.0", ] @@ -1985,10 +2969,14 @@ version = "0.3.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b" dependencies = [ + "matchers", "nu-ansi-term", + "once_cell", + "regex", "sharded-slab", "smallvec", "thread_local", + "tracing", "tracing-core", "tracing-log", ] @@ -2061,12 +3049,36 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "urlencoding" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da" + +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + [[package]] name = "valuable" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" +[[package]] +name = "value-bag" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a84c137d37ab0142f0f2ddfe332651fdbf252e7b7dbb4e67b6c1f1b2e925101" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + [[package]] name = "version_check" version = "0.9.5" @@ -2078,6 +3090,7 @@ name = "vingo" version = "0.1.0" dependencies = [ "axum", + "chrono", "rand", "reqwest", "sea-orm", @@ -2089,6 +3102,12 @@ dependencies = [ "tracing-subscriber", ] +[[package]] +name = "waker-fn" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "317211a0dc0ceedd78fb2ca9a44aed3d7b9b26f81870d485c07122b4350673b7" + [[package]] name = "want" version = "0.3.1" @@ -2234,6 +3253,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows-core" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" +dependencies = [ + "windows-targets 0.52.6", +] + [[package]] name = "windows-registry" version = "0.2.0" diff --git a/vingo/Cargo.toml b/vingo/Cargo.toml index 6b3c4e0..9c90e58 100644 --- a/vingo/Cargo.toml +++ b/vingo/Cargo.toml @@ -3,11 +3,15 @@ name = "vingo" version = "0.1.0" edition = "2021" +[workspace] +members = [ "migration" ] + [dependencies] -axum = { version = "0.7.5", default-features = false, features = ["tokio", "http1", "tracing", "query" ] } +axum = { version = "0.7.5", default-features = false, features = ["tokio", "http1", "tracing", "query", "json" ] } +chrono = { version = "0.4.38", default-features = false, features = ["serde"] } rand = { version = "0.8.5", default-features = false } reqwest = { version = "0.12.7", default-features = false, features = [ "json", "rustls-tls" ] } -sea-orm = { version = "1.0.1", default-features = false, features = [ "sqlx-postgres", "runtime-tokio-rustls" ] } +sea-orm = { version = "1.0.1", default-features = false, features = [ "sqlx-postgres", "runtime-tokio-rustls", "macros", "with-chrono"] } serde = { version = "1.0.209", default-features = false, features = ["derive"] } tokio = { version = "1.39.3", default-features = false, features = ["rt-multi-thread", "macros", "net"] } tower-http = { version = "0.5.2", default-features = false, features = ["trace"] } diff --git a/vingo/handlers/days.go b/vingo/handlers/days.go deleted file mode 100644 index d0b8a8b..0000000 --- a/vingo/handlers/days.go +++ /dev/null @@ -1,52 +0,0 @@ -package handlers - -import ( - "time" - "vingo/database" - - "github.com/gofiber/fiber/v2" -) - -type Days struct{} - -type DaysBody struct { - StartDate time.Time `json:"start_date"` - EndDate time.Time `json:"end_date"` -} - -func (Days) CreateMultiple(c *fiber.Ctx) error { - payload := new(DaysBody) - if err := c.BodyParser(payload); err != nil { - logger.Println("Error parsing body:", err) - return c.Status(400).SendString("Error parsing body") - } - - err := database.CreateDays(payload.StartDate, payload.EndDate) - if err != nil { - logger.Println("Error creating days:", err) - return c.Status(500).SendString("Error creating days") - } - - return c.SendStatus(200) -} - -func (Days) Delete(c *fiber.Ctx) error { - day_id := c.Params("id") - err := database.DeleteDay(day_id) - if err != nil { - logger.Println("Error deleting day:", err) - return c.Status(500).SendString("Error deleting day") - } - - return c.SendStatus(200) -} - -func (Days) All(c *fiber.Ctx) error { - days, err := database.GetDays() - if err != nil { - logger.Println("Error getting days:", err) - return c.Status(500).SendString("Error getting days") - } - - return c.JSON(days) -} diff --git a/vingo/migration/Cargo.toml b/vingo/migration/Cargo.toml new file mode 100644 index 0000000..23a5d66 --- /dev/null +++ b/vingo/migration/Cargo.toml @@ -0,0 +1,20 @@ +[package] +name = "migration" +version = "0.1.0" +edition = "2021" +publish = false + +[lib] +name = "migration" +path = "src/lib.rs" + +[dependencies] +async-std = { version = "1", features = ["attributes", "tokio1"] } + +[dependencies.sea-orm-migration] +version = "1.0.0" +features = [ + "sqlx-postgres", + "runtime-tokio-rustls", + "with-chrono", +] diff --git a/vingo/migration/README.md b/vingo/migration/README.md new file mode 100644 index 0000000..3b438d8 --- /dev/null +++ b/vingo/migration/README.md @@ -0,0 +1,41 @@ +# Running Migrator CLI + +- Generate a new migration file + ```sh + cargo run -- generate MIGRATION_NAME + ``` +- Apply all pending migrations + ```sh + cargo run + ``` + ```sh + cargo run -- up + ``` +- Apply first 10 pending migrations + ```sh + cargo run -- up -n 10 + ``` +- Rollback last applied migrations + ```sh + cargo run -- down + ``` +- Rollback last 10 applied migrations + ```sh + cargo run -- down -n 10 + ``` +- Drop all tables from the database, then reapply all migrations + ```sh + cargo run -- fresh + ``` +- Rollback all applied migrations, then reapply all migrations + ```sh + cargo run -- refresh + ``` +- Rollback all applied migrations + ```sh + cargo run -- reset + ``` +- Check the status of all migrations + ```sh + cargo run -- status + ``` diff --git a/vingo/migration/src/lib.rs b/vingo/migration/src/lib.rs new file mode 100644 index 0000000..d691340 --- /dev/null +++ b/vingo/migration/src/lib.rs @@ -0,0 +1,12 @@ +pub use sea_orm_migration::prelude::*; + +mod m20220101_000001_create_users; + +pub struct Migrator; + +#[async_trait::async_trait] +impl MigratorTrait for Migrator { + fn migrations() -> Vec> { + vec![Box::new(m20220101_000001_create_users::Migration)] + } +} diff --git a/vingo/migration/src/m20220101_000001_create_users.rs b/vingo/migration/src/m20220101_000001_create_users.rs new file mode 100644 index 0000000..85b282e --- /dev/null +++ b/vingo/migration/src/m20220101_000001_create_users.rs @@ -0,0 +1,41 @@ +use sea_orm_migration::{prelude::*, schema::*}; + +#[derive(DeriveMigrationName)] +pub struct Migration; + +#[derive(DeriveIden)] +enum User { + Table, + Id, + Name, + Admin, + CreatedAt, +} + +#[async_trait::async_trait] +impl MigrationTrait for Migration { + async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { + // Replace the sample below with your own migration scripts + manager + .create_table( + Table::create() + .table(User::Table) + .col(ColumnDef::new(User::Id).integer().primary_key()) + .col(text(User::Name)) + .col(boolean(User::Admin).default(false)) + .col( + timestamp_with_time_zone(User::CreatedAt) + .default(Expr::current_timestamp()), + ) + .to_owned(), + ) + .await + } + + async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { + // Replace the sample below with your own migration scripts + manager + .drop_table(Table::drop().table(User::Table).to_owned()) + .await + } +} diff --git a/vingo/migration/src/main.rs b/vingo/migration/src/main.rs new file mode 100644 index 0000000..c6b6e48 --- /dev/null +++ b/vingo/migration/src/main.rs @@ -0,0 +1,6 @@ +use sea_orm_migration::prelude::*; + +#[async_std::main] +async fn main() { + cli::run_cli(migration::Migrator).await; +} diff --git a/vingo/src/entities/mod.rs b/vingo/src/entities/mod.rs new file mode 100644 index 0000000..ea71b96 --- /dev/null +++ b/vingo/src/entities/mod.rs @@ -0,0 +1,5 @@ +//! `SeaORM` Entity, @generated by sea-orm-codegen 1.0.1 + +pub mod prelude; + +pub mod user; diff --git a/vingo/src/entities/prelude.rs b/vingo/src/entities/prelude.rs new file mode 100644 index 0000000..48ab431 --- /dev/null +++ b/vingo/src/entities/prelude.rs @@ -0,0 +1,3 @@ +//! `SeaORM` Entity, @generated by sea-orm-codegen 1.0.1 + +pub use super::user::Entity as User; diff --git a/vingo/src/entities/user.rs b/vingo/src/entities/user.rs new file mode 100644 index 0000000..53872bd --- /dev/null +++ b/vingo/src/entities/user.rs @@ -0,0 +1,20 @@ +//! `SeaORM` Entity, @generated by sea-orm-codegen 1.0.1 + +use sea_orm::entity::prelude::*; +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)] +#[sea_orm(table_name = "user")] +pub struct Model { + #[sea_orm(primary_key, auto_increment = false)] + pub id: i32, + #[sea_orm(column_type = "Text")] + pub name: String, + pub admin: bool, + pub created_at: DateTimeWithTimeZone, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation {} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/vingo/src/main.rs b/vingo/src/main.rs index ed9d412..db4f0c7 100644 --- a/vingo/src/main.rs +++ b/vingo/src/main.rs @@ -2,6 +2,7 @@ mod routes { pub mod auth; } +mod entities; use routes::auth; use axum::{routing::get, Router}; @@ -9,7 +10,7 @@ use sea_orm::{Database, DatabaseConnection}; use tower_http::trace::TraceLayer; use tower_sessions::{cookie::SameSite, MemoryStore, SessionManagerLayer}; -const DB_URL: &str = "postgres://zess:zess@localhost/zess"; +const DB_URL: &str = "postgres://postgres:zess@localhost/zess"; #[derive(Clone)] struct AppState { @@ -47,5 +48,6 @@ fn routes() -> Router { Router::new() .route("/login", get(auth::login)) .route("/logout", get(auth::logout)) + .route("/user", get(auth::current_user)) .route("/auth/callback", get(auth::callback)) } diff --git a/vingo/src/routes/auth.rs b/vingo/src/routes/auth.rs index c5306b4..8cf2d41 100644 --- a/vingo/src/routes/auth.rs +++ b/vingo/src/routes/auth.rs @@ -1,23 +1,28 @@ -use std::borrow::Borrow; - -use axum::extract::Query; +use axum::extract::{Query, State}; use axum::response::{Html, IntoResponse, Redirect}; +use axum::Json; +use chrono::Local; use rand::distributions::{Alphanumeric, DistString}; use reqwest::StatusCode; +use sea_orm::sea_query::OnConflict; +use sea_orm::{EntityTrait, Set, TryIntoModel}; use serde::{Deserialize, Serialize}; use tower_sessions::Session; +use crate::entities::{prelude::*, *}; +use crate::AppState; + const ZAUTH_URL: &str = "https://zauth.zeus.gent"; const CALLBACK_URL: &str = "http://localhost:4000/api/auth/callback"; -pub async fn current_user(session: Session) -> Result, StatusCode> { - let username = session - .get::("user") +pub async fn current_user(session: Session) -> Result, StatusCode> { + let user = session + .get::("user") .await .unwrap() .ok_or(StatusCode::INTERNAL_SERVER_ERROR)?; - Ok(Html(format!("Logged in as {}", username))) + Ok(Json(user)) } pub async fn login(session: Session) -> impl IntoResponse { @@ -27,14 +32,14 @@ pub async fn login(session: Session) -> impl IntoResponse { } pub async fn logout(session: Session) -> Result, StatusCode> { - let username = session - .get::("user") + let user = session + .get::("user") .await .unwrap() .ok_or(StatusCode::INTERNAL_SERVER_ERROR)?; session.clear().await; - Ok(Html("logged out as ".to_owned() + &username)) + Ok(Html("logged out as ".to_owned() + &user.name)) } #[derive(Deserialize, Debug)] @@ -46,26 +51,25 @@ pub struct Callback { #[derive(Deserialize, Debug)] pub struct ZauthToken { access_token: String, - token_type: String, - expires_in: u64, } #[derive(Serialize, Deserialize, Debug)] pub struct ZauthUser { - id: u64, + id: i32, username: String, } pub async fn callback( Query(params): Query, session: Session, + state: State, ) -> Result, StatusCode> { - let state = session + let zauth_state = session .get::("state") .await .unwrap() .ok_or(StatusCode::INTERNAL_SERVER_ERROR)?; - if state != params.state { + if zauth_state != params.state { return Err(StatusCode::UNAUTHORIZED); } @@ -89,7 +93,7 @@ pub async fn callback( .await .unwrap(); - let user = client + let zauth_user = client .get(format!("{ZAUTH_URL}/current_user")) .header("Authorization", "Bearer ".to_owned() + &token.access_token) .send() @@ -101,9 +105,29 @@ pub async fn callback( .await .unwrap(); - let username = user.username.clone(); + let db_user = user::ActiveModel { + id: Set(zauth_user.id), + name: Set(zauth_user.username), + admin: Set(false), + created_at: Set(Local::now().into()), + }; + + // update name if user already exists + User::insert(db_user.clone()) + .on_conflict( + OnConflict::column(user::Column::Id) + .update_column(user::Column::Name) + .to_owned(), + ) + .exec(&state.db) + .await + .unwrap(); + + let db_user = db_user.try_into_model().unwrap(); + let username = db_user.name.clone(); + session.clear().await; - session.insert("user", &username).await.unwrap(); + session.insert("user", db_user).await.unwrap(); Ok(Html(format!("Logged in as {}", username))) } From f3a09fc580cecacfbc9d7e83bbaac5e27d10b54f Mon Sep 17 00:00:00 2001 From: Hannes Klinckaert Date: Thu, 29 Aug 2024 21:54:07 +0200 Subject: [PATCH 06/31] vingo: start error handling --- vingo/src/main.rs | 4 +--- vingo/src/routes/auth.rs | 24 +++++++++--------------- vingo/src/routes/mod.rs | 6 ++++++ vingo/src/routes/util/errors.rs | 3 +++ vingo/src/routes/util/session.rs | 15 +++++++++++++++ 5 files changed, 34 insertions(+), 18 deletions(-) create mode 100644 vingo/src/routes/mod.rs create mode 100644 vingo/src/routes/util/errors.rs create mode 100644 vingo/src/routes/util/session.rs diff --git a/vingo/src/main.rs b/vingo/src/main.rs index db4f0c7..417247c 100644 --- a/vingo/src/main.rs +++ b/vingo/src/main.rs @@ -1,6 +1,4 @@ -mod routes { - pub mod auth; -} +mod routes; mod entities; use routes::auth; diff --git a/vingo/src/routes/auth.rs b/vingo/src/routes/auth.rs index 8cf2d41..5b3ebaa 100644 --- a/vingo/src/routes/auth.rs +++ b/vingo/src/routes/auth.rs @@ -8,20 +8,19 @@ use sea_orm::sea_query::OnConflict; use sea_orm::{EntityTrait, Set, TryIntoModel}; use serde::{Deserialize, Serialize}; use tower_sessions::Session; +use user::Model; use crate::entities::{prelude::*, *}; use crate::AppState; +use super::util::session::get_user; +use super::util::errors::ResponseResult; + const ZAUTH_URL: &str = "https://zauth.zeus.gent"; const CALLBACK_URL: &str = "http://localhost:4000/api/auth/callback"; -pub async fn current_user(session: Session) -> Result, StatusCode> { - let user = session - .get::("user") - .await - .unwrap() - .ok_or(StatusCode::INTERNAL_SERVER_ERROR)?; - +pub async fn current_user(session: Session) -> ResponseResult> { + let user = get_user(&session).await?; Ok(Json(user)) } @@ -31,15 +30,10 @@ pub async fn login(session: Session) -> impl IntoResponse { Redirect::to(&format!("{ZAUTH_URL}/oauth/authorize?client_id=tomtest&response_type=code&state={state}&redirect_uri={CALLBACK_URL}")) } -pub async fn logout(session: Session) -> Result, StatusCode> { - let user = session - .get::("user") - .await - .unwrap() - .ok_or(StatusCode::INTERNAL_SERVER_ERROR)?; - +pub async fn logout(session: Session) -> ResponseResult> { + let user = get_user(&session).await?; session.clear().await; - Ok(Html("logged out as ".to_owned() + &user.name)) + Ok(Json(true)) } #[derive(Deserialize, Debug)] diff --git a/vingo/src/routes/mod.rs b/vingo/src/routes/mod.rs new file mode 100644 index 0000000..ef081cd --- /dev/null +++ b/vingo/src/routes/mod.rs @@ -0,0 +1,6 @@ +pub mod auth; + +pub mod util { + pub mod errors; + pub mod session; +} \ No newline at end of file diff --git a/vingo/src/routes/util/errors.rs b/vingo/src/routes/util/errors.rs new file mode 100644 index 0000000..1cb8558 --- /dev/null +++ b/vingo/src/routes/util/errors.rs @@ -0,0 +1,3 @@ +use reqwest::StatusCode; + +pub type ResponseResult = Result; \ No newline at end of file diff --git a/vingo/src/routes/util/session.rs b/vingo/src/routes/util/session.rs new file mode 100644 index 0000000..8c00471 --- /dev/null +++ b/vingo/src/routes/util/session.rs @@ -0,0 +1,15 @@ +use reqwest::StatusCode; +use tower_sessions::Session; +use user::Model; + +use crate::entities::*; +use super::errors::ResponseResult; + +pub async fn get_user(session: &Session) -> ResponseResult { + session + .get("user") + .await + .inspect_err(|e| eprintln!("error: {e}")) + .or(Err((StatusCode::INTERNAL_SERVER_ERROR, "Failed to get session")))? + .ok_or((StatusCode::INTERNAL_SERVER_ERROR, "Not logged in")) +} \ No newline at end of file From 944d4fa50db87f101c3bf248766d96ee471c5802 Mon Sep 17 00:00:00 2001 From: Hannes Klinckaert Date: Thu, 29 Aug 2024 22:51:05 +0200 Subject: [PATCH 07/31] vingo: add error handling and error messages --- vingo/src/main.rs | 1 + vingo/src/routes/auth.rs | 55 ++++++++++++++++++++------------ vingo/src/routes/mod.rs | 2 +- vingo/src/routes/util/errors.rs | 18 ++++++++++- vingo/src/routes/util/session.rs | 9 +++--- 5 files changed, 57 insertions(+), 28 deletions(-) diff --git a/vingo/src/main.rs b/vingo/src/main.rs index 417247c..07b9d37 100644 --- a/vingo/src/main.rs +++ b/vingo/src/main.rs @@ -38,6 +38,7 @@ async fn main() { let listener = tokio::net::TcpListener::bind("127.0.0.1:4000") .await .unwrap(); + println!("listening on {}", listener.local_addr().unwrap()); axum::serve(listener, app).await.unwrap(); } diff --git a/vingo/src/routes/auth.rs b/vingo/src/routes/auth.rs index 5b3ebaa..7f5aea2 100644 --- a/vingo/src/routes/auth.rs +++ b/vingo/src/routes/auth.rs @@ -13,8 +13,8 @@ use user::Model; use crate::entities::{prelude::*, *}; use crate::AppState; +use super::util::errors::{ResponseResult, ResultAndLogError}; use super::util::session::get_user; -use super::util::errors::ResponseResult; const ZAUTH_URL: &str = "https://zauth.zeus.gent"; const CALLBACK_URL: &str = "http://localhost:4000/api/auth/callback"; @@ -24,14 +24,17 @@ pub async fn current_user(session: Session) -> ResponseResult> { Ok(Json(user)) } -pub async fn login(session: Session) -> impl IntoResponse { +pub async fn login(session: Session) -> ResponseResult { let state = Alphanumeric.sample_string(&mut rand::thread_rng(), 16); - session.insert("state", state.clone()).await.unwrap(); - Redirect::to(&format!("{ZAUTH_URL}/oauth/authorize?client_id=tomtest&response_type=code&state={state}&redirect_uri={CALLBACK_URL}")) + // insert state so we can check it in the callback + session.insert("state", state.clone()).await + .or_log((StatusCode::INTERNAL_SERVER_ERROR, "failed to insert state in session"))?; + // redirect to zauth to authenticate + Ok(Redirect::to(&format!("{ZAUTH_URL}/oauth/authorize?client_id=tomtest&response_type=code&state={state}&redirect_uri={CALLBACK_URL}"))) } pub async fn logout(session: Session) -> ResponseResult> { - let user = get_user(&session).await?; + get_user(&session).await?; session.clear().await; Ok(Json(true)) } @@ -57,14 +60,15 @@ pub async fn callback( Query(params): Query, session: Session, state: State, -) -> Result, StatusCode> { +) -> ResponseResult<()> { let zauth_state = session .get::("state") .await - .unwrap() - .ok_or(StatusCode::INTERNAL_SERVER_ERROR)?; + .or_log((StatusCode::INTERNAL_SERVER_ERROR, "failed to get session"))? + .ok_or((StatusCode::INTERNAL_SERVER_ERROR, "state not in session"))?; + // check if saved state matches returned state if zauth_state != params.state { - return Err(StatusCode::UNAUTHORIZED); + return Err((StatusCode::UNAUTHORIZED, "state does not match")); } let client = reqwest::Client::new(); @@ -74,35 +78,43 @@ pub async fn callback( ("redirect_uri", CALLBACK_URL), ]; + // get token from zauth with code let token = client .post(&format!("{ZAUTH_URL}/oauth/token")) .basic_auth("tomtest", Some("blargh")) .form(&form) .send() .await - .unwrap() + .or_log(( + StatusCode::INTERNAL_SERVER_ERROR, + "zauth token request error", + ))? .error_for_status() - .unwrap() + .or_log((StatusCode::INTERNAL_SERVER_ERROR, "non 200 for zauth token"))? .json::() .await - .unwrap(); + .or_log((StatusCode::INTERNAL_SERVER_ERROR, "failed to parse json"))?; + // get user info from zauth let zauth_user = client .get(format!("{ZAUTH_URL}/current_user")) .header("Authorization", "Bearer ".to_owned() + &token.access_token) .send() .await - .unwrap() + .or_log(( + StatusCode::INTERNAL_SERVER_ERROR, + "zauth user request error", + ))? .error_for_status() - .unwrap() + .or_log((StatusCode::INTERNAL_SERVER_ERROR, "non 200 for zauth user"))? .json::() .await - .unwrap(); + .or_log((StatusCode::INTERNAL_SERVER_ERROR, "failed to parse json"))?; let db_user = user::ActiveModel { id: Set(zauth_user.id), name: Set(zauth_user.username), - admin: Set(false), + admin: Set(false), // cant insert if not set, even if default created_at: Set(Local::now().into()), }; @@ -115,13 +127,14 @@ pub async fn callback( ) .exec(&state.db) .await - .unwrap(); + .or_log((StatusCode::INTERNAL_SERVER_ERROR, "user insert error"))?; - let db_user = db_user.try_into_model().unwrap(); - let username = db_user.name.clone(); + let db_user = db_user.try_into_model() + .or_log((StatusCode::INTERNAL_SERVER_ERROR, "user to model failed"))?; session.clear().await; - session.insert("user", db_user).await.unwrap(); + session.insert("user", db_user).await + .or_log((StatusCode::INTERNAL_SERVER_ERROR, "failed to insert user in session"))?; - Ok(Html(format!("Logged in as {}", username))) + Ok(()) } diff --git a/vingo/src/routes/mod.rs b/vingo/src/routes/mod.rs index ef081cd..d2aa22c 100644 --- a/vingo/src/routes/mod.rs +++ b/vingo/src/routes/mod.rs @@ -3,4 +3,4 @@ pub mod auth; pub mod util { pub mod errors; pub mod session; -} \ No newline at end of file +} diff --git a/vingo/src/routes/util/errors.rs b/vingo/src/routes/util/errors.rs index 1cb8558..9928e7d 100644 --- a/vingo/src/routes/util/errors.rs +++ b/vingo/src/routes/util/errors.rs @@ -1,3 +1,19 @@ use reqwest::StatusCode; -pub type ResponseResult = Result; \ No newline at end of file +pub type ResponseResult = Result; + +pub trait ResultAndLogError { + fn or_log(self, err_value: F) -> Result; +} + +impl ResultAndLogError for Result { + fn or_log(self, err_value: F) -> Result { + match self { + Ok(v) => Ok(v), + Err(e) => { + eprintln!("err {e}"); + Err(err_value) + } + } + } +} diff --git a/vingo/src/routes/util/session.rs b/vingo/src/routes/util/session.rs index 8c00471..911d4bf 100644 --- a/vingo/src/routes/util/session.rs +++ b/vingo/src/routes/util/session.rs @@ -2,14 +2,13 @@ use reqwest::StatusCode; use tower_sessions::Session; use user::Model; +use super::errors::{ResponseResult, ResultAndLogError}; use crate::entities::*; -use super::errors::ResponseResult; pub async fn get_user(session: &Session) -> ResponseResult { session .get("user") .await - .inspect_err(|e| eprintln!("error: {e}")) - .or(Err((StatusCode::INTERNAL_SERVER_ERROR, "Failed to get session")))? - .ok_or((StatusCode::INTERNAL_SERVER_ERROR, "Not logged in")) -} \ No newline at end of file + .or_log((StatusCode::INTERNAL_SERVER_ERROR, "Failed to get session"))? + .ok_or((StatusCode::UNAUTHORIZED, "Not logged in")) +} From 74412ceb98c91abd3669d37c0de7851887a30f95 Mon Sep 17 00:00:00 2001 From: Hannes Klinckaert Date: Fri, 30 Aug 2024 02:07:23 +0200 Subject: [PATCH 08/31] vingo: add card table --- vingo/migration/src/lib.rs | 6 ++- .../src/m20220101_000001_create_users.rs | 2 +- .../src/m20240829_234032_create_card.rs | 48 +++++++++++++++++++ vingo/src/entities/card.rs | 37 ++++++++++++++ vingo/src/entities/mod.rs | 1 + vingo/src/entities/prelude.rs | 1 + vingo/src/entities/user.rs | 11 ++++- vingo/src/main.rs | 2 +- vingo/src/routes/auth.rs | 15 ++++-- vingo/src/routes/cards.rs | 0 10 files changed, 114 insertions(+), 9 deletions(-) create mode 100644 vingo/migration/src/m20240829_234032_create_card.rs create mode 100644 vingo/src/entities/card.rs create mode 100644 vingo/src/routes/cards.rs diff --git a/vingo/migration/src/lib.rs b/vingo/migration/src/lib.rs index d691340..a82eec5 100644 --- a/vingo/migration/src/lib.rs +++ b/vingo/migration/src/lib.rs @@ -1,12 +1,16 @@ pub use sea_orm_migration::prelude::*; mod m20220101_000001_create_users; +mod m20240829_234032_create_card; pub struct Migrator; #[async_trait::async_trait] impl MigratorTrait for Migrator { fn migrations() -> Vec> { - vec![Box::new(m20220101_000001_create_users::Migration)] + vec![ + Box::new(m20220101_000001_create_users::Migration), + Box::new(m20240829_234032_create_card::Migration), + ] } } diff --git a/vingo/migration/src/m20220101_000001_create_users.rs b/vingo/migration/src/m20220101_000001_create_users.rs index 85b282e..9be9ec3 100644 --- a/vingo/migration/src/m20220101_000001_create_users.rs +++ b/vingo/migration/src/m20220101_000001_create_users.rs @@ -4,7 +4,7 @@ use sea_orm_migration::{prelude::*, schema::*}; pub struct Migration; #[derive(DeriveIden)] -enum User { +pub enum User { Table, Id, Name, diff --git a/vingo/migration/src/m20240829_234032_create_card.rs b/vingo/migration/src/m20240829_234032_create_card.rs new file mode 100644 index 0000000..ace6e92 --- /dev/null +++ b/vingo/migration/src/m20240829_234032_create_card.rs @@ -0,0 +1,48 @@ +use sea_orm_migration::{prelude::*, schema::*}; + +use crate::m20220101_000001_create_users::User; + +#[derive(DeriveMigrationName)] +pub struct Migration; + +#[derive(DeriveIden)] +enum Card { + Table, + Id, + Serial, + Name, + CreatedAt, + UserId, +} + +#[async_trait::async_trait] +impl MigrationTrait for Migration { + async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { + manager + .create_table( + Table::create() + .table(Card::Table) + .col(pk_auto(Card::Id)) + .col(text_uniq(Card::Serial)) + .col(text(Card::Name).default("")) + .col( + timestamp_with_time_zone(Card::CreatedAt) + .default(Expr::current_timestamp()), + ) + .col(integer(Card::UserId)) + .foreign_key( + ForeignKey::create() + .from(Card::Table, Card::UserId) + .to(User::Table, User::Id), + ) + .to_owned(), + ) + .await + } + + async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { + manager + .drop_table(Table::drop().table(Card::Table).to_owned()) + .await + } +} diff --git a/vingo/src/entities/card.rs b/vingo/src/entities/card.rs new file mode 100644 index 0000000..571e218 --- /dev/null +++ b/vingo/src/entities/card.rs @@ -0,0 +1,37 @@ +//! `SeaORM` Entity, @generated by sea-orm-codegen 1.0.1 + +use sea_orm::entity::prelude::*; +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)] +#[sea_orm(table_name = "card")] +pub struct Model { + #[sea_orm(primary_key)] + pub id: i32, + #[sea_orm(column_type = "Text", unique)] + pub serial: String, + #[sea_orm(column_type = "Text")] + pub name: String, + pub created_at: DateTimeWithTimeZone, + pub user_id: i32, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation { + #[sea_orm( + belongs_to = "super::user::Entity", + from = "Column::UserId", + to = "super::user::Column::Id", + on_update = "NoAction", + on_delete = "NoAction" + )] + User, +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::User.def() + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/vingo/src/entities/mod.rs b/vingo/src/entities/mod.rs index ea71b96..aea4caf 100644 --- a/vingo/src/entities/mod.rs +++ b/vingo/src/entities/mod.rs @@ -2,4 +2,5 @@ pub mod prelude; +pub mod card; pub mod user; diff --git a/vingo/src/entities/prelude.rs b/vingo/src/entities/prelude.rs index 48ab431..346d85b 100644 --- a/vingo/src/entities/prelude.rs +++ b/vingo/src/entities/prelude.rs @@ -1,3 +1,4 @@ //! `SeaORM` Entity, @generated by sea-orm-codegen 1.0.1 +pub use super::card::Entity as Card; pub use super::user::Entity as User; diff --git a/vingo/src/entities/user.rs b/vingo/src/entities/user.rs index 53872bd..8a2bae9 100644 --- a/vingo/src/entities/user.rs +++ b/vingo/src/entities/user.rs @@ -15,6 +15,15 @@ pub struct Model { } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] -pub enum Relation {} +pub enum Relation { + #[sea_orm(has_many = "super::card::Entity")] + Card, +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Card.def() + } +} impl ActiveModelBehavior for ActiveModel {} diff --git a/vingo/src/main.rs b/vingo/src/main.rs index 07b9d37..228d057 100644 --- a/vingo/src/main.rs +++ b/vingo/src/main.rs @@ -38,7 +38,7 @@ async fn main() { let listener = tokio::net::TcpListener::bind("127.0.0.1:4000") .await .unwrap(); - + println!("listening on {}", listener.local_addr().unwrap()); axum::serve(listener, app).await.unwrap(); } diff --git a/vingo/src/routes/auth.rs b/vingo/src/routes/auth.rs index 7f5aea2..35e869a 100644 --- a/vingo/src/routes/auth.rs +++ b/vingo/src/routes/auth.rs @@ -27,8 +27,10 @@ pub async fn current_user(session: Session) -> ResponseResult> { pub async fn login(session: Session) -> ResponseResult { let state = Alphanumeric.sample_string(&mut rand::thread_rng(), 16); // insert state so we can check it in the callback - session.insert("state", state.clone()).await - .or_log((StatusCode::INTERNAL_SERVER_ERROR, "failed to insert state in session"))?; + session.insert("state", state.clone()).await.or_log(( + StatusCode::INTERNAL_SERVER_ERROR, + "failed to insert state in session", + ))?; // redirect to zauth to authenticate Ok(Redirect::to(&format!("{ZAUTH_URL}/oauth/authorize?client_id=tomtest&response_type=code&state={state}&redirect_uri={CALLBACK_URL}"))) } @@ -129,12 +131,15 @@ pub async fn callback( .await .or_log((StatusCode::INTERNAL_SERVER_ERROR, "user insert error"))?; - let db_user = db_user.try_into_model() + let db_user = db_user + .try_into_model() .or_log((StatusCode::INTERNAL_SERVER_ERROR, "user to model failed"))?; session.clear().await; - session.insert("user", db_user).await - .or_log((StatusCode::INTERNAL_SERVER_ERROR, "failed to insert user in session"))?; + session.insert("user", db_user).await.or_log(( + StatusCode::INTERNAL_SERVER_ERROR, + "failed to insert user in session", + ))?; Ok(()) } diff --git a/vingo/src/routes/cards.rs b/vingo/src/routes/cards.rs new file mode 100644 index 0000000..e69de29 From 740cca4d85f2dfc0bc3b34dd2610bfd7c4553c16 Mon Sep 17 00:00:00 2001 From: Hannes Klinckaert Date: Fri, 30 Aug 2024 02:57:32 +0200 Subject: [PATCH 09/31] vingo: add card endpoints --- vingo/src/main.rs | 9 ++++-- vingo/src/routes/auth.rs | 2 +- vingo/src/routes/cards.rs | 59 +++++++++++++++++++++++++++++++++++++++ vingo/src/routes/mod.rs | 1 + 4 files changed, 68 insertions(+), 3 deletions(-) diff --git a/vingo/src/main.rs b/vingo/src/main.rs index 228d057..85f1ba7 100644 --- a/vingo/src/main.rs +++ b/vingo/src/main.rs @@ -1,9 +1,12 @@ mod routes; mod entities; -use routes::auth; +use routes::{auth, cards}; -use axum::{routing::get, Router}; +use axum::{ + routing::{get, post}, + Router, +}; use sea_orm::{Database, DatabaseConnection}; use tower_http::trace::TraceLayer; use tower_sessions::{cookie::SameSite, MemoryStore, SessionManagerLayer}; @@ -49,4 +52,6 @@ fn routes() -> Router { .route("/logout", get(auth::logout)) .route("/user", get(auth::current_user)) .route("/auth/callback", get(auth::callback)) + .route("/cards", get(cards::get_for_current_user)) + .route("/cards/:card_id", post(cards::update)) } diff --git a/vingo/src/routes/auth.rs b/vingo/src/routes/auth.rs index 35e869a..2474be8 100644 --- a/vingo/src/routes/auth.rs +++ b/vingo/src/routes/auth.rs @@ -1,5 +1,5 @@ use axum::extract::{Query, State}; -use axum::response::{Html, IntoResponse, Redirect}; +use axum::response::Redirect; use axum::Json; use chrono::Local; use rand::distributions::{Alphanumeric, DistString}; diff --git a/vingo/src/routes/cards.rs b/vingo/src/routes/cards.rs index e69de29..b3ac329 100644 --- a/vingo/src/routes/cards.rs +++ b/vingo/src/routes/cards.rs @@ -0,0 +1,59 @@ +use axum::{ + extract::{Path, State}, + Json, +}; +use reqwest::StatusCode; +use sea_orm::*; +use serde::{Deserialize, Serialize}; +use tower_sessions::Session; + +use super::util::{ + errors::{ResponseResult, ResultAndLogError}, + session::get_user, +}; +use crate::{ + entities::{prelude::*, *}, + AppState, +}; + +pub async fn get_for_current_user( + session: Session, + state: State, +) -> ResponseResult>> { + let user = get_user(&session).await?; + let cards = Card::find() + .filter(card::Column::UserId.eq(user.id)) + .all(&state.db) + .await + .or_log((StatusCode::INTERNAL_SERVER_ERROR, "failed to get cards"))?; + + Ok(Json(cards)) +} + +#[derive(Debug, Serialize, Deserialize)] +pub struct CardUpdate { + name: String, +} + +pub async fn update( + session: Session, + state: State, + Path(card_id): Path, + Json(new_card): Json, +) -> ResponseResult<()> { + let user = get_user(&session).await?; + let mut card = Card::find_by_id(card_id) + .filter(card::Column::UserId.eq(user.id)) + .one(&state.db) + .await + .or_log((StatusCode::INTERNAL_SERVER_ERROR, "failed to get card"))? + .ok_or((StatusCode::NOT_FOUND, "card not found"))? + .into_active_model(); + + card.name = Set(new_card.name); + card.update(&state.db) + .await + .or_log((StatusCode::INTERNAL_SERVER_ERROR, "failed to update card"))?; + + Ok(()) +} diff --git a/vingo/src/routes/mod.rs b/vingo/src/routes/mod.rs index d2aa22c..8ae2a8b 100644 --- a/vingo/src/routes/mod.rs +++ b/vingo/src/routes/mod.rs @@ -1,4 +1,5 @@ pub mod auth; +pub mod cards; pub mod util { pub mod errors; From def603aba276d5f6f514ea4f9ce317c15bd76c1a Mon Sep 17 00:00:00 2001 From: Hannes Klinckaert Date: Tue, 3 Sep 2024 21:57:41 +0200 Subject: [PATCH 10/31] vingo: add card registering --- vingo/Cargo.lock | 1 + vingo/Cargo.toml | 2 ++ vingo/src/main.rs | 41 ++++++++++++++++++++++++++++++++------ vingo/src/routes/auth.rs | 5 +++-- vingo/src/routes/cards.rs | 21 +++++++++++++++++++- vingo/src/routes/scans.rs | 42 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 103 insertions(+), 9 deletions(-) create mode 100644 vingo/src/routes/scans.rs diff --git a/vingo/Cargo.lock b/vingo/Cargo.lock index e0f7bcc..bf6ed25 100644 --- a/vingo/Cargo.lock +++ b/vingo/Cargo.lock @@ -3091,6 +3091,7 @@ version = "0.1.0" dependencies = [ "axum", "chrono", + "migration", "rand", "reqwest", "sea-orm", diff --git a/vingo/Cargo.toml b/vingo/Cargo.toml index 9c90e58..49e8c8f 100644 --- a/vingo/Cargo.toml +++ b/vingo/Cargo.toml @@ -19,3 +19,5 @@ tower-sessions = { version = "0.12.3", default-features = false, features = ["me tracing = "0.1.37" tracing-subscriber = "0.3.16" + +migration = { path = "migration"} diff --git a/vingo/src/main.rs b/vingo/src/main.rs index 85f1ba7..2353170 100644 --- a/vingo/src/main.rs +++ b/vingo/src/main.rs @@ -1,21 +1,36 @@ mod routes; mod entities; -use routes::{auth, cards}; + +use std::sync::Arc; + +use chrono::{FixedOffset, Local, TimeDelta}; +use routes::{auth, cards, scans}; use axum::{ routing::{get, post}, Router, }; -use sea_orm::{Database, DatabaseConnection}; +use sea_orm::{prelude::DateTimeWithTimeZone, Database, DatabaseConnection}; +use tokio::sync::Mutex; use tower_http::trace::TraceLayer; use tower_sessions::{cookie::SameSite, MemoryStore, SessionManagerLayer}; +use migration::{Migrator, MigratorTrait}; + const DB_URL: &str = "postgres://postgres:zess@localhost/zess"; -#[derive(Clone)] +#[derive(Clone, Debug)] struct AppState { db: DatabaseConnection, + registering: Arc>, +} + +#[derive(Clone, Debug)] +struct RegisterState { + user: i32, + end: DateTimeWithTimeZone, + last_success: bool, } #[tokio::main] @@ -25,10 +40,22 @@ async fn main() { .init(); let sess_store = MemoryStore::default(); - let sess_mw = SessionManagerLayer::new(sess_store).with_same_site(SameSite::Lax); + let sess_mw = SessionManagerLayer::new(sess_store) + .with_same_site(SameSite::Lax) + .with_http_only(false); let db = Database::connect(DB_URL).await.unwrap(); - let state = AppState { db }; + Migrator::up(&db, None).await.unwrap(); + + let registering_state = RegisterState { + user: -1, + end: Local::now().fixed_offset() - TimeDelta::minutes(1), + last_success: false, + }; + let state = AppState { + db, + registering: Arc::new(Mutex::new(registering_state)), + }; // build our application with a route let app = Router::new() @@ -48,10 +75,12 @@ async fn main() { fn routes() -> Router { Router::new() - .route("/login", get(auth::login)) + .route("/login", post(auth::login)) .route("/logout", get(auth::logout)) .route("/user", get(auth::current_user)) .route("/auth/callback", get(auth::callback)) .route("/cards", get(cards::get_for_current_user)) .route("/cards/:card_id", post(cards::update)) + .route("/cards/register", get(cards::start_register)) + .route("/scans", post(scans::add)) } diff --git a/vingo/src/routes/auth.rs b/vingo/src/routes/auth.rs index 2474be8..4b840d6 100644 --- a/vingo/src/routes/auth.rs +++ b/vingo/src/routes/auth.rs @@ -18,6 +18,7 @@ use super::util::session::get_user; const ZAUTH_URL: &str = "https://zauth.zeus.gent"; const CALLBACK_URL: &str = "http://localhost:4000/api/auth/callback"; +const FRONTEND_URL: &str = "http://localhost:5173"; pub async fn current_user(session: Session) -> ResponseResult> { let user = get_user(&session).await?; @@ -62,7 +63,7 @@ pub async fn callback( Query(params): Query, session: Session, state: State, -) -> ResponseResult<()> { +) -> ResponseResult { let zauth_state = session .get::("state") .await @@ -141,5 +142,5 @@ pub async fn callback( "failed to insert user in session", ))?; - Ok(()) + Ok(Redirect::to(FRONTEND_URL)) } diff --git a/vingo/src/routes/cards.rs b/vingo/src/routes/cards.rs index b3ac329..718af36 100644 --- a/vingo/src/routes/cards.rs +++ b/vingo/src/routes/cards.rs @@ -1,7 +1,10 @@ +use std::sync::Mutex; + use axum::{ extract::{Path, State}, - Json, + Extension, Json, }; +use chrono::{Local, TimeDelta}; use reqwest::StatusCode; use sea_orm::*; use serde::{Deserialize, Serialize}; @@ -30,6 +33,22 @@ pub async fn get_for_current_user( Ok(Json(cards)) } +pub async fn start_register(session: Session, state: State) -> ResponseResult<()> { + let user = get_user(&session).await?; + let mut registering = state.registering.lock().await; + if Local::now() < registering.end { + Err(( + StatusCode::SERVICE_UNAVAILABLE, + "someone is already registering a card", + ))? + } + + registering.user = user.id; + registering.end = Local::now().fixed_offset() + TimeDelta::minutes(1); + + Ok(()) +} + #[derive(Debug, Serialize, Deserialize)] pub struct CardUpdate { name: String, diff --git a/vingo/src/routes/scans.rs b/vingo/src/routes/scans.rs new file mode 100644 index 0000000..cec63ce --- /dev/null +++ b/vingo/src/routes/scans.rs @@ -0,0 +1,42 @@ +use crate::{entities::card, AppState}; +use axum::extract::State; +use chrono::Local; +use reqwest::StatusCode; +use sea_orm::{ActiveModelTrait, Set}; + +use super::util::errors::{ResponseResult, ResultAndLogError}; + +const SCAN_KEY: &str = "bad_key"; + +pub async fn add(state: State, body: String) -> ResponseResult { + let (serial, key) = body + .split_once(";") + .ok_or((StatusCode::BAD_REQUEST, "invalid format: serial;key"))?; + if key != SCAN_KEY { + Err((StatusCode::UNAUTHORIZED, "invalid key"))? + } + + let mut registering = state.registering.lock().await; + dbg!(®istering); + + // if someone is registering a card + if Local::now() < registering.end { + let db_result = card::ActiveModel { + serial: Set(serial.to_owned()), + user_id: Set(registering.user), + ..Default::default() + } + .insert(&state.db) + .await; + + // end registering session + registering.user = -1; + registering.end = Local::now().fixed_offset(); + registering.last_success = db_result.is_ok(); + + db_result.or_log((StatusCode::INTERNAL_SERVER_ERROR, "failed to insert card"))?; + return Ok("card registered".to_string()); + } + + Ok(body) +} From 9320ec1213d8625f982c07c3151e45d17d9e0650 Mon Sep 17 00:00:00 2001 From: Hannes Klinckaert Date: Tue, 3 Sep 2024 21:58:21 +0200 Subject: [PATCH 11/31] vinvoor: fix cookie name --- vinvoor/src/providers/UserProvider.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vinvoor/src/providers/UserProvider.tsx b/vinvoor/src/providers/UserProvider.tsx index 93fc6d6..0cd3396 100644 --- a/vinvoor/src/providers/UserProvider.tsx +++ b/vinvoor/src/providers/UserProvider.tsx @@ -30,7 +30,7 @@ export const UserProvider: FC = ({ children }) => { const [error, setError] = useState>(undefined); useEffect(() => { - const sessionId = Cookies.get("session_id"); + const sessionId = Cookies.get("id"); if (!sessionId) { setLoading(false); @@ -41,7 +41,7 @@ export const UserProvider: FC = ({ children }) => { getApi("user") .then(data => setUser(data)) .catch(error => { - Cookies.remove("session_id"); + Cookies.remove("id"); setUser(undefined); if (!isResponseNot200Error(error)) setError(error as Error); }) From 5bca63a959972dca8221f7622acababaa4c7d756 Mon Sep 17 00:00:00 2001 From: Hannes Klinckaert Date: Tue, 3 Sep 2024 23:27:42 +0200 Subject: [PATCH 12/31] vingo: add scans endpoints --- vingo/migration/src/lib.rs | 2 + .../src/m20240829_234032_create_card.rs | 2 +- .../src/m20240903_194156_create_scan.rs | 43 +++++++++++++++ vingo/src/entities/card.rs | 8 +++ vingo/src/entities/mod.rs | 1 + vingo/src/entities/prelude.rs | 1 + vingo/src/entities/scan.rs | 34 ++++++++++++ vingo/src/main.rs | 11 ++-- vingo/src/routes/cards.rs | 4 +- vingo/src/routes/mod.rs | 1 + vingo/src/routes/scans.rs | 54 +++++++++++++++---- 11 files changed, 143 insertions(+), 18 deletions(-) create mode 100644 vingo/migration/src/m20240903_194156_create_scan.rs create mode 100644 vingo/src/entities/scan.rs diff --git a/vingo/migration/src/lib.rs b/vingo/migration/src/lib.rs index a82eec5..aa5bca8 100644 --- a/vingo/migration/src/lib.rs +++ b/vingo/migration/src/lib.rs @@ -2,6 +2,7 @@ pub use sea_orm_migration::prelude::*; mod m20220101_000001_create_users; mod m20240829_234032_create_card; +mod m20240903_194156_create_scan; pub struct Migrator; @@ -11,6 +12,7 @@ impl MigratorTrait for Migrator { vec![ Box::new(m20220101_000001_create_users::Migration), Box::new(m20240829_234032_create_card::Migration), + Box::new(m20240903_194156_create_scan::Migration), ] } } diff --git a/vingo/migration/src/m20240829_234032_create_card.rs b/vingo/migration/src/m20240829_234032_create_card.rs index ace6e92..d36703a 100644 --- a/vingo/migration/src/m20240829_234032_create_card.rs +++ b/vingo/migration/src/m20240829_234032_create_card.rs @@ -6,7 +6,7 @@ use crate::m20220101_000001_create_users::User; pub struct Migration; #[derive(DeriveIden)] -enum Card { +pub enum Card { Table, Id, Serial, diff --git a/vingo/migration/src/m20240903_194156_create_scan.rs b/vingo/migration/src/m20240903_194156_create_scan.rs new file mode 100644 index 0000000..4ac9605 --- /dev/null +++ b/vingo/migration/src/m20240903_194156_create_scan.rs @@ -0,0 +1,43 @@ +use crate::m20240829_234032_create_card::Card; +use sea_orm_migration::{prelude::*, schema::*}; + +#[derive(DeriveMigrationName)] +pub struct Migration; + +#[derive(DeriveIden)] +enum Scan { + Table, + Id, + ScanTime, + CardSerial, +} + +#[async_trait::async_trait] +impl MigrationTrait for Migration { + async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { + // Replace the sample below with your own migration scripts + manager + .create_table( + Table::create() + .table(Scan::Table) + .col(pk_auto(Scan::Id)) + .col(text(Scan::CardSerial)) + .col( + timestamp_with_time_zone(Scan::ScanTime).default(Expr::current_timestamp()), + ) + .foreign_key( + ForeignKey::create() + .from(Scan::Table, Scan::CardSerial) + .to(Card::Table, Card::Serial), + ) + .to_owned(), + ) + .await + } + + async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { + manager + .drop_table(Table::drop().table(Scan::Table).to_owned()) + .await + } +} diff --git a/vingo/src/entities/card.rs b/vingo/src/entities/card.rs index 571e218..36d6321 100644 --- a/vingo/src/entities/card.rs +++ b/vingo/src/entities/card.rs @@ -18,6 +18,8 @@ pub struct Model { #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] pub enum Relation { + #[sea_orm(has_one = "super::scan::Entity")] + Scan, #[sea_orm( belongs_to = "super::user::Entity", from = "Column::UserId", @@ -28,6 +30,12 @@ pub enum Relation { User, } +impl Related for Entity { + fn to() -> RelationDef { + Relation::Scan.def() + } +} + impl Related for Entity { fn to() -> RelationDef { Relation::User.def() diff --git a/vingo/src/entities/mod.rs b/vingo/src/entities/mod.rs index aea4caf..2158412 100644 --- a/vingo/src/entities/mod.rs +++ b/vingo/src/entities/mod.rs @@ -3,4 +3,5 @@ pub mod prelude; pub mod card; +pub mod scan; pub mod user; diff --git a/vingo/src/entities/prelude.rs b/vingo/src/entities/prelude.rs index 346d85b..f282b4e 100644 --- a/vingo/src/entities/prelude.rs +++ b/vingo/src/entities/prelude.rs @@ -1,4 +1,5 @@ //! `SeaORM` Entity, @generated by sea-orm-codegen 1.0.1 pub use super::card::Entity as Card; +pub use super::scan::Entity as Scan; pub use super::user::Entity as User; diff --git a/vingo/src/entities/scan.rs b/vingo/src/entities/scan.rs new file mode 100644 index 0000000..842158b --- /dev/null +++ b/vingo/src/entities/scan.rs @@ -0,0 +1,34 @@ +//! `SeaORM` Entity, @generated by sea-orm-codegen 1.0.1 + +use sea_orm::entity::prelude::*; +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)] +#[sea_orm(table_name = "scan")] +pub struct Model { + #[sea_orm(primary_key)] + pub id: i32, + #[sea_orm(column_type = "Text", unique)] + pub card_serial: String, + pub scan_time: DateTimeWithTimeZone, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation { + #[sea_orm( + belongs_to = "super::card::Entity", + from = "Column::CardSerial", + to = "super::card::Column::Serial", + on_update = "NoAction", + on_delete = "NoAction" + )] + Card, +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Card.def() + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/vingo/src/main.rs b/vingo/src/main.rs index 2353170..6f960df 100644 --- a/vingo/src/main.rs +++ b/vingo/src/main.rs @@ -4,11 +4,11 @@ mod entities; use std::sync::Arc; -use chrono::{FixedOffset, Local, TimeDelta}; +use chrono::Local; use routes::{auth, cards, scans}; use axum::{ - routing::{get, post}, + routing::{get, patch, post}, Router, }; use sea_orm::{prelude::DateTimeWithTimeZone, Database, DatabaseConnection}; @@ -49,7 +49,7 @@ async fn main() { let registering_state = RegisterState { user: -1, - end: Local::now().fixed_offset() - TimeDelta::minutes(1), + end: Local::now().fixed_offset(), last_success: false, }; let state = AppState { @@ -80,7 +80,8 @@ fn routes() -> Router { .route("/user", get(auth::current_user)) .route("/auth/callback", get(auth::callback)) .route("/cards", get(cards::get_for_current_user)) - .route("/cards/:card_id", post(cards::update)) - .route("/cards/register", get(cards::start_register)) + .route("/cards/:card_id", patch(cards::update)) + .route("/cards/register", post(cards::start_register)) + .route("/scans", get(scans::get_for_current_user)) .route("/scans", post(scans::add)) } diff --git a/vingo/src/routes/cards.rs b/vingo/src/routes/cards.rs index 718af36..097304e 100644 --- a/vingo/src/routes/cards.rs +++ b/vingo/src/routes/cards.rs @@ -1,8 +1,6 @@ -use std::sync::Mutex; - use axum::{ extract::{Path, State}, - Extension, Json, + Json, }; use chrono::{Local, TimeDelta}; use reqwest::StatusCode; diff --git a/vingo/src/routes/mod.rs b/vingo/src/routes/mod.rs index 8ae2a8b..036eedc 100644 --- a/vingo/src/routes/mod.rs +++ b/vingo/src/routes/mod.rs @@ -1,5 +1,6 @@ pub mod auth; pub mod cards; +pub mod scans; pub mod util { pub mod errors; diff --git a/vingo/src/routes/scans.rs b/vingo/src/routes/scans.rs index cec63ce..e23c5b7 100644 --- a/vingo/src/routes/scans.rs +++ b/vingo/src/routes/scans.rs @@ -1,16 +1,43 @@ -use crate::{entities::card, AppState}; -use axum::extract::State; +use crate::{ + entities::{prelude::*, *}, + AppState, +}; + +use axum::{extract::State, Json}; use chrono::Local; use reqwest::StatusCode; -use sea_orm::{ActiveModelTrait, Set}; +use sea_orm::{ + ActiveModelTrait, ColumnTrait, EntityTrait, JoinType::InnerJoin, QueryFilter, QuerySelect, + RelationTrait, Set, +}; +use tower_sessions::Session; -use super::util::errors::{ResponseResult, ResultAndLogError}; +use super::util::{ + errors::{ResponseResult, ResultAndLogError}, + session::get_user, +}; const SCAN_KEY: &str = "bad_key"; +pub async fn get_for_current_user( + session: Session, + state: State, +) -> ResponseResult>> { + let user = get_user(&session).await?; + let scans = Scan::find() + .join(InnerJoin, scan::Relation::Card.def()) + .join(InnerJoin, card::Relation::User.def()) + .filter(user::Column::Id.eq(user.id)) + .all(&state.db) + .await + .or_log((StatusCode::INTERNAL_SERVER_ERROR, "failed to get scans"))?; + + Ok(Json(scans)) +} + pub async fn add(state: State, body: String) -> ResponseResult { let (serial, key) = body - .split_once(";") + .split_once(';') .ok_or((StatusCode::BAD_REQUEST, "invalid format: serial;key"))?; if key != SCAN_KEY { Err((StatusCode::UNAUTHORIZED, "invalid key"))? @@ -20,7 +47,8 @@ pub async fn add(state: State, body: String) -> ResponseResult dbg!(®istering); // if someone is registering a card - if Local::now() < registering.end { + if Local::now().fixed_offset() < registering.end { + dbg!("ohno registering"); let db_result = card::ActiveModel { serial: Set(serial.to_owned()), user_id: Set(registering.user), @@ -35,8 +63,16 @@ pub async fn add(state: State, body: String) -> ResponseResult registering.last_success = db_result.is_ok(); db_result.or_log((StatusCode::INTERNAL_SERVER_ERROR, "failed to insert card"))?; - return Ok("card registered".to_string()); + Ok("card registered".to_string()) + } else { + scan::ActiveModel { + card_serial: Set(serial.to_string()), + scan_time: Set(Local::now().fixed_offset()), + ..Default::default() + } + .insert(&state.db) + .await + .or_log((StatusCode::INTERNAL_SERVER_ERROR, "failed to insert scan"))?; + Ok("scanned".to_string()) } - - Ok(body) } From a48d7dd2d43dde7d86d0ce0f228b2a1690926ac9 Mon Sep 17 00:00:00 2001 From: Topvennie Date: Tue, 3 Sep 2024 23:36:48 +0200 Subject: [PATCH 13/31] vinvoor: json snake_case --- vinvoor/src/types/leaderboard.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/vinvoor/src/types/leaderboard.ts b/vinvoor/src/types/leaderboard.ts index 4f8ae81..8e2960f 100644 --- a/vinvoor/src/types/leaderboard.ts +++ b/vinvoor/src/types/leaderboard.ts @@ -14,10 +14,10 @@ export interface LeaderboardItemJSON { export interface LeaderboardItem { position: number; - userId: number; + user_id: number; username: string; - totalDays: number; - positionChange: number; + total_days: number; + position_change: number; } // Converters @@ -36,7 +36,7 @@ export const convertLeaderboardItemJSON = ( export const leaderboardHeadCells: readonly TableHeadCell[] = [ { - id: "positionChange", + id: "position_change", label: "Change", align: "right", padding: "checkbox", @@ -54,7 +54,7 @@ export const leaderboardHeadCells: readonly TableHeadCell[] = [ padding: "normal", }, { - id: "totalDays", + id: "total_days", label: "Total Days", align: "right", padding: "normal", From 26406c1594142faa9a0b62963fb9f0b10cc7a3ae Mon Sep 17 00:00:00 2001 From: Topvennie Date: Wed, 4 Sep 2024 00:06:13 +0200 Subject: [PATCH 14/31] vinvoor: more snake_case --- .../dataproviders/leaderboardProvider.ts | 15 +++++++++++++++ vinvoor/src/types/leaderboard.ts | 10 +++++----- 2 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 vinvoor/src/providers/dataproviders/leaderboardProvider.ts diff --git a/vinvoor/src/providers/dataproviders/leaderboardProvider.ts b/vinvoor/src/providers/dataproviders/leaderboardProvider.ts new file mode 100644 index 0000000..5eec883 --- /dev/null +++ b/vinvoor/src/providers/dataproviders/leaderboardProvider.ts @@ -0,0 +1,15 @@ +import { + convertLeaderboardItemJSON, + LeaderboardItem, + LeaderboardItemJSON, +} from "../../types/leaderboard"; +import { createDataContext } from "../DataProvider"; + +export const { + DataProvider: LeaderboardProvider, + useDataContext: useLeaderboardContext, +} = createDataContext( + "leaderboard", + [], + convertLeaderboardItemJSON, +); diff --git a/vinvoor/src/types/leaderboard.ts b/vinvoor/src/types/leaderboard.ts index 8e2960f..4f8ae81 100644 --- a/vinvoor/src/types/leaderboard.ts +++ b/vinvoor/src/types/leaderboard.ts @@ -14,10 +14,10 @@ export interface LeaderboardItemJSON { export interface LeaderboardItem { position: number; - user_id: number; + userId: number; username: string; - total_days: number; - position_change: number; + totalDays: number; + positionChange: number; } // Converters @@ -36,7 +36,7 @@ export const convertLeaderboardItemJSON = ( export const leaderboardHeadCells: readonly TableHeadCell[] = [ { - id: "position_change", + id: "positionChange", label: "Change", align: "right", padding: "checkbox", @@ -54,7 +54,7 @@ export const leaderboardHeadCells: readonly TableHeadCell[] = [ padding: "normal", }, { - id: "total_days", + id: "totalDays", label: "Total Days", align: "right", padding: "normal", From 6feee284f35971d9423a2f3037bbee24469b6db6 Mon Sep 17 00:00:00 2001 From: Hannes Klinckaert Date: Wed, 4 Sep 2024 01:46:58 +0200 Subject: [PATCH 15/31] vingo: fix docker for backend --- dev.sh | 8 ++++---- docker-compose.yml | 1 - vingo/Dockerfile.dev | 9 +++++++++ 3 files changed, 13 insertions(+), 5 deletions(-) create mode 100644 vingo/Dockerfile.dev diff --git a/dev.sh b/dev.sh index 79c599f..44278d8 100755 --- a/dev.sh +++ b/dev.sh @@ -21,7 +21,7 @@ done # Build the docker containers if clean flag is set if [ "$clean" = true ]; then - rm vingo/.env || true +# rm vingo/.env || true rm vinvoor/.env || true docker compose -f docker-compose.yml build fi @@ -29,9 +29,9 @@ fi # Check for the required files -if [ ! -f vingo/.env ]; then - cp vingo/dev.env vingo/.env -fi +#if [ ! -f vingo/.env ]; then +# cp vingo/dev.env vingo/.env +#fi if [ ! -f vinvoor/.env ]; then cp vinvoor/dev.env vinvoor/.env fi diff --git a/docker-compose.yml b/docker-compose.yml index f3d87fc..4cb3511 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -20,7 +20,6 @@ services: - 4000:4000 volumes: - ./vingo:/backend - - backend-packages:/go/pkg/mod extra_hosts: - "host.docker.internal:host-gateway" depends_on: diff --git a/vingo/Dockerfile.dev b/vingo/Dockerfile.dev new file mode 100644 index 0000000..4a22e53 --- /dev/null +++ b/vingo/Dockerfile.dev @@ -0,0 +1,9 @@ +FROM rust:1.80.1-alpine3.19 + +WORKDIR /backend + +RUN apk add musl-dev + +RUN cargo install cargo-watch + +CMD cargo watch -x run From ebd31a05394cb29bffe0f0d2361a3e9ed8a347d1 Mon Sep 17 00:00:00 2001 From: Hannes Klinckaert Date: Wed, 4 Sep 2024 01:47:15 +0200 Subject: [PATCH 16/31] vingo: add cardstatus endpoint --- vingo/src/main.rs | 6 +++--- vingo/src/routes/cards.rs | 23 +++++++++++++++++++++++ vingo/src/routes/scans.rs | 1 - vinvoor/src/cards/CardsAdd.tsx | 12 ++++++------ 4 files changed, 32 insertions(+), 10 deletions(-) diff --git a/vingo/src/main.rs b/vingo/src/main.rs index 6f960df..1ca1ee3 100644 --- a/vingo/src/main.rs +++ b/vingo/src/main.rs @@ -18,7 +18,7 @@ use tower_sessions::{cookie::SameSite, MemoryStore, SessionManagerLayer}; use migration::{Migrator, MigratorTrait}; -const DB_URL: &str = "postgres://postgres:zess@localhost/zess"; +const DB_URL: &str = "postgres://postgres:zess@host.docker.internal/zess?sslmode=disable"; #[derive(Clone, Debug)] struct AppState { @@ -65,7 +65,7 @@ async fn main() { .with_state(state); // run it - let listener = tokio::net::TcpListener::bind("127.0.0.1:4000") + let listener = tokio::net::TcpListener::bind("0.0.0.0:4000") .await .unwrap(); @@ -81,7 +81,7 @@ fn routes() -> Router { .route("/auth/callback", get(auth::callback)) .route("/cards", get(cards::get_for_current_user)) .route("/cards/:card_id", patch(cards::update)) - .route("/cards/register", post(cards::start_register)) + .route("/cards/register", get(cards::register_status).post(cards::start_register)) .route("/scans", get(scans::get_for_current_user)) .route("/scans", post(scans::add)) } diff --git a/vingo/src/routes/cards.rs b/vingo/src/routes/cards.rs index 097304e..07ab9a2 100644 --- a/vingo/src/routes/cards.rs +++ b/vingo/src/routes/cards.rs @@ -47,6 +47,29 @@ pub async fn start_register(session: Session, state: State) -> Respons Ok(()) } +#[derive(Debug, Serialize, Deserialize)] +pub struct RegisterStatus { + registering: bool, + is_current_user: bool, + success: bool, + time_remaining: u32, + time_percentage: f64, +} + +pub async fn register_status(session: Session, state: State) -> ResponseResult> { + let user = get_user(&session).await?; + let registering = state.registering.lock().await; + + let time_remaining = (registering.end - Local::now().fixed_offset()).num_seconds() as u32; + Ok(Json(RegisterStatus { + registering: Local::now().fixed_offset() < registering.end, + is_current_user: user.id == registering.user, + success: registering.last_success, + time_remaining, + time_percentage: f64::from(time_remaining) / 60.0, + })) +} + #[derive(Debug, Serialize, Deserialize)] pub struct CardUpdate { name: String, diff --git a/vingo/src/routes/scans.rs b/vingo/src/routes/scans.rs index e23c5b7..f53da18 100644 --- a/vingo/src/routes/scans.rs +++ b/vingo/src/routes/scans.rs @@ -44,7 +44,6 @@ pub async fn add(state: State, body: String) -> ResponseResult } let mut registering = state.registering.lock().await; - dbg!(®istering); // if someone is registering a card if Local::now().fixed_offset() < registering.end { diff --git a/vinvoor/src/cards/CardsAdd.tsx b/vinvoor/src/cards/CardsAdd.tsx index f79eb6c..a6ca0c2 100644 --- a/vinvoor/src/cards/CardsAdd.tsx +++ b/vinvoor/src/cards/CardsAdd.tsx @@ -49,10 +49,10 @@ export const CardsAdd = () => { const checkCardsChange = async (): Promise => { let status: CardGetRegisterResponse = await getApi(REGISTER_ENDPOINT); - while (status.registering && status.isCurrentUser) { + while (status.registering && status.is_current_user) { setProgressProps({ - time: status.timeRemaining, - percentage: status.timePercentage, + time: status.time_remaining, + percentage: status.time_percentage, }); status = await getApi(REGISTER_ENDPOINT); await new Promise(r => setTimeout(r, CHECK_INTERVAL)); @@ -73,7 +73,7 @@ export const CardsAdd = () => { void error.response .json() .then((response: CardPostResponse) => { - if (response.isCurrentUser) + if (response.is_current_user) enqueueSnackbar(requestYou, { variant: "warning", }); @@ -86,13 +86,13 @@ export const CardsAdd = () => { }); } - if (response.registering && response.isCurrentUser) started = true; + if (response.registering && response.is_current_user) started = true; if (started) { setRegistering(true); let id: Optional; - if (!(response.registering && response.isCurrentUser)) { + if (!(response.registering && response.is_current_user)) { id = randomInt().toString(); enqueueSnackbar(requestSuccess, { variant: "info", From 95aa632cae33ba18774d09bf3c5082eef58fbf00 Mon Sep 17 00:00:00 2001 From: Topvennie Date: Wed, 4 Sep 2024 16:34:12 +0200 Subject: [PATCH 17/31] vinvoor: sssssssnake case --- vinvoor/src/cards/CardsAdd.tsx | 43 ++++++++++++++++++++++++---------- vinvoor/src/types/cards.ts | 4 ++-- vinvoor/src/util/fetch.ts | 30 ++++++++++++++++-------- 3 files changed, 53 insertions(+), 24 deletions(-) diff --git a/vinvoor/src/cards/CardsAdd.tsx b/vinvoor/src/cards/CardsAdd.tsx index a6ca0c2..36826c2 100644 --- a/vinvoor/src/cards/CardsAdd.tsx +++ b/vinvoor/src/cards/CardsAdd.tsx @@ -3,7 +3,14 @@ import { Button, Typography } from "@mui/material"; import { useConfirm } from "material-ui-confirm"; import { useSnackbar } from "notistack"; import { useEffect, useState } from "react"; -import { CardGetRegisterResponse, CardPostResponse } from "../types/cards"; +import { + CardGetRegisterResponse, + CardGetRegisterResponseJSON, + CardPostResponse, + CardPostResponseJSON, + convertCardGetRegisterResponseJSON, + convertCardPostResponseJSON, +} from "../types/cards"; import { Optional } from "../types/general"; import { getApi, isResponseNot200Error, postApi } from "../util/fetch"; import { randomInt } from "../util/util"; @@ -47,14 +54,19 @@ export const CardsAdd = () => { const { enqueueSnackbar, closeSnackbar } = useSnackbar(); const checkCardsChange = async (): Promise => { - let status: CardGetRegisterResponse = - await getApi(REGISTER_ENDPOINT); - while (status.registering && status.is_current_user) { + let status: CardGetRegisterResponse = await getApi< + CardGetRegisterResponse, + CardGetRegisterResponseJSON + >(REGISTER_ENDPOINT, convertCardGetRegisterResponseJSON); + while (status.registering && status.isCurrentUser) { setProgressProps({ - time: status.time_remaining, - percentage: status.time_percentage, + time: status.timeRemaining, + percentage: status.timePercentage, }); - status = await getApi(REGISTER_ENDPOINT); + status = await getApi< + CardGetRegisterResponse, + CardGetRegisterResponseJSON + >(REGISTER_ENDPOINT, convertCardGetRegisterResponseJSON); await new Promise(r => setTimeout(r, CHECK_INTERVAL)); } @@ -62,18 +74,25 @@ export const CardsAdd = () => { }; const handleRegister = (start: boolean) => { - getApi(REGISTER_ENDPOINT) + getApi( + REGISTER_ENDPOINT, + convertCardGetRegisterResponseJSON, + ) .then(async response => { let started = false; if (!response.registering && start) { - await postApi(REGISTER_ENDPOINT) + await postApi( + REGISTER_ENDPOINT, + {}, + convertCardPostResponseJSON, + ) .then(() => (started = true)) .catch(error => { if (isResponseNot200Error(error)) { void error.response .json() .then((response: CardPostResponse) => { - if (response.is_current_user) + if (response.isCurrentUser) enqueueSnackbar(requestYou, { variant: "warning", }); @@ -86,13 +105,13 @@ export const CardsAdd = () => { }); } - if (response.registering && response.is_current_user) started = true; + if (response.registering && response.isCurrentUser) started = true; if (started) { setRegistering(true); let id: Optional; - if (!(response.registering && response.is_current_user)) { + if (!(response.registering && response.isCurrentUser)) { id = randomInt().toString(); enqueueSnackbar(requestSuccess, { variant: "info", diff --git a/vinvoor/src/types/cards.ts b/vinvoor/src/types/cards.ts index 8f5ada5..6090c33 100644 --- a/vinvoor/src/types/cards.ts +++ b/vinvoor/src/types/cards.ts @@ -9,11 +9,11 @@ export interface CardJSON extends BaseJSON { amount_used: number; } -interface CardPostResponseJSON { +export interface CardPostResponseJSON { is_current_user: boolean; } -interface CardGetRegisterResponseJSON { +export interface CardGetRegisterResponseJSON { registering: boolean; is_current_user: boolean; success: boolean; diff --git a/vinvoor/src/util/fetch.ts b/vinvoor/src/util/fetch.ts index dfe9fe3..f2e34ed 100644 --- a/vinvoor/src/util/fetch.ts +++ b/vinvoor/src/util/fetch.ts @@ -10,22 +10,32 @@ export const getApi = ( export const postApi = ( endpoint: string, body: Record = {}, + convertData?: (data: U) => T, ) => - _fetch(`${URLS.API}/${endpoint}`, { - method: "POST", - body: JSON.stringify(body), - headers: new Headers({ "content-type": "application/json" }), - }); + _fetch( + `${URLS.API}/${endpoint}`, + { + method: "POST", + body: JSON.stringify(body), + headers: new Headers({ "content-type": "application/json" }), + }, + convertData, + ); export const patchApi = ( endpoint: string, body: Record = {}, + convertData?: (data: U) => T, ) => - _fetch(`${URLS.API}/${endpoint}`, { - method: "PATCH", - body: JSON.stringify(body), - headers: new Headers({ "content-type": "application/json" }), - }); + _fetch( + `${URLS.API}/${endpoint}`, + { + method: "PATCH", + body: JSON.stringify(body), + headers: new Headers({ "content-type": "application/json" }), + }, + convertData, + ); export const deleteAPI = ( endpoint: string, From 3a8f55af36a7a3ebf8564df5f06eb9a44c702acf Mon Sep 17 00:00:00 2001 From: Hannes Klinckaert Date: Fri, 6 Sep 2024 23:02:11 +0200 Subject: [PATCH 18/31] vingo: add leaderboard --- vingo/src/main.rs | 12 ++++--- vingo/src/routes/cards.rs | 5 ++- vingo/src/routes/leaderboard.rs | 54 ++++++++++++++++++++++++++++++++ vingo/src/routes/mod.rs | 1 + vinvoor/src/types/leaderboard.ts | 7 +++-- 5 files changed, 70 insertions(+), 9 deletions(-) create mode 100644 vingo/src/routes/leaderboard.rs diff --git a/vingo/src/main.rs b/vingo/src/main.rs index 1ca1ee3..531d9fe 100644 --- a/vingo/src/main.rs +++ b/vingo/src/main.rs @@ -5,7 +5,7 @@ mod entities; use std::sync::Arc; use chrono::Local; -use routes::{auth, cards, scans}; +use routes::{auth, cards, leaderboard, scans}; use axum::{ routing::{get, patch, post}, @@ -65,9 +65,7 @@ async fn main() { .with_state(state); // run it - let listener = tokio::net::TcpListener::bind("0.0.0.0:4000") - .await - .unwrap(); + let listener = tokio::net::TcpListener::bind("0.0.0.0:4000").await.unwrap(); println!("listening on {}", listener.local_addr().unwrap()); axum::serve(listener, app).await.unwrap(); @@ -81,7 +79,11 @@ fn routes() -> Router { .route("/auth/callback", get(auth::callback)) .route("/cards", get(cards::get_for_current_user)) .route("/cards/:card_id", patch(cards::update)) - .route("/cards/register", get(cards::register_status).post(cards::start_register)) + .route( + "/cards/register", + get(cards::register_status).post(cards::start_register), + ) .route("/scans", get(scans::get_for_current_user)) .route("/scans", post(scans::add)) + .route("/leaderboard", get(leaderboard::get)) } diff --git a/vingo/src/routes/cards.rs b/vingo/src/routes/cards.rs index 07ab9a2..a589a9d 100644 --- a/vingo/src/routes/cards.rs +++ b/vingo/src/routes/cards.rs @@ -56,7 +56,10 @@ pub struct RegisterStatus { time_percentage: f64, } -pub async fn register_status(session: Session, state: State) -> ResponseResult> { +pub async fn register_status( + session: Session, + state: State, +) -> ResponseResult> { let user = get_user(&session).await?; let registering = state.registering.lock().await; diff --git a/vingo/src/routes/leaderboard.rs b/vingo/src/routes/leaderboard.rs new file mode 100644 index 0000000..e1211ea --- /dev/null +++ b/vingo/src/routes/leaderboard.rs @@ -0,0 +1,54 @@ +use axum::{extract::State, Json}; +use chrono::{DateTime, FixedOffset, Local, TimeDelta}; +use reqwest::StatusCode; +use serde::{Deserialize, Serialize}; + +use sea_orm::{DbBackend, FromQueryResult, Statement}; + +use crate::AppState; + +use super::util::errors::{ResponseResult, ResultAndLogError}; + +#[derive(Debug, FromQueryResult, Serialize, Deserialize)] +pub struct LeaderboardItem { + id: i32, + name: String, + total_days: i64, + position: i64, + position_change: Option, +} + +pub async fn get(state: State) -> ResponseResult>> { + let mut leaderboard = leaderboard_from_db(&state, Local::now().fixed_offset()).await?; + let leaderboard_last_week = + leaderboard_from_db(&state, Local::now().fixed_offset() - TimeDelta::days(7)).await?; + + for user in &mut leaderboard { + let position_change = leaderboard_last_week + .iter() + .find(|v| v.id == user.id) + .and_then(|v| Some(v.position - user.position)); + user.position_change = position_change; + } + + Ok(Json(leaderboard)) +} + +async fn leaderboard_from_db( + state: &State, + before: DateTime, +) -> ResponseResult> { + let result = LeaderboardItem::find_by_statement(Statement::from_sql_and_values(DbBackend::Postgres," + SELECT id, name, count as total_days, RANK() OVER (ORDER BY count desc) AS position + FROM (SELECT COUNT(DISTINCT ((scan_time - INTERVAL '4 hours') AT TIME ZONE 'Europe/Brussels')::date), \"user\".id, \"user\".name + FROM scan + LEFT JOIN card ON card_serial = serial + LEFT JOIN \"user\" ON user_id = \"user\".id + WHERE scan_time < $1 + GROUP BY \"user\".name, \"user\".id);", [before.into()])) + .all(&state.db) + .await + .or_log((StatusCode::INTERNAL_SERVER_ERROR, "could not select leaderboard items"))?; + + Ok(result) +} diff --git a/vingo/src/routes/mod.rs b/vingo/src/routes/mod.rs index 036eedc..83f7e73 100644 --- a/vingo/src/routes/mod.rs +++ b/vingo/src/routes/mod.rs @@ -1,5 +1,6 @@ pub mod auth; pub mod cards; +pub mod leaderboard; pub mod scans; pub mod util { diff --git a/vinvoor/src/types/leaderboard.ts b/vinvoor/src/types/leaderboard.ts index 4f8ae81..2831bcc 100644 --- a/vinvoor/src/types/leaderboard.ts +++ b/vinvoor/src/types/leaderboard.ts @@ -4,8 +4,8 @@ import { TableHeadCell } from "./general"; export interface LeaderboardItemJSON { position: number; - user_id: number; - username: string; + id: number; + name: string; total_days: number; position_change: number; } @@ -27,7 +27,8 @@ export const convertLeaderboardItemJSON = ( ): LeaderboardItem[] => leaderboardItems.map(leaderboardItem => ({ ...leaderboardItem, - userId: leaderboardItem.user_id, + userId: leaderboardItem.id, + username: leaderboardItem.name, totalDays: leaderboardItem.total_days, positionChange: leaderboardItem.position_change, })); From 9af7d1711f20d1cf9f3f19e25f50f23e1456a3fe Mon Sep 17 00:00:00 2001 From: Topvennie Date: Mon, 9 Sep 2024 20:55:27 +0200 Subject: [PATCH 19/31] vingo: cors --- vingo/.tool-versions | 1 + vingo/Cargo.toml | 40 +++++++++++++++---- vingo/src/main.rs | 2 + .../src/leaderboard/LeaderboardTableBody.tsx | 6 +-- vinvoor/src/types/leaderboard.ts | 8 ++-- 5 files changed, 41 insertions(+), 16 deletions(-) create mode 100644 vingo/.tool-versions diff --git a/vingo/.tool-versions b/vingo/.tool-versions new file mode 100644 index 0000000..0070a0b --- /dev/null +++ b/vingo/.tool-versions @@ -0,0 +1 @@ +rust 1.80.1 diff --git a/vingo/Cargo.toml b/vingo/Cargo.toml index 49e8c8f..3d1d361 100644 --- a/vingo/Cargo.toml +++ b/vingo/Cargo.toml @@ -4,20 +4,44 @@ version = "0.1.0" edition = "2021" [workspace] -members = [ "migration" ] +members = ["migration"] [dependencies] -axum = { version = "0.7.5", default-features = false, features = ["tokio", "http1", "tracing", "query", "json" ] } +axum = { version = "0.7.5", default-features = false, features = [ + "tokio", + "http1", + "tracing", + "query", + "json", +] } chrono = { version = "0.4.38", default-features = false, features = ["serde"] } rand = { version = "0.8.5", default-features = false } -reqwest = { version = "0.12.7", default-features = false, features = [ "json", "rustls-tls" ] } -sea-orm = { version = "1.0.1", default-features = false, features = [ "sqlx-postgres", "runtime-tokio-rustls", "macros", "with-chrono"] } +reqwest = { version = "0.12.7", default-features = false, features = [ + "json", + "rustls-tls", +] } +sea-orm = { version = "1.0.1", default-features = false, features = [ + "sqlx-postgres", + "runtime-tokio-rustls", + "macros", + "with-chrono", +] } serde = { version = "1.0.209", default-features = false, features = ["derive"] } -tokio = { version = "1.39.3", default-features = false, features = ["rt-multi-thread", "macros", "net"] } -tower-http = { version = "0.5.2", default-features = false, features = ["trace"] } -tower-sessions = { version = "0.12.3", default-features = false, features = ["memory-store", "axum-core"] } +tokio = { version = "1.39.3", default-features = false, features = [ + "rt-multi-thread", + "macros", + "net", +] } +tower-http = { version = "0.5.2", default-features = false, features = [ + "trace", + "cors", +] } +tower-sessions = { version = "0.12.3", default-features = false, features = [ + "memory-store", + "axum-core", +] } tracing = "0.1.37" tracing-subscriber = "0.3.16" -migration = { path = "migration"} +migration = { path = "migration" } diff --git a/vingo/src/main.rs b/vingo/src/main.rs index 531d9fe..0dbfeb3 100644 --- a/vingo/src/main.rs +++ b/vingo/src/main.rs @@ -14,6 +14,7 @@ use axum::{ use sea_orm::{prelude::DateTimeWithTimeZone, Database, DatabaseConnection}; use tokio::sync::Mutex; use tower_http::trace::TraceLayer; +use tower_http::cors::CorsLayer; use tower_sessions::{cookie::SameSite, MemoryStore, SessionManagerLayer}; use migration::{Migrator, MigratorTrait}; @@ -61,6 +62,7 @@ async fn main() { let app = Router::new() .nest("/api", routes()) .layer(sess_mw) + .layer(CorsLayer::very_permissive()) .layer(TraceLayer::new_for_http()) .with_state(state); diff --git a/vinvoor/src/leaderboard/LeaderboardTableBody.tsx b/vinvoor/src/leaderboard/LeaderboardTableBody.tsx index cec256a..6307ad9 100644 --- a/vinvoor/src/leaderboard/LeaderboardTableBody.tsx +++ b/vinvoor/src/leaderboard/LeaderboardTableBody.tsx @@ -112,13 +112,13 @@ export const LeaderboardTableBody = () => { {rows.map((row, index) => { return ( theme.palette.action.hover, }), - ...(row.username === user!.username && { + ...(row.name === user!.username && { backgroundColor: theme => alpha( theme.palette.primary.main, diff --git a/vinvoor/src/types/leaderboard.ts b/vinvoor/src/types/leaderboard.ts index 2831bcc..376916b 100644 --- a/vinvoor/src/types/leaderboard.ts +++ b/vinvoor/src/types/leaderboard.ts @@ -14,8 +14,8 @@ export interface LeaderboardItemJSON { export interface LeaderboardItem { position: number; - userId: number; - username: string; + id: number; + name: string; totalDays: number; positionChange: number; } @@ -27,8 +27,6 @@ export const convertLeaderboardItemJSON = ( ): LeaderboardItem[] => leaderboardItems.map(leaderboardItem => ({ ...leaderboardItem, - userId: leaderboardItem.id, - username: leaderboardItem.name, totalDays: leaderboardItem.total_days, positionChange: leaderboardItem.position_change, })); @@ -49,7 +47,7 @@ export const leaderboardHeadCells: readonly TableHeadCell[] = [ padding: "checkbox", }, { - id: "username", + id: "name", label: "Username", align: "left", padding: "normal", From 4615dfdbef1d023c85bb1a24037c860241ed32b6 Mon Sep 17 00:00:00 2001 From: Topvennie Date: Mon, 9 Sep 2024 22:33:55 +0200 Subject: [PATCH 20/31] vinvoor: background foundation --- vinvoor/src/App.tsx | 20 ++++++++++++++------ vinvoor/src/overview/Overview.tsx | 16 ++++++++++------ vinvoor/src/providers/ThemeProvider.tsx | 2 +- vinvoor/src/providers/UserProvider.tsx | 11 ++++++++++- vinvoor/src/themes/background.css | 11 +++++++++++ vinvoor/src/{ => themes}/theme.ts | 0 vinvoor/src/user/Logout.tsx | 13 +++++-------- 7 files changed, 51 insertions(+), 22 deletions(-) create mode 100644 vinvoor/src/themes/background.css rename vinvoor/src/{ => themes}/theme.ts (100%) diff --git a/vinvoor/src/App.tsx b/vinvoor/src/App.tsx index d8b3b94..fa7af95 100644 --- a/vinvoor/src/App.tsx +++ b/vinvoor/src/App.tsx @@ -1,21 +1,29 @@ -import { Container } from "@mui/material"; -import { useContext } from "react"; +import { Box, Container } from "@mui/material"; +import { useContext, useState } from "react"; import { Navigate, Outlet, useOutlet } from "react-router-dom"; import { LoadingSkeleton } from "./components/LoadingSkeleton"; import { NavBar } from "./navbar/NavBar"; import { Overview } from "./overview/Overview"; import { UserContext } from "./providers/UserProvider"; import { WelcomePage } from "./WelcomePage"; +import { randomInt } from "./util/util"; +import "./themes/background.css"; export const App = () => { const { user, loading, error } = useContext(UserContext); - const outlet = useOutlet(); + const [backgroundSix] = useState(() => randomInt(0, 50) === 1); + return ( - <> + - + {user !== undefined ? ( outlet !== null ? ( @@ -31,6 +39,6 @@ export const App = () => { )} - + ); }; diff --git a/vinvoor/src/overview/Overview.tsx b/vinvoor/src/overview/Overview.tsx index 3f4ce28..7f86374 100644 --- a/vinvoor/src/overview/Overview.tsx +++ b/vinvoor/src/overview/Overview.tsx @@ -82,12 +82,16 @@ export const Overview = () => { ) : ( - - - You don't have any scans. - - Start scanning to see some data! - + + + + You don't have any scans. + + + Start scanning to see some data! + + + )} ); diff --git a/vinvoor/src/providers/ThemeProvider.tsx b/vinvoor/src/providers/ThemeProvider.tsx index 199df6c..957c63b 100644 --- a/vinvoor/src/providers/ThemeProvider.tsx +++ b/vinvoor/src/providers/ThemeProvider.tsx @@ -1,7 +1,7 @@ import { ThemeProvider as MUIThemeProvider } from "@mui/material"; import Cookies from "js-cookie"; import { createContext, FC, ReactNode, useEffect, useState } from "react"; -import { ThemeMode, themeModes } from "../theme"; +import { ThemeMode, themeModes } from "../themes/theme"; interface ThemeProviderProps { children: ReactNode; diff --git a/vinvoor/src/providers/UserProvider.tsx b/vinvoor/src/providers/UserProvider.tsx index 0cd3396..feff698 100644 --- a/vinvoor/src/providers/UserProvider.tsx +++ b/vinvoor/src/providers/UserProvider.tsx @@ -10,12 +10,16 @@ interface UserProviderProps { interface UserContextProps { user?: User; + invalidateUser: (error?: Error) => void; loading: boolean; error?: Error; } const defaultUserContextProps: UserContextProps = { user: undefined, + invalidateUser: () => { + // No operation, placeholder function + }, loading: true, error: undefined, }; @@ -29,6 +33,11 @@ export const UserProvider: FC = ({ children }) => { const [loading, setLoading] = useState(true); const [error, setError] = useState>(undefined); + const invalidateUser = (error?: Error) => { + setUser(undefined); + setError(error); + }; + useEffect(() => { const sessionId = Cookies.get("id"); @@ -51,7 +60,7 @@ export const UserProvider: FC = ({ children }) => { }, []); return ( - + {children} ); diff --git a/vinvoor/src/themes/background.css b/vinvoor/src/themes/background.css new file mode 100644 index 0000000..a0c92af --- /dev/null +++ b/vinvoor/src/themes/background.css @@ -0,0 +1,11 @@ +.Six::before { + width: 100%; + height: 100%; + position: absolute; + content: '""'; + background-image: url('data:image/svg+xml;utf8,6'); + background-repeat: "repeat"; + background-size: "50px 50px"; + opacity: 0.1; + z-index: -1; +} diff --git a/vinvoor/src/theme.ts b/vinvoor/src/themes/theme.ts similarity index 100% rename from vinvoor/src/theme.ts rename to vinvoor/src/themes/theme.ts diff --git a/vinvoor/src/user/Logout.tsx b/vinvoor/src/user/Logout.tsx index 19f178b..c7e787f 100644 --- a/vinvoor/src/user/Logout.tsx +++ b/vinvoor/src/user/Logout.tsx @@ -1,15 +1,12 @@ import { Button, ButtonProps } from "@mui/material"; -import { FC } from "react"; +import { FC, useContext } from "react"; +import { postApi } from "../util/fetch"; +import { UserContext } from "../providers/UserProvider"; export const Logout: FC = props => { - const url = import.meta.env.VITE_BACKEND_URL as string; - + const { invalidateUser } = useContext(UserContext); const handleClick = () => { - const form = document.createElement("form"); - form.method = "POST"; - form.action = `${url}/logout`; - document.body.appendChild(form); - form.submit(); + void postApi("logout").finally(() => invalidateUser()); }; return void; - loading: boolean; - error?: Error; -} - -const defaultUserContextProps: UserContextProps = { - user: undefined, - invalidateUser: () => { - // No operation, placeholder function - }, - loading: true, - error: undefined, -}; - -export const UserContext = createContext( - defaultUserContextProps, -); - -export const UserProvider: FC = ({ children }) => { - const [user, setUser] = useState>(undefined); - const [loading, setLoading] = useState(true); - const [error, setError] = useState>(undefined); - - const invalidateUser = (error?: Error) => { - setUser(undefined); - setError(error); - }; - - useEffect(() => { - const sessionId = Cookies.get("id"); - - if (!sessionId) { - setLoading(false); - - return; - } - - getApi("user") - .then(data => setUser(data)) - .catch(error => { - Cookies.remove("id"); - setUser(undefined); - if (!isResponseNot200Error(error)) setError(error as Error); - }) - .finally(() => { - setLoading(false); - }); - }, []); - - return ( - - {children} - - ); -}; diff --git a/vinvoor/src/providers/dataproviders/leaderboardProvider.ts b/vinvoor/src/providers/dataproviders/leaderboardProvider.ts deleted file mode 100644 index 5eec883..0000000 --- a/vinvoor/src/providers/dataproviders/leaderboardProvider.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { - convertLeaderboardItemJSON, - LeaderboardItem, - LeaderboardItemJSON, -} from "../../types/leaderboard"; -import { createDataContext } from "../DataProvider"; - -export const { - DataProvider: LeaderboardProvider, - useDataContext: useLeaderboardContext, -} = createDataContext( - "leaderboard", - [], - convertLeaderboardItemJSON, -); diff --git a/vinvoor/src/types/cards.ts b/vinvoor/src/types/cards.ts index 6090c33..a105562 100644 --- a/vinvoor/src/types/cards.ts +++ b/vinvoor/src/types/cards.ts @@ -7,6 +7,7 @@ export interface CardJSON extends BaseJSON { name: string; last_used: string; amount_used: number; + created_at: string; } export interface CardPostResponseJSON { @@ -28,6 +29,7 @@ export interface Card extends Base { name: string; lastUsed: Date; amountUsed: number; + createdAt: Date; } export interface CardPostResponse { diff --git a/vinvoor/src/types/days.ts b/vinvoor/src/types/days.ts index afdf81f..dd28134 100644 --- a/vinvoor/src/types/days.ts +++ b/vinvoor/src/types/days.ts @@ -19,7 +19,6 @@ export const convertDayJSON = (daysJSON: DayJSON[]): Day[] => .map(dayJSON => ({ ...dayJSON, date: new Date(dayJSON.date), - createdAt: new Date(dayJSON.created_at), })) .sort((a, b) => a.date.getTime() - b.date.getTime()); diff --git a/vinvoor/src/types/general.ts b/vinvoor/src/types/general.ts index 5444f65..1c9cbc2 100644 --- a/vinvoor/src/types/general.ts +++ b/vinvoor/src/types/general.ts @@ -2,12 +2,10 @@ export type Optional = T | undefined; export interface BaseJSON { id: number; - created_at: string; } export interface Base { id: number; - createdAt: Date; } export type TableOrder = "asc" | "desc"; diff --git a/vinvoor/src/types/scans.ts b/vinvoor/src/types/scans.ts index c7f0068..6e2fe7e 100644 --- a/vinvoor/src/types/scans.ts +++ b/vinvoor/src/types/scans.ts @@ -7,6 +7,7 @@ import { Base, BaseJSON, TableHeadCell } from "./general"; export interface ScanJSON extends BaseJSON { scan_time: string; card_serial: string; + created_at: string; } // Internal @@ -14,6 +15,7 @@ export interface ScanJSON extends BaseJSON { export interface Scan extends Base { scanTime: Date; cardSerial: string; + createdAt: Date; } export interface ScanCard { diff --git a/vinvoor/src/types/seasons.ts b/vinvoor/src/types/seasons.ts new file mode 100644 index 0000000..fba1d43 --- /dev/null +++ b/vinvoor/src/types/seasons.ts @@ -0,0 +1,26 @@ +import { Base, BaseJSON } from "./general"; + +// External + +export interface SeasonJSON extends BaseJSON { + name: string; + start: string; + end: string; +} + +// Internal + +export interface Season extends Base { + name: string; + start: Date; + end: Date; +} + +// Converters + +export const convertSeasonJSON = (seasonsJSON: SeasonJSON[]): Season[] => + seasonsJSON.map(seasonJSON => ({ + ...seasonJSON, + start: new Date(seasonJSON.start), + end: new Date(seasonJSON.end), + })); diff --git a/vinvoor/src/types/settings.ts b/vinvoor/src/types/settings.ts index dca71d4..c5861f8 100644 --- a/vinvoor/src/types/settings.ts +++ b/vinvoor/src/types/settings.ts @@ -1,30 +1,22 @@ -import { Base, BaseJSON } from "./general"; - // External -export interface SettingsJSON extends BaseJSON { - scan_in_out: boolean; - leaderboard: boolean; - public: boolean; +export interface SettingsJSON { + season: number; } // Internal -export interface Settings extends Base { - scanInOut: boolean; - leaderboard: boolean; - public: boolean; +export interface Settings { + season: number; } // Converters export const converSettingsJSON = (settingsJSON: SettingsJSON): Settings => ({ ...settingsJSON, - createdAt: new Date(settingsJSON.created_at), - scanInOut: settingsJSON.scan_in_out, }); -// Table +// // Table interface AdjustableSettings { id: keyof Settings; diff --git a/vinvoor/src/types/user.ts b/vinvoor/src/types/user.ts index 80ae83a..acebacf 100644 --- a/vinvoor/src/types/user.ts +++ b/vinvoor/src/types/user.ts @@ -1,10 +1,22 @@ -import { Settings } from "./settings"; +// External -// External / Internal +export interface UserJSON { + id: number; + name: string; + admin: boolean; +} + +// Internal export interface User { id: number; - username: string; + name: string; admin: boolean; - settings: Settings; } + +// Converters + +export const convertUserJSON = (userJSON: UserJSON): User => ({ ...userJSON }); + +// TODO: Rename user directory to auth +// TODO: Convert user to tanstack query diff --git a/vinvoor/src/user/Logout.tsx b/vinvoor/src/user/Logout.tsx deleted file mode 100644 index c7e787f..0000000 --- a/vinvoor/src/user/Logout.tsx +++ /dev/null @@ -1,13 +0,0 @@ -import { Button, ButtonProps } from "@mui/material"; -import { FC, useContext } from "react"; -import { postApi } from "../util/fetch"; -import { UserContext } from "../providers/UserProvider"; - -export const Logout: FC = props => { - const { invalidateUser } = useContext(UserContext); - const handleClick = () => { - void postApi("logout").finally(() => invalidateUser()); - }; - - return