start working on auth

This commit is contained in:
philipp 2023-04-03 16:11:26 +02:00
parent 3dbfadb00e
commit d50f3d9746
12 changed files with 485 additions and 106 deletions

314
Cargo.lock generated
View File

@ -31,6 +31,17 @@ dependencies = [
"libc",
]
[[package]]
name = "argon2"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95c2fcf79ad1932ac6269a738109997a83c227c09b75842ae564dc8ede6a861c"
dependencies = [
"base64ct",
"blake2",
"password-hash",
]
[[package]]
name = "async-stream"
version = "0.3.4"
@ -61,7 +72,7 @@ checksum = "b9ccdd8f2a161be9bd5c023df56f1b2a0bd1d83872ae53b71a84a12c9bf6e842"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.10",
"syn 2.0.13",
]
[[package]]
@ -94,6 +105,12 @@ version = "0.21.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4a4ddaa51a5bc52a6948f74c06d20aaaddb71924eab79b8c97a8c556e942d6a"
[[package]]
name = "base64ct"
version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b"
[[package]]
name = "binascii"
version = "0.1.4"
@ -112,6 +129,15 @@ version = "2.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "487f1e0fcbe47deb8b0574e646def1c903389d95241dd1bbcc6ce4a715dfc0c1"
[[package]]
name = "blake2"
version = "0.10.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "46502ad458c9a52b69d4d4d32775c788b7a1b85e8bc9d482d92250fc0e3f8efe"
dependencies = [
"digest",
]
[[package]]
name = "block-buffer"
version = "0.10.4"
@ -218,9 +244,9 @@ dependencies = [
[[package]]
name = "core-foundation-sys"
version = "0.8.3"
version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc"
checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa"
[[package]]
name = "cpufeatures"
@ -309,7 +335,7 @@ dependencies = [
"proc-macro2",
"quote",
"scratch",
"syn 2.0.10",
"syn 2.0.13",
]
[[package]]
@ -326,7 +352,7 @@ checksum = "2345488264226bf682893e25de0769f3360aac9957980ec49361b083ddaa5bc5"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.10",
"syn 2.0.13",
]
[[package]]
@ -365,7 +391,7 @@ dependencies = [
"proc-macro2",
"proc-macro2-diagnostics",
"quote",
"syn 2.0.10",
"syn 2.0.13",
]
[[package]]
@ -376,6 +402,7 @@ checksum = "8168378f4e5023e7218c89c891c0fd8ecdb5e5e4f18cb78f38cf245dd021e76f"
dependencies = [
"block-buffer",
"crypto-common",
"subtle",
]
[[package]]
@ -414,13 +441,13 @@ dependencies = [
[[package]]
name = "errno"
version = "0.2.8"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1"
checksum = "50d6a0976c999d473fe89ad888d5a284e55366d9dc9038b1ba2aa15128c4afa0"
dependencies = [
"errno-dragonfly",
"libc",
"winapi",
"windows-sys 0.45.0",
]
[[package]]
@ -470,7 +497,7 @@ checksum = "8a3de6e8d11b22ff9edc6d916f890800597d60f8b2da1caf2955c274638d6412"
dependencies = [
"cfg-if",
"libc",
"redox_syscall",
"redox_syscall 0.2.16",
"windows-sys 0.45.0",
]
@ -483,7 +510,7 @@ dependencies = [
"futures-core",
"futures-sink",
"pin-project",
"spin 0.9.6",
"spin 0.9.8",
]
[[package]]
@ -512,9 +539,9 @@ dependencies = [
[[package]]
name = "futures"
version = "0.3.27"
version = "0.3.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "531ac96c6ff5fd7c62263c5e3c67a603af4fcaee2e1a0ae5565ba3a11e69e549"
checksum = "23342abe12aba583913b2e62f22225ff9c950774065e4bfb61a19cd9770fec40"
dependencies = [
"futures-channel",
"futures-core",
@ -526,9 +553,9 @@ dependencies = [
[[package]]
name = "futures-channel"
version = "0.3.27"
version = "0.3.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "164713a5a0dcc3e7b4b1ed7d3b433cabc18025386f9339346e8daf15963cf7ac"
checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2"
dependencies = [
"futures-core",
"futures-sink",
@ -536,15 +563,15 @@ dependencies = [
[[package]]
name = "futures-core"
version = "0.3.27"
version = "0.3.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "86d7a0c1aa76363dac491de0ee99faf6941128376f1cf96f07db7603b7de69dd"
checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c"
[[package]]
name = "futures-executor"
version = "0.3.27"
version = "0.3.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1997dd9df74cdac935c76252744c1ed5794fac083242ea4fe77ef3ed60ba0f83"
checksum = "ccecee823288125bd88b4d7f565c9e58e41858e47ab72e8ea2d64e93624386e0"
dependencies = [
"futures-core",
"futures-task",
@ -564,27 +591,27 @@ dependencies = [
[[package]]
name = "futures-io"
version = "0.3.27"
version = "0.3.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "89d422fa3cbe3b40dca574ab087abb5bc98258ea57eea3fd6f1fa7162c778b91"
checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964"
[[package]]
name = "futures-sink"
version = "0.3.27"
version = "0.3.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec93083a4aecafb2a80a885c9de1f0ccae9dbd32c2bb54b0c3a65690e0b8d2f2"
checksum = "f43be4fe21a13b9781a69afa4985b0f6ee0e1afab2c6f454a8cf30e2b2237b6e"
[[package]]
name = "futures-task"
version = "0.3.27"
version = "0.3.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd65540d33b37b16542a0438c12e6aeead10d4ac5d05bd3f805b8f35ab592879"
checksum = "76d3d132be6c0e6aa1534069c705a74a5997a356c0dc2f86a47765e5617c5b65"
[[package]]
name = "futures-util"
version = "0.3.27"
version = "0.3.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3ef6b17e481503ec85211fed8f39d1970f128935ca1f814cd32ac4a6842e84ab"
checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533"
dependencies = [
"futures-channel",
"futures-core",
@ -612,9 +639,9 @@ dependencies = [
[[package]]
name = "generic-array"
version = "0.14.6"
version = "0.14.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bff49e947297f3312447abdca79f45f4738097cc82b06e72054d2223f601f1b9"
checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a"
dependencies = [
"typenum",
"version_check",
@ -911,9 +938,9 @@ dependencies = [
[[package]]
name = "is-terminal"
version = "0.4.5"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8687c819457e979cc940d09cb16e42a1bf70aa6b60a549de6d3a62a0ee90c69e"
checksum = "256017f749ab3117e93acb91063009e1f1bb56d03965b14c2c8df4eb02c524d8"
dependencies = [
"hermit-abi 0.3.1",
"io-lifetimes",
@ -1005,9 +1032,9 @@ dependencies = [
[[package]]
name = "linux-raw-sys"
version = "0.1.4"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4"
checksum = "d59d8c75012853d2e872fb56bc8a2e53718e2cafe1a4c823143141c6d90c322f"
[[package]]
name = "lock_api"
@ -1084,9 +1111,9 @@ dependencies = [
[[package]]
name = "multer"
version = "2.0.4"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ed4198ce7a4cbd2a57af78d28c6fbb57d81ac5f1d6ad79ac6c5587419cbdf22"
checksum = "01acbdc23469fd8fe07ab135923371d5f5a422fbf9c522158677c8eb15bc51c2"
dependencies = [
"bytes",
"encoding_rs",
@ -1096,7 +1123,7 @@ dependencies = [
"log",
"memchr",
"mime",
"spin 0.9.6",
"spin 0.9.8",
"tokio",
"tokio-util",
"version_check",
@ -1114,11 +1141,11 @@ dependencies = [
[[package]]
name = "normpath"
version = "1.1.0"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "972dec05f98e7c787ede35d7a9ea4735eb7788c299287352757b3def6cc1f7b5"
checksum = "ec60c60a693226186f5d6edf073232bfb6464ed97eb22cf3b01c1e8198fd97f5"
dependencies = [
"windows-sys 0.45.0",
"windows-sys 0.48.0",
]
[[package]]
@ -1220,7 +1247,7 @@ dependencies = [
"cfg-if",
"instant",
"libc",
"redox_syscall",
"redox_syscall 0.2.16",
"smallvec",
"winapi",
]
@ -1233,7 +1260,7 @@ checksum = "9069cbb9f99e3a5083476ccb29ceb1de18b9118cafa53e90c9551235de2b9521"
dependencies = [
"cfg-if",
"libc",
"redox_syscall",
"redox_syscall 0.2.16",
"smallvec",
"windows-sys 0.45.0",
]
@ -1247,6 +1274,17 @@ dependencies = [
"regex",
]
[[package]]
name = "password-hash"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "346f04948ba92c43e8469c1ee6736c7563d71012b17d40745260fe106aac2166"
dependencies = [
"base64ct",
"rand_core",
"subtle",
]
[[package]]
name = "paste"
version = "1.0.12"
@ -1273,7 +1311,7 @@ dependencies = [
"proc-macro2",
"proc-macro2-diagnostics",
"quote",
"syn 2.0.10",
"syn 2.0.13",
]
[[package]]
@ -1284,9 +1322,9 @@ checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e"
[[package]]
name = "pest"
version = "2.5.6"
version = "2.5.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8cbd939b234e95d72bc393d51788aec68aeeb5d51e748ca08ff3aad58cb722f7"
checksum = "7b1403e8401ad5dedea73c626b99758535b342502f8d1e361f4a2dd952749122"
dependencies = [
"thiserror",
"ucd-trie",
@ -1294,9 +1332,9 @@ dependencies = [
[[package]]
name = "pest_derive"
version = "2.5.6"
version = "2.5.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a81186863f3d0a27340815be8f2078dd8050b14cd71913db9fbda795e5f707d7"
checksum = "be99c4c1d2fc2769b1d00239431d711d08f6efedcecb8b6e30707160aee99c15"
dependencies = [
"pest",
"pest_generator",
@ -1304,22 +1342,22 @@ dependencies = [
[[package]]
name = "pest_generator"
version = "2.5.6"
version = "2.5.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "75a1ef20bf3193c15ac345acb32e26b3dc3223aff4d77ae4fc5359567683796b"
checksum = "e56094789873daa36164de2e822b3888c6ae4b4f9da555a1103587658c805b1e"
dependencies = [
"pest",
"pest_meta",
"proc-macro2",
"quote",
"syn 1.0.109",
"syn 2.0.13",
]
[[package]]
name = "pest_meta"
version = "2.5.6"
version = "2.5.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5e3b284b1f13a20dc5ebc90aff59a51b8d7137c221131b52a7260c08cbc1cc80"
checksum = "6733073c7cff3d8459fda0e42f13a047870242aed8b509fe98000928975f359e"
dependencies = [
"once_cell",
"pest",
@ -1411,9 +1449,9 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
[[package]]
name = "proc-macro2"
version = "1.0.54"
version = "1.0.56"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e472a104799c74b514a57226160104aa483546de37e839ec50e3c2e41dd87534"
checksum = "2b63bdb0cd06f1f4dedf69b254734f9b45af66e4a031e42a7480257d9898b435"
dependencies = [
"unicode-ident",
]
@ -1426,7 +1464,7 @@ checksum = "606c4ba35817e2922a308af55ad51bab3645b59eae5c570d4a6cf07e36bd493b"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.10",
"syn 2.0.13",
"version_check",
"yansi",
]
@ -1479,6 +1517,15 @@ dependencies = [
"bitflags 1.3.2",
]
[[package]]
name = "redox_syscall"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29"
dependencies = [
"bitflags 1.3.2",
]
[[package]]
name = "ref-cast"
version = "1.0.16"
@ -1496,7 +1543,7 @@ checksum = "8d2275aab483050ab2a7364c1a46604865ee7d6906684e08db0f090acf74f9e7"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.10",
"syn 2.0.13",
]
[[package]]
@ -1590,7 +1637,7 @@ dependencies = [
"proc-macro2",
"quote",
"rocket_http",
"syn 2.0.10",
"syn 2.0.13",
"unicode-xid",
]
@ -1638,6 +1685,8 @@ dependencies = [
name = "rot"
version = "0.1.0"
dependencies = [
"argon2",
"base64",
"env_logger",
"log",
"rocket",
@ -1647,9 +1696,9 @@ dependencies = [
[[package]]
name = "rustix"
version = "0.36.11"
version = "0.37.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "db4165c9963ab29e422d6c26fbc1d37f15bace6b2810221f9d925023480fcf0e"
checksum = "d097081ed288dfe45699b72f5b5d648e5f15d64d900c7080273baa20c16a6849"
dependencies = [
"bitflags 1.3.2",
"errno",
@ -1731,29 +1780,29 @@ dependencies = [
[[package]]
name = "serde"
version = "1.0.158"
version = "1.0.159"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "771d4d9c4163ee138805e12c710dd365e4f44be8be0503cb1bb9eb989425d9c9"
checksum = "3c04e8343c3daeec41f58990b9d77068df31209f2af111e059e9fe9646693065"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.158"
version = "1.0.159"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e801c1712f48475582b7696ac71e0ca34ebb30e09338425384269d9717c62cad"
checksum = "4c614d17805b093df4b147b51339e7e44bf05ef59fba1e45d83500bcfb4d8585"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.10",
"syn 2.0.13",
]
[[package]]
name = "serde_json"
version = "1.0.94"
version = "1.0.95"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1c533a59c9d8a93a09c6ab31f0fd5e5f4dd1b8fc9434804029839884765d04ea"
checksum = "d721eca97ac802aa7777b701877c8004d950fc142651367300d21c1cc0194744"
dependencies = [
"itoa",
"ryu",
@ -1837,9 +1886,9 @@ checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d"
[[package]]
name = "spin"
version = "0.9.6"
version = "0.9.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5d6e0250b93c8427a177b849d144a96d5acc57006149479403d7861ab721e34"
checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67"
dependencies = [
"lock_api",
]
@ -1969,6 +2018,12 @@ dependencies = [
"unicode-normalization",
]
[[package]]
name = "subtle"
version = "2.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601"
[[package]]
name = "syn"
version = "1.0.109"
@ -1982,9 +2037,9 @@ dependencies = [
[[package]]
name = "syn"
version = "2.0.10"
version = "2.0.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5aad1363ed6d37b84299588d62d3a7d95b5a5c2d9aad5c85609fda12afaa1f40"
checksum = "4c9da457c5285ac1f936ebd076af6dac17a61cfe7826f2076b4d015cf47bc8ec"
dependencies = [
"proc-macro2",
"quote",
@ -1993,15 +2048,15 @@ dependencies = [
[[package]]
name = "tempfile"
version = "3.4.0"
version = "3.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "af18f7ae1acd354b992402e9ec5864359d693cd8a79dcbef59f76891701c1e95"
checksum = "b9fbec84f381d5795b08656e4912bec604d162bff9291d6189a78f4c8ab87998"
dependencies = [
"cfg-if",
"fastrand",
"redox_syscall",
"redox_syscall 0.3.5",
"rustix",
"windows-sys 0.42.0",
"windows-sys 0.45.0",
]
[[package]]
@ -2053,7 +2108,7 @@ checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.10",
"syn 2.0.13",
]
[[package]]
@ -2109,14 +2164,13 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
[[package]]
name = "tokio"
version = "1.26.0"
version = "1.27.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "03201d01c3c27a29c8a5cee5b55a93ddae1ccf6f08f65365c2c918f8c1b76f64"
checksum = "d0de47a4eecbe11f498978a9b29d792f0d2692d1dd003650c24c76510e3bc001"
dependencies = [
"autocfg",
"bytes",
"libc",
"memchr",
"mio",
"num_cpus",
"pin-project-lite",
@ -2128,13 +2182,13 @@ dependencies = [
[[package]]
name = "tokio-macros"
version = "1.8.2"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d266c00fde287f55d3f1c3e96c500c362a2b8c695076ec180f27918820bc6df8"
checksum = "61a573bdc87985e9d6ddeed1b3d864e8a302c847e40d647746df2f1de209d1ce"
dependencies = [
"proc-macro2",
"quote",
"syn 1.0.109",
"syn 2.0.13",
]
[[package]]
@ -2563,7 +2617,7 @@ version = "0.44.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e745dab35a0c4c77aa3ce42d595e13d2003d6902d6b08c9ef5fc326d08da12b"
dependencies = [
"windows-targets",
"windows-targets 0.42.2",
]
[[package]]
@ -2572,7 +2626,7 @@ version = "0.46.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cdacb41e6a96a052c6cb63a144f24900236121c6f63f4f8219fef5977ecb0c25"
dependencies = [
"windows-targets",
"windows-targets 0.42.2",
]
[[package]]
@ -2581,13 +2635,13 @@ version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7"
dependencies = [
"windows_aarch64_gnullvm",
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_gnullvm",
"windows_x86_64_msvc",
"windows_aarch64_gnullvm 0.42.2",
"windows_aarch64_msvc 0.42.2",
"windows_i686_gnu 0.42.2",
"windows_i686_msvc 0.42.2",
"windows_x86_64_gnu 0.42.2",
"windows_x86_64_gnullvm 0.42.2",
"windows_x86_64_msvc 0.42.2",
]
[[package]]
@ -2596,7 +2650,16 @@ version = "0.45.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0"
dependencies = [
"windows-targets",
"windows-targets 0.42.2",
]
[[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.0",
]
[[package]]
@ -2605,13 +2668,28 @@ version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071"
dependencies = [
"windows_aarch64_gnullvm",
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_gnullvm",
"windows_x86_64_msvc",
"windows_aarch64_gnullvm 0.42.2",
"windows_aarch64_msvc 0.42.2",
"windows_i686_gnu 0.42.2",
"windows_i686_msvc 0.42.2",
"windows_x86_64_gnu 0.42.2",
"windows_x86_64_gnullvm 0.42.2",
"windows_x86_64_msvc 0.42.2",
]
[[package]]
name = "windows-targets"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b1eb6f0cd7c80c79759c929114ef071b87354ce476d9d94271031c0497adfd5"
dependencies = [
"windows_aarch64_gnullvm 0.48.0",
"windows_aarch64_msvc 0.48.0",
"windows_i686_gnu 0.48.0",
"windows_i686_msvc 0.48.0",
"windows_x86_64_gnu 0.48.0",
"windows_x86_64_gnullvm 0.48.0",
"windows_x86_64_msvc 0.48.0",
]
[[package]]
@ -2620,42 +2698,84 @@ version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8"
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc"
[[package]]
name = "windows_aarch64_msvc"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43"
[[package]]
name = "windows_aarch64_msvc"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3"
[[package]]
name = "windows_i686_gnu"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f"
[[package]]
name = "windows_i686_gnu"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241"
[[package]]
name = "windows_i686_msvc"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060"
[[package]]
name = "windows_i686_msvc"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00"
[[package]]
name = "windows_x86_64_gnu"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36"
[[package]]
name = "windows_x86_64_gnu"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953"
[[package]]
name = "windows_x86_64_msvc"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0"
[[package]]
name = "windows_x86_64_msvc"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a"
[[package]]
name = "yansi"
version = "0.5.1"

View File

@ -10,5 +10,6 @@ rocket = { version = "0.5.0-rc.3"}
rocket_dyn_templates = {version = "0.1.0-rc.3", features = [ "tera" ] }
log = "0.4"
env_logger = "0.10"
sqlx = { version = "0.6", features = ["sqlite", "runtime-tokio-rustls"] }
sqlx = { version = "0.6", features = ["sqlite", "runtime-tokio-rustls", "macros"] }
argon2 = "0.5"
base64 = "0.21"

View File

@ -1,7 +1,7 @@
CREATE TABLE IF NOT EXISTS "user" (
"id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
"name" text NOT NULL UNIQUE,
"pw" text,
"pw" text NOT NULL DEFAULT "",
"is_cox" boolean NOT NULL DEFAULT FALSE,
"is_admin" boolean NOT NULL DEFAULT FALSE,
"is_guest" boolean NOT NULL DEFAULT TRUE

View File

@ -1 +1,2 @@
pub mod model;
pub mod rest;

View File

@ -1,4 +1,5 @@
use rot::rest;
use rot::{model::user::Users, rest};
use sqlx::SqlitePool;
#[macro_use]
extern crate rocket;
@ -7,5 +8,9 @@ extern crate rocket;
async fn rocket() -> _ {
env_logger::init();
rest::start()
//let pool = SqlitePool::connect(":memory:").await.unwrap();
let pool = SqlitePool::connect("db.sqlite").await.unwrap(); //TODO: fixme
let users = Users::new(&pool).await.unwrap(); //TODO: fixme
rest::start(pool)
}

1
src/model/mod.rs Normal file
View File

@ -0,0 +1 @@
pub mod user;

130
src/model/user.rs Normal file
View File

@ -0,0 +1,130 @@
use std::ops::Deref;
use argon2::{password_hash::SaltString, Argon2, PasswordHash, PasswordHasher, PasswordVerifier};
use base64::{engine, prelude::BASE64_STANDARD_NO_PAD};
use rocket::{
request::{self, FromRequest},
Request,
};
use sqlx::{FromRow, SqlitePool};
#[derive(FromRow, Debug)]
pub struct User {
id: i64,
name: String,
pw: String,
is_cox: bool,
is_admin: bool,
is_guest: bool,
}
pub enum LoginError {
SqlxError(sqlx::Error),
InvalidAuthenticationCombo,
}
impl From<sqlx::Error> for LoginError {
fn from(sqlx_error: sqlx::Error) -> Self {
Self::SqlxError(sqlx_error)
}
}
impl User {
pub async fn find_by_name(db: &SqlitePool, name: String) -> Result<Self, sqlx::Error> {
let user: User = sqlx::query_as!(
User,
"
SELECT id, name, pw, is_cox, is_admin, is_guest
FROM user
WHERE name like ?
",
name
)
.fetch_one(db)
.await?;
Ok(user)
}
pub async fn login(db: &SqlitePool, name: String, pw: String) -> Result<Self, LoginError> {
let user = User::find_by_name(db, name).await?;
let argon2 = Argon2::default();
let salt = SaltString::from_b64("CdR4i0HA9e0CM").unwrap(); //TODO: generate salt for each user
let password_hash = argon2
.hash_password(&pw.as_bytes(), &salt)
.unwrap()
.to_string();
//TODO: fixme
let parsed_hash = PasswordHash::new(&password_hash).unwrap(); //TODO: fixme
//TODO: If user.pw == "" -> set new pw!
match Argon2::default()
.verify_password(base64::encode(pw.as_bytes()).as_bytes(), &parsed_hash)
{
Ok(_) => Ok(user),
Err(_) => Err(LoginError::InvalidAuthenticationCombo),
}
}
}
pub struct Users {
users: Vec<User>,
}
#[derive(Debug)]
pub enum Error {}
//#[rocket::async_trait]
//impl<'r> FromRequest<'r> for User {
// type Error = Error;
//
// async fn from_request(req: &'r Request<'_>) -> request::Outcome<Self, Self::Error> {
// //TODO: https://betterprogramming.pub/building-the-rust-web-app-multiple-users-and-authentication-5ca5988ddfe4
// }
//}
impl Deref for Users {
type Target = Vec<User>;
fn deref(&self) -> &Self::Target {
&self.users
}
}
impl Users {
pub async fn new(pool: &SqlitePool) -> Result<Self, sqlx::Error> {
let users: Vec<User> = sqlx::query_as!(
User,
r#"
SELECT id, name, pw, is_cox, is_admin, is_guest
FROM user
"#,
)
.fetch_all(pool)
.await?;
Ok(Self { users })
}
}
#[cfg(test)]
mod test {
use super::Users;
use sqlx::SqlitePool;
#[sqlx::test]
fn user_with_test_db() {
let pool = SqlitePool::connect(":memory:").await.unwrap();
sqlx::query_file!("./migration.sql")
.execute(&pool)
.await
.unwrap();
sqlx::query_file!("./seeds.sql")
.execute(&pool)
.await
.unwrap();
let users = Users::new(&pool).await.unwrap();
assert_eq!(users.len(), 4);
}
}

47
src/rest/auth.rs Normal file
View File

@ -0,0 +1,47 @@
use rocket::{
form::Form,
get, post,
request::FlashMessage,
response::{status, Flash, Redirect},
routes, FromForm, Responder, Route, State,
};
use rocket_dyn_templates::{context, tera, Template};
use sqlx::SqlitePool;
use crate::model::user::{self, User, Users};
#[get("/")]
async fn index(flash: Option<FlashMessage<'_>>) -> Template {
let mut context = tera::Context::new();
if let Some(msg) = flash {
context.insert("flash", &msg.into_inner());
}
Template::render("auth/login", context.into_json())
}
#[derive(FromForm)]
struct LoginForm {
name: String,
password: String,
}
#[post("/", data = "<login>")]
async fn login(login: Form<LoginForm>, db: &State<SqlitePool>) -> Flash<Redirect> {
let user = User::login(db, login.name.clone(), login.password.clone()).await;
//TODO: be able to use for find_by_name. This would get rid of the following match clause.
let user = match user {
Ok(user) => user,
Err(_) => {
return Flash::error(Redirect::to("/auth"), "Falscher Benutzername/Passwort");
}
};
Flash::success(Redirect::to("/"), "Login erfolgreich")
}
pub fn routes() -> Vec<Route> {
routes![index, login]
}

View File

@ -1,14 +1,21 @@
use rocket::{get, routes, Build, Rocket};
use rocket_dyn_templates::Template;
use rocket_dyn_templates::{context, Template};
use sqlx::SqlitePool;
use crate::model::user::Users;
mod auth;
#[get("/")]
fn index() -> &'static str {
"Hello, world!"
fn index() -> Template {
Template::render("index", context! {})
}
pub fn start() -> Rocket<Build> {
pub fn start(db: SqlitePool) -> Rocket<Build> {
rocket::build()
.manage(db)
.mount("/", routes![index])
.mount("/auth", auth::routes())
.attach(Template::fairing())
}

View File

@ -0,0 +1,26 @@
{% if flash %}
{% if flash.0 == "success" %}
<div class="row">
<div class="one-column p-1 text-white bg-green mb-3 light text-center">
{{ flash.1 }}
</div>
</div>
{% endif %}
{% if flash.0 == "error" %}
<div class="row">
<div class="one-column p-1 text-white bg-red mb-3 bold text-center">
{{ flash.1 }}
</div>
</div>
{% endif %}
{% endif %}
<form method="post" action="/auth">
<label for="name">Name</label>
<input type="text" id="name" name="name" />
<label for="password">Passwort</label>
<input type="password" id="password" name="password" />
<button type="submit">Login</button>
</form>

17
templates/base.html.tera Normal file
View File

@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
{% block content %}
{% endblock content %}
</body>
</html>

24
templates/index.html.tera Normal file
View File

@ -0,0 +1,24 @@
{% extends "base" %}
{% block content %}
{% if flash %}
{% if flash.0 == "success" %}
<div class="row">
<div class="one-column p-1 text-white bg-green mb-3 light text-center">
{{ flash.1 }}
</div>
</div>
{% endif %}
{% if flash.0 == "error" %}
<div class="row">
<div class="one-column p-1 text-white bg-red mb-3 bold text-center">
{{ flash.1 }}
</div>
</div>
{% endif %}
{% endif %}
<h1>Hi</h1>
{% endblock content %}