From fd0405f55a71445414b06330f16d9dfc359d904f Mon Sep 17 00:00:00 2001 From: Erin Nova Date: Sat, 17 Jul 2021 19:41:41 -0400 Subject: [PATCH 01/10] Broken code please help I'm dumb --- Cargo.lock | 801 +++++++++++++++++++++++++++++++++++++++++-------- Cargo.toml | 8 +- README.md | 3 + src/auth.rs | 92 ------ src/chat.rs | 15 + src/main.rs | 8 +- src/message.rs | 8 +- 7 files changed, 717 insertions(+), 218 deletions(-) create mode 100644 src/chat.rs diff --git a/Cargo.lock b/Cargo.lock index 09ecd54..f75f5a2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,5 +1,7 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +version = 3 + [[package]] name = "aho-corasick" version = "0.7.18" @@ -25,9 +27,9 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "648ed8c8d2ce5409ccd57453d9d1b214b342a0d69376a6feda1fd6cae3299308" dependencies = [ - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.27", + "quote 1.0.9", + "syn 1.0.73", ] [[package]] @@ -36,9 +38,9 @@ version = "0.1.50" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b98e84bbb4cbcdd97da190ba0c58a1bb0de2c1fdf67d159e192ed766aeca722" dependencies = [ - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.27", + "quote 1.0.9", + "syn 1.0.73", ] [[package]] @@ -58,7 +60,7 @@ checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" dependencies = [ "hermit-abi", "libc", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -73,6 +75,22 @@ version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4521f3e3d031370679b3b140beb36dfe4801b09ac77e30c61941f97df3ef28b" +[[package]] +name = "base64" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "489d6c0ed21b11d038c31b6ceccca973e65d73ba3bd8ecb9a2babf5546164643" +dependencies = [ + "byteorder", + "safemem", +] + +[[package]] +name = "base64" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" + [[package]] name = "binascii" version = "0.1.4" @@ -91,6 +109,12 @@ version = "3.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c59e7af012c713f529e7a3ee57ce9b31ddd858d4b512923602f74608b009631" +[[package]] +name = "byteorder" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" + [[package]] name = "bytes" version = "1.0.1" @@ -103,6 +127,12 @@ version = "1.0.68" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4a72c244c1ff497a746a7e1fb3d14bd08420ecda70c8f25c7112f2781652d787" +[[package]] +name = "cfg-if" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" + [[package]] name = "cfg-if" version = "1.0.0" @@ -120,7 +150,7 @@ dependencies = [ "num-traits", "serde", "time 0.1.43", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -135,15 +165,25 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" +[[package]] +name = "cookie" +version = "0.11.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80f6044740a4a516b8aac14c140cdf35c1a640b1bd6b98b6224e49143b2f1566" +dependencies = [ + "percent-encoding 2.1.0", + "time 0.1.43", +] + [[package]] name = "cookie" version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ffdf8865bac3d9a3bde5bde9088ca431b11f5d37c7a578b8086af77248b76627" dependencies = [ - "percent-encoding", + "percent-encoding 2.1.0", "time 0.2.27", - "version_check", + "version_check 0.9.3", ] [[package]] @@ -153,10 +193,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40eebddd2156ce1bb37b20bbe5151340a31828b1f2d22ba4141f3531710e38df" dependencies = [ "convert_case", - "proc-macro2", - "quote", + "proc-macro2 1.0.27", + "quote 1.0.9", "rustc_version 0.3.3", - "syn", + "syn 1.0.73", +] + +[[package]] +name = "devise" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74e04ba2d03c5fa0d954c061fc8c9c288badadffc272ebb87679a89846de3ed3" +dependencies = [ + "devise_codegen 0.2.0", + "devise_core 0.2.0", ] [[package]] @@ -165,8 +215,18 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "411cf45ac38f00df3679689616649dc12607b846db171780bb790b514a042832" dependencies = [ - "devise_codegen", - "devise_core", + "devise_codegen 0.3.0", + "devise_core 0.3.0", +] + +[[package]] +name = "devise_codegen" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "066ceb7928ca93a9bedc6d0e612a8a0424048b0ab1f75971b203d01420c055d7" +dependencies = [ + "devise_core 0.2.0", + "quote 0.6.13", ] [[package]] @@ -175,8 +235,20 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2cf7081f06822f1787e29359354426132cf832cc977d7a8ff747848631462ad1" dependencies = [ - "devise_core", - "quote", + "devise_core 0.3.0", + "quote 1.0.9", +] + +[[package]] +name = "devise_core" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf41c59b22b5e3ec0ea55c7847e5f358d340f3a8d6d53a5cf4f1564967f96487" +dependencies = [ + "bitflags", + "proc-macro2 0.4.30", + "quote 0.6.13", + "syn 0.15.44", ] [[package]] @@ -186,10 +258,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "80c23631758736875d7ce08f847f296b4001b72cf90878e85b47df7ac5442147" dependencies = [ "bitflags", - "proc-macro2", + "proc-macro2 1.0.27", "proc-macro2-diagnostics", - "quote", - "syn", + "quote 1.0.9", + "syn 1.0.73", ] [[package]] @@ -210,7 +282,7 @@ version = "0.8.28" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "80df024fbc5ac80f87dfef0d9f5209a252f2a497f7f42944cff24d8253cac065" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", ] [[package]] @@ -221,7 +293,7 @@ checksum = "a19187fea3ac7e84da7dacf48de0c45d63c6a76f9490dae389aead16c243fce3" dependencies = [ "atty", "humantime", - "log", + "log 0.4.14", "regex", "termcolor", ] @@ -233,11 +305,23 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "790b4292c72618abbab50f787a477014fe15634f96291de45672ce46afe122df" dependencies = [ "atomic", - "pear", + "pear 0.2.3", "serde", - "toml", + "toml 0.5.8", "uncased", - "version_check", + "version_check 0.9.3", +] + +[[package]] +name = "filetime" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d34cfa13a63ae058bfa601fe9e313bbdb3746427c1459185464ce0fcf62e1e8" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "redox_syscall", + "winapi 0.3.9", ] [[package]] @@ -246,6 +330,41 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "fsevent" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ab7d1bd1bd33cc98b0889831b72da23c0aa4df9cec7e0702f46ecea04b35db6" +dependencies = [ + "bitflags", + "fsevent-sys", +] + +[[package]] +name = "fsevent-sys" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f41b048a94555da0f42f1d632e2e19510084fb8e303b0daa2816e733fb3644a0" +dependencies = [ + "libc", +] + +[[package]] +name = "fuchsia-zircon" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" +dependencies = [ + "bitflags", + "fuchsia-zircon-sys", +] + +[[package]] +name = "fuchsia-zircon-sys" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" + [[package]] name = "futures" version = "0.3.15" @@ -302,9 +421,9 @@ checksum = "a4c40298486cdf52cc00cd6d6987892ba502c7656a16a4192a9992b1ccedd121" dependencies = [ "autocfg", "proc-macro-hack", - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.27", + "quote 1.0.9", + "syn 1.0.73", ] [[package]] @@ -348,9 +467,9 @@ checksum = "c1d9279ca822891c1a4dae06d185612cf8fc6acfe5dff37781b41297811b12ee" dependencies = [ "cc", "libc", - "log", + "log 0.4.14", "rustversion", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -359,7 +478,7 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "libc", "wasi", ] @@ -444,6 +563,25 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" +[[package]] +name = "hyper" +version = "0.10.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a0652d9a2609a968c14be1a9ea00bf4b1d64e2e1f53a1b51b6fff3a6e829273" +dependencies = [ + "base64 0.9.3", + "httparse", + "language-tags", + "log 0.3.9", + "mime 0.2.6", + "num_cpus", + "time 0.1.43", + "traitobject", + "typeable", + "unicase", + "url", +] + [[package]] name = "hyper" version = "0.14.10" @@ -468,6 +606,17 @@ dependencies = [ "want", ] +[[package]] +name = "idna" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38f09e0f0b1fb55fdee1f17470ad800da77af5186a1a76c026b679358b7e844e" +dependencies = [ + "matches", + "unicode-bidi", + "unicode-normalization", +] + [[package]] name = "indexmap" version = "1.7.0" @@ -485,13 +634,42 @@ version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3094308123a0e9fd59659ce45e22de9f53fc1d2ac6e1feb9fef988e4f76cad77" +[[package]] +name = "inotify" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4816c66d2c8ae673df83366c18341538f234a26d65a9ecea5c348b453ac1d02f" +dependencies = [ + "bitflags", + "inotify-sys", + "libc", +] + +[[package]] +name = "inotify-sys" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e05c02b5e89bff3b946cedeca278abc628fe811e604f027c45a8aa3cf793d0eb" +dependencies = [ + "libc", +] + [[package]] name = "instant" version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "61124eeebbd69b8190558df225adf7e4caafce0d743919e5d6b19652314ec5ec" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", +] + +[[package]] +name = "iovec" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e" +dependencies = [ + "libc", ] [[package]] @@ -500,12 +678,34 @@ version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736" +[[package]] +name = "kernel32-sys" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" +dependencies = [ + "winapi 0.2.8", + "winapi-build", +] + +[[package]] +name = "language-tags" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a91d884b6667cd606bb5a69aa0c99ba811a115fc68915e7056ec08a46e93199a" + [[package]] name = "lazy_static" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +[[package]] +name = "lazycell" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" + [[package]] name = "libc" version = "0.2.97" @@ -521,13 +721,22 @@ dependencies = [ "scopeguard", ] +[[package]] +name = "log" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" +dependencies = [ + "log 0.4.14", +] + [[package]] name = "log" version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", ] [[package]] @@ -536,25 +745,59 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2111607c723d7857e0d8299d5ce7a0bf4b844d3e44f8de136b13da513eaf8fc4" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "generator", "scoped-tls", "serde", "serde_json", ] +[[package]] +name = "matches" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" + [[package]] name = "memchr" version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b16bd47d9e329435e309c58469fe0791c2d0d1ba96ec0954152a5ae2b04387dc" +[[package]] +name = "mime" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba626b8a6de5da682e1caa06bdb42a335aee5a84db8e5046a3e8ab17ba0a3ae0" +dependencies = [ + "log 0.3.9", +] + [[package]] name = "mime" version = "0.3.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" +[[package]] +name = "mio" +version = "0.6.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4afd66f5b91bf2a3bc13fad0e21caedac168ca4c707504e75585648ae80e4cc4" +dependencies = [ + "cfg-if 0.1.10", + "fuchsia-zircon", + "fuchsia-zircon-sys", + "iovec", + "kernel32-sys", + "libc", + "log 0.4.14", + "miow 0.2.2", + "net2", + "slab", + "winapi 0.2.8", +] + [[package]] name = "mio" version = "0.7.13" @@ -562,10 +805,34 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8c2bdb6314ec10835cd3293dd268473a835c02b7b352e788be788b3c6ca6bb16" dependencies = [ "libc", - "log", - "miow", + "log 0.4.14", + "miow 0.3.7", "ntapi", - "winapi", + "winapi 0.3.9", +] + +[[package]] +name = "mio-extras" +version = "2.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52403fe290012ce777c4626790c8951324a2b9e3316b3143779c72b029742f19" +dependencies = [ + "lazycell", + "log 0.4.14", + "mio 0.6.23", + "slab", +] + +[[package]] +name = "miow" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebd808424166322d4a38da87083bfddd3ac4c131334ed55856112eb06d46944d" +dependencies = [ + "kernel32-sys", + "net2", + "winapi 0.2.8", + "ws2_32-sys", ] [[package]] @@ -574,7 +841,7 @@ version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b9f1c5b025cda876f66ef43a113f91ebc9f4ccef34843000e0adf6ebbab84e21" dependencies = [ - "winapi", + "winapi 0.3.9", ] [[package]] @@ -589,13 +856,42 @@ dependencies = [ "futures-util", "http", "httparse", - "log", - "mime", + "log 0.4.14", + "mime 0.3.16", "spin", "tokio", "tokio-util", "twoway", - "version_check", + "version_check 0.9.3", +] + +[[package]] +name = "net2" +version = "0.2.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "391630d12b68002ae1e25e8f974306474966550ad82dac6886fb8910c19568ae" +dependencies = [ + "cfg-if 0.1.10", + "libc", + "winapi 0.3.9", +] + +[[package]] +name = "notify" +version = "4.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae03c8c853dba7bfd23e571ff0cff7bc9dceb40a4cd684cd1681824183f45257" +dependencies = [ + "bitflags", + "filetime", + "fsevent", + "fsevent-sys", + "inotify", + "libc", + "mio 0.6.23", + "mio-extras", + "walkdir", + "winapi 0.3.9", ] [[package]] @@ -604,7 +900,7 @@ version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f6bb902e437b6d86e03cce10a7e2af662292c5dfef23b65899ea3ac9354ad44" dependencies = [ - "winapi", + "winapi 0.3.9", ] [[package]] @@ -659,12 +955,21 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fa7a782938e745763fe6907fc6ba86946d72f49fe7e21de074e08128a99fb018" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "instant", "libc", "redox_syscall", "smallvec", - "winapi", + "winapi 0.3.9", +] + +[[package]] +name = "pear" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5320f212db967792b67cfe12bd469d08afd6318a249bd917d5c19bc92200ab8a" +dependencies = [ + "pear_codegen 0.1.4", ] [[package]] @@ -674,7 +979,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "15e44241c5e4c868e3eaa78b7c1848cadd6344ed4f54d029832d32b415a58702" dependencies = [ "inlinable_string", - "pear_codegen", + "pear_codegen 0.2.3", + "yansi", +] + +[[package]] +name = "pear_codegen" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfc1c836fdc3d1ef87c348b237b5b5c4dff922156fb2d968f57734f9669768ca" +dependencies = [ + "proc-macro2 0.4.30", + "quote 0.6.13", + "syn 0.15.44", + "version_check 0.9.3", "yansi", ] @@ -684,12 +1002,18 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "82a5ca643c2303ecb740d506539deba189e16f2754040a42901cd8105d0282d0" dependencies = [ - "proc-macro2", + "proc-macro2 1.0.27", "proc-macro2-diagnostics", - "quote", - "syn", + "quote 1.0.9", + "syn 1.0.73", ] +[[package]] +name = "percent-encoding" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831" + [[package]] name = "percent-encoding" version = "2.1.0" @@ -719,13 +1043,15 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "pogchat" -version = "0.2.0" +version = "0.3.0" dependencies = [ "chrono", "env_logger", - "log", - "rocket", + "log 0.4.14", + "rocket 0.5.0-rc.1", + "rocket_contrib", "serde", + "serde_derive", "serde_json", "sha1", "uuid", @@ -749,13 +1075,22 @@ version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bc881b2c22681370c6a780e47af9840ef841837bc98118431d4e1868bd0c1086" +[[package]] +name = "proc-macro2" +version = "0.4.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" +dependencies = [ + "unicode-xid 0.1.0", +] + [[package]] name = "proc-macro2" version = "1.0.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0d8caf72986c1a598726adc988bb5984792ef84f5ee5aa50209145ee8077038" dependencies = [ - "unicode-xid", + "unicode-xid 0.2.2", ] [[package]] @@ -764,20 +1099,29 @@ version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4bf29726d67464d49fa6224a1d07936a8c08bb3fba727c7493f6cf1616fdaada" dependencies = [ - "proc-macro2", - "quote", - "syn", - "version_check", + "proc-macro2 1.0.27", + "quote 1.0.9", + "syn 1.0.73", + "version_check 0.9.3", "yansi", ] +[[package]] +name = "quote" +version = "0.6.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1" +dependencies = [ + "proc-macro2 0.4.30", +] + [[package]] name = "quote" version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" dependencies = [ - "proc-macro2", + "proc-macro2 1.0.27", ] [[package]] @@ -844,9 +1188,9 @@ version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4c38e3aecd2b21cb3959637b883bb3714bc7e43f0268b9a29d3743ee3e55cdd2" dependencies = [ - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.27", + "quote 1.0.9", + "syn 1.0.73", ] [[package]] @@ -872,7 +1216,28 @@ version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" dependencies = [ - "winapi", + "winapi 0.3.9", +] + +[[package]] +name = "rocket" +version = "0.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a7ab1dfdc75bb8bd2be381f37796b1b300c45a3c9145b34d86715e8dd90bf28" +dependencies = [ + "atty", + "base64 0.13.0", + "log 0.4.14", + "memchr", + "num_cpus", + "pear 0.1.4", + "rocket_codegen 0.4.10", + "rocket_http 0.4.10", + "state 0.4.2", + "time 0.1.43", + "toml 0.4.10", + "version_check 0.9.3", + "yansi", ] [[package]] @@ -891,7 +1256,7 @@ dependencies = [ "figment", "futures", "indexmap", - "log", + "log 0.4.14", "memchr", "multer", "num_cpus", @@ -899,17 +1264,32 @@ dependencies = [ "pin-project-lite", "rand", "ref-cast", - "rocket_codegen", - "rocket_http", + "rocket_codegen 0.5.0-rc.1", + "rocket_http 0.5.0-rc.1", "serde", - "state", + "state 0.5.2", "tempfile", "time 0.2.27", "tokio", "tokio-stream", "tokio-util", "ubyte", - "version_check", + "version_check 0.9.3", + "yansi", +] + +[[package]] +name = "rocket_codegen" +version = "0.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1729e687d6d2cf434d174da84fb948f7fef4fac22d20ce94ca61c28b72dbcf9f" +dependencies = [ + "devise 0.2.0", + "glob", + "indexmap", + "quote 0.6.13", + "rocket_http 0.4.10", + "version_check 0.9.3", "yansi", ] @@ -919,14 +1299,44 @@ version = "0.5.0-rc.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "66f5fa462f7eb958bba8710c17c5d774bbbd59809fa76fb1957af7e545aea8bb" dependencies = [ - "devise", + "devise 0.3.0", "glob", "indexmap", - "proc-macro2", - "quote", - "rocket_http", - "syn", - "unicode-xid", + "proc-macro2 1.0.27", + "quote 1.0.9", + "rocket_http 0.5.0-rc.1", + "syn 1.0.73", + "unicode-xid 0.2.2", +] + +[[package]] +name = "rocket_contrib" +version = "0.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b6303dccab46dce6c7ac26c9b9d8d8cde1b19614b027c3f913be6611bff6d9b" +dependencies = [ + "log 0.4.14", + "notify", + "rocket 0.4.10", + "serde", + "serde_json", +] + +[[package]] +name = "rocket_http" +version = "0.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6131e6e6d38a9817f4a494ff5da95971451c2eb56a53915579fc9c80f6ef0117" +dependencies = [ + "cookie 0.11.4", + "hyper 0.10.16", + "indexmap", + "pear 0.1.4", + "percent-encoding 1.0.1", + "smallvec", + "state 0.4.2", + "time 0.1.43", + "unicode-xid 0.1.0", ] [[package]] @@ -935,23 +1345,23 @@ version = "0.5.0-rc.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "23c8b7d512d2fcac2316ebe590cde67573844b99e6cc9ee0f53375fa16e25ebd" dependencies = [ - "cookie", + "cookie 0.15.0", "either", "http", - "hyper", + "hyper 0.14.10", "indexmap", - "log", + "log 0.4.14", "memchr", - "mime", + "mime 0.3.16", "parking_lot", - "pear", - "percent-encoding", + "pear 0.2.3", + "percent-encoding 2.1.0", "pin-project-lite", "ref-cast", "serde", "smallvec", "stable-pattern", - "state", + "state 0.5.2", "time 0.2.27", "tokio", "uncased", @@ -987,6 +1397,21 @@ version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" +[[package]] +name = "safemem" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef703b7cb59335eae2eb93ceb664c0eb7ea6bf567079d843e09420219668e072" + +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + [[package]] name = "scoped-tls" version = "1.0.0" @@ -1047,9 +1472,9 @@ version = "1.0.126" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "963a7dbc9895aeac7ac90e74f34a5d5261828f79df35cbed41e10189d3804d43" dependencies = [ - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.27", + "quote 1.0.9", + "syn 1.0.73", ] [[package]] @@ -1097,7 +1522,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e3dfc207c526015c632472a77be09cf1b6e46866581aecae5cc38fb4235dea2" dependencies = [ "libc", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -1121,9 +1546,15 @@ version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e113fb6f3de07a243d434a56ec6f186dfd51cb08448239fe7bcae73f87ff28ff" dependencies = [ - "version_check", + "version_check 0.9.3", ] +[[package]] +name = "state" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3015a7d0a5fd5105c91c3710d42f9ccf0abfb287d62206484dcc67f9569a6483" + [[package]] name = "state" version = "0.5.2" @@ -1153,11 +1584,11 @@ version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c87a60a40fccc84bef0652345bbbbbe20a605bf5d0ce81719fc476f5c03b50ef" dependencies = [ - "proc-macro2", - "quote", + "proc-macro2 1.0.27", + "quote 1.0.9", "serde", "serde_derive", - "syn", + "syn 1.0.73", ] [[package]] @@ -1167,13 +1598,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "58fa5ff6ad0d98d1ffa8cb115892b6e69d67799f6763e162a1c9db421dc22e11" dependencies = [ "base-x", - "proc-macro2", - "quote", + "proc-macro2 1.0.27", + "quote 1.0.9", "serde", "serde_derive", "serde_json", "sha1", - "syn", + "syn 1.0.73", ] [[package]] @@ -1182,15 +1613,26 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "213701ba3370744dcd1a12960caa4843b3d68b4d1c0a5d575e0d65b2ee9d16c0" +[[package]] +name = "syn" +version = "0.15.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ca4b3b69a77cbe1ffc9e198781b7acb0c7365a883670e8f1c1bc66fba79a5c5" +dependencies = [ + "proc-macro2 0.4.30", + "quote 0.6.13", + "unicode-xid 0.1.0", +] + [[package]] name = "syn" version = "1.0.73" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f71489ff30030d2ae598524f61326b902466f72a0fb1a8564c001cc63425bcc7" dependencies = [ - "proc-macro2", - "quote", - "unicode-xid", + "proc-macro2 1.0.27", + "quote 1.0.9", + "unicode-xid 0.2.2", ] [[package]] @@ -1199,12 +1641,12 @@ version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dac1c663cfc93810f88aed9b8941d48cabf856a1b111c29a40439018d870eb22" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "libc", "rand", "redox_syscall", "remove_dir_all", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -1223,7 +1665,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438" dependencies = [ "libc", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -1237,8 +1679,8 @@ dependencies = [ "standback", "stdweb", "time-macros", - "version_check", - "winapi", + "version_check 0.9.3", + "winapi 0.3.9", ] [[package]] @@ -1258,12 +1700,27 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fd3c141a1b43194f3f56a1411225df8646c55781d5f26db825b3d98507eb482f" dependencies = [ "proc-macro-hack", - "proc-macro2", - "quote", + "proc-macro2 1.0.27", + "quote 1.0.9", "standback", - "syn", + "syn 1.0.73", ] +[[package]] +name = "tinyvec" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b5220f05bb7de7f3f53c7c065e1199b3172696fe2db9f9c4d8ad9b4ee74c342" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" + [[package]] name = "tokio" version = "1.8.1" @@ -1274,13 +1731,13 @@ dependencies = [ "bytes", "libc", "memchr", - "mio", + "mio 0.7.13", "num_cpus", "once_cell", "pin-project-lite", "signal-hook-registry", "tokio-macros", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -1289,9 +1746,9 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "54473be61f4ebe4efd09cec9bd5d16fa51d70ea0192213d754d2d500457db110" dependencies = [ - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.27", + "quote 1.0.9", + "syn 1.0.73", ] [[package]] @@ -1314,11 +1771,20 @@ dependencies = [ "bytes", "futures-core", "futures-sink", - "log", + "log 0.4.14", "pin-project-lite", "tokio", ] +[[package]] +name = "toml" +version = "0.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "758664fc71a3a69038656bee8b6be6477d2a6c315a6b81f7081f591bffa4111f" +dependencies = [ + "serde", +] + [[package]] name = "toml" version = "0.5.8" @@ -1340,7 +1806,7 @@ version = "0.1.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09adeb8c97449311ccd28a427f96fb563e7fd31aabf994189879d9da2394b89d" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "pin-project-lite", "tracing-core", ] @@ -1354,6 +1820,12 @@ dependencies = [ "lazy_static", ] +[[package]] +name = "traitobject" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "efd1f82c56340fdf16f2a953d7bda4f8fdffba13d93b00844c25572110b26079" + [[package]] name = "try-lock" version = "0.2.3" @@ -1370,6 +1842,12 @@ dependencies = [ "unchecked-index", ] +[[package]] +name = "typeable" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1410f6f91f21d1612654e7cc69193b0334f909dcf2c790c4826254fbb86f8887" + [[package]] name = "ubyte" version = "0.10.1" @@ -1392,7 +1870,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5baeed7327e25054889b9bd4f975f32e5f4c5d434042d59ab6cd4142c0a76ed0" dependencies = [ "serde", - "version_check", + "version_check 0.9.3", ] [[package]] @@ -1401,12 +1879,56 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eeba86d422ce181a719445e51872fa30f1f7413b62becb52e95ec91aa262d85c" +[[package]] +name = "unicase" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f4765f83163b74f957c797ad9253caf97f103fb064d3999aea9568d09fc8a33" +dependencies = [ + "version_check 0.1.5", +] + +[[package]] +name = "unicode-bidi" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eeb8be209bb1c96b7c177c7420d26e04eccacb0eeae6b980e35fcb74678107e0" +dependencies = [ + "matches", +] + +[[package]] +name = "unicode-normalization" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d54590932941a9e9266f0832deed84ebe1bf2e4c9e4a3554d393d18f5e854bf9" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-xid" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" + [[package]] name = "unicode-xid" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" +[[package]] +name = "url" +version = "1.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd4e7c0d531266369519a4aa4f399d748bd37043b00bde1e4ff1f60a120b355a" +dependencies = [ + "idna", + "matches", + "percent-encoding 1.0.1", +] + [[package]] name = "uuid" version = "0.8.2" @@ -1417,19 +1939,36 @@ dependencies = [ "serde", ] +[[package]] +name = "version_check" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd" + [[package]] name = "version_check" version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe" +[[package]] +name = "walkdir" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "808cf2735cd4b6866113f648b791c6adc5714537bc222d9347bb203386ffda56" +dependencies = [ + "same-file", + "winapi 0.3.9", + "winapi-util", +] + [[package]] name = "want" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" dependencies = [ - "log", + "log 0.4.14", "try-lock", ] @@ -1445,7 +1984,7 @@ version = "0.2.74" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d54ee1d4ed486f78874278e63e4069fc1ab9f6a18ca492076ffb90c5eb2997fd" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "wasm-bindgen-macro", ] @@ -1457,10 +1996,10 @@ checksum = "3b33f6a0694ccfea53d94db8b2ed1c3a8a4c86dd936b13b9f0a15ec4a451b900" dependencies = [ "bumpalo", "lazy_static", - "log", - "proc-macro2", - "quote", - "syn", + "log 0.4.14", + "proc-macro2 1.0.27", + "quote 1.0.9", + "syn 1.0.73", "wasm-bindgen-shared", ] @@ -1470,7 +2009,7 @@ version = "0.2.74" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "088169ca61430fe1e58b8096c24975251700e7b1f6fd91cc9d59b04fb9b18bd4" dependencies = [ - "quote", + "quote 1.0.9", "wasm-bindgen-macro-support", ] @@ -1480,9 +2019,9 @@ version = "0.2.74" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "be2241542ff3d9f241f5e2cb6dd09b37efe786df8851c54957683a49f0987a97" dependencies = [ - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.27", + "quote 1.0.9", + "syn 1.0.73", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -1493,6 +2032,12 @@ version = "0.2.74" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d7cff876b8f18eed75a66cf49b65e7f967cb354a7aa16003fb55dbfd25b44b4f" +[[package]] +name = "winapi" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" + [[package]] name = "winapi" version = "0.3.9" @@ -1503,6 +2048,12 @@ dependencies = [ "winapi-x86_64-pc-windows-gnu", ] +[[package]] +name = "winapi-build" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" + [[package]] name = "winapi-i686-pc-windows-gnu" version = "0.4.0" @@ -1515,7 +2066,7 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" dependencies = [ - "winapi", + "winapi 0.3.9", ] [[package]] @@ -1524,6 +2075,16 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "ws2_32-sys" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" +dependencies = [ + "winapi 0.2.8", + "winapi-build", +] + [[package]] name = "yansi" version = "0.5.0" diff --git a/Cargo.toml b/Cargo.toml index 0aeaff9..b177fb0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pogchat" -version = "0.2.0" +version = "0.3.0" authors = ["Erin Nova "] edition = "2018" @@ -15,3 +15,9 @@ uuid = { version = "0.8.1", features = ["serde", "v4"] } log = "0.4.0" env_logger = "0.8.4" chrono = { version = "0.4.11", features = ["serde"] } +serde_derive = "1.0" + +[dependencies.rocket_contrib] +version = "0.4.10" +default-features = false +features = ["json"] diff --git a/README.md b/README.md index 0c38579..73e5848 100644 --- a/README.md +++ b/README.md @@ -29,3 +29,6 @@ Whenever user sends a message, client will send message & token and backend will - [ ] Basic messaging system - [ ] Token generation & storage - [x] Pronouns +- [ ] Change pronouns +- [ ] User management (banning, etc.) +- [ ] Blacklist words from chat/names diff --git a/src/auth.rs b/src/auth.rs index eb06aea..4fc38a7 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -20,99 +20,7 @@ pub fn index() -> &'static str { `GET /api/about/pronouns/` Get the pronouns of a user" } -/* -// The output is wrapped in a Result to allow matching on errors -// Returns an Iterator to the Reader of the lines of the file. -fn read_lines

(filename: P) -> io::Result>> -where P: AsRef, { - let file = File::open(filename)?; - Ok(io::BufReader::new(file).lines()) -} -// Function to read json from file into the vector -fn read_json() -> Vec { - // Create path to file - let path = Path::new("users.json"); - let display = path.display(); - - let mut users: Vec = Vec::new(); // Create an empty vector of users - - // Read through the lines and append them to the array - if let Ok(lines) = read_lines(&path) { - for line in lines { - if let Ok(user) = line { - info!("read {} from json file {}", display, &user); - // Parse line from file into a data structure - let user: User = serde_json::from_str(&user).unwrap(); - users.push(user); - } - } - } - return users; -} - -// Function to append the last value of the users vector to the file -fn append_json(users_list: &Vec) -> Result<()> { - // Create a file to write to - let path = Path::new("users.json"); - let display = path.display(); - - let mut file = match OpenOptions::new() - .write(true) - .create(true) - .append(true) - .open(&path){ - Err(why) => panic!("couldn't create {}: {}", display, why), - Ok(file) => file, - }; - - // Serialize the last user value - let users_json = serde_json::to_string(&users_list[users_list.len()-1])?; - - // Write to the file - match file.write_all(users_json.as_bytes()) { - Err(why) => panic!("couldn't write to {}: {}", display, why), - Ok(_) => info!("succesfully wrote to {}", display), - }; - // Add newline - match file.write_all("\n".as_bytes()) { - Err(why) => panic!("couldn't write to {}: {}", display, why), - Ok(_) => info!("succesfully wrote to {}", display), - }; - Ok(()) -} - -// Function to write whole vector of users to file -fn write_json(users_list: &Vec) -> Result<()> { - // Create a file to write to - let path = Path::new("users.json"); - let display = path.display(); - - let mut file = match OpenOptions::new() - .write(true) - .create(true) - .open(&path){ - Err(why) => panic!("couldn't create {}: {}", display, why), - Ok(file) => file, - }; - - let mut users_json = String::new(); - for i in 0..users_list.len() { - // Serialize the users - users_json += &serde_json::to_string(&users_list[i])?; - if i <= users_list.len()-2 { // don't append newline if it's the last element - users_json += "\n"; - } - } - - // Write to the file - match file.write_all(users_json.as_bytes()) { - Err(why) => panic!("couldn't write to {}: {}", display, why), - Ok(_) => info!("succesfully wrote to {}", display), - }; - Ok(()) -} -*/ // Post request to register a user and pin #[post("/api/register///")] pub fn register_user(name: &str, pin: i32, pronouns: &str) -> String { diff --git a/src/chat.rs b/src/chat.rs new file mode 100644 index 0000000..6c3ed26 --- /dev/null +++ b/src/chat.rs @@ -0,0 +1,15 @@ +/* Contains Rocket code for chat/message functionality */ +extern crate log; +extern crate rocket_contrib; +use crate::message::Message; +extern crate serde_derive; +use rocket_contrib::json::{Json, JsonValue}; +use rocket::{data::FromData, response::Responder}; + +#[post("/api/message/send", format = "json", data = "")] +pub fn send_message(message: Json) -> JsonValue { + json!({ + "status": "ok", + "reason": "bruh" + }) +} diff --git a/src/main.rs b/src/main.rs index a26a97a..1c124a1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,12 +1,14 @@ -#[macro_use] -extern crate log; +#[macro_use] extern crate log; #[macro_use] extern crate rocket; +#[macro_use] extern crate rocket_contrib; + use rocket::fairing::AdHoc; mod auth; mod user; mod message; mod file_io; +mod chat; #[launch] fn rocket() -> _ { @@ -22,7 +24,7 @@ fn rocket() -> _ { rocket::build() .mount( "/", - routes![auth::index, auth::get_user, auth::register_user, auth::check_pin, auth::change, auth::get_user_name, auth::get_user_pronouns], + routes![auth::index, auth::get_user, auth::register_user, auth::check_pin, auth::change, auth::get_user_name, auth::get_user_pronouns, chat::send_message], ) .attach(cors_fairing) } diff --git a/src/message.rs b/src/message.rs index 270b9d3..57801e9 100644 --- a/src/message.rs +++ b/src/message.rs @@ -1,11 +1,15 @@ use uuid::Uuid; use chrono::prelude::*; use crate::user::User; +use serde::{Deserialize, Serialize}; -#[derive(Clone)] +#[derive(Deserialize, Serialize)] pub struct Message { + /* pub id: Uuid, pub user: User, pub body: String, - pub created_at: DateTime, + pub created_at: DateTime, */ + id: u8, + body: String, } From 57b97ffe94bc6a78273308396a26d47bee1a3243 Mon Sep 17 00:00:00 2001 From: Erin Nova Date: Sat, 17 Jul 2021 20:22:43 -0400 Subject: [PATCH 02/10] switch to proper rust docs --- Cargo.lock | 18 +++++++++--------- src/chat.rs | 7 ++----- src/message.rs | 11 ++++------- 3 files changed, 15 insertions(+), 21 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f75f5a2..9376268 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -123,9 +123,9 @@ checksum = "b700ce4376041dcd0a327fd0097c41095743c4c8af8887265942faf1100bd040" [[package]] name = "cc" -version = "1.0.68" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a72c244c1ff497a746a7e1fb3d14bd08420ecda70c8f25c7112f2781652d787" +checksum = "e70cc2f62c6ce1868963827bd677764c62d07c3d9a3e1fb1177ee1a9ab199eb2" [[package]] name = "cfg-if" @@ -177,9 +177,9 @@ dependencies = [ [[package]] name = "cookie" -version = "0.15.0" +version = "0.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffdf8865bac3d9a3bde5bde9088ca431b11f5d37c7a578b8086af77248b76627" +checksum = "d5f1c7727e460397e56abc4bddc1d49e07a1ad78fc98eb2e1c8f032a58a2f80d" dependencies = [ "percent-encoding 2.1.0", "time 0.2.27", @@ -656,9 +656,9 @@ dependencies = [ [[package]] name = "instant" -version = "0.1.9" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61124eeebbd69b8190558df225adf7e4caafce0d743919e5d6b19652314ec5ec" +checksum = "bee0328b1209d157ef001c94dd85b4f8f64139adb0eac2659f4b08382b2f474d" dependencies = [ "cfg-if 1.0.0", ] @@ -1345,7 +1345,7 @@ version = "0.5.0-rc.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "23c8b7d512d2fcac2316ebe590cde67573844b99e6cc9ee0f53375fa16e25ebd" dependencies = [ - "cookie 0.15.0", + "cookie 0.15.1", "either", "http", "hyper 0.14.10", @@ -1527,9 +1527,9 @@ dependencies = [ [[package]] name = "spin" -version = "0.9.1" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5fdd7196b4ae35a111c6dc97f9cc152ca3ea8ad744f7cb46a9f27b3ef8f2f54" +checksum = "511254be0c5bcf062b019a6c89c01a664aa359ded62f78aa72c6fc137c0590e5" [[package]] name = "stable-pattern" diff --git a/src/chat.rs b/src/chat.rs index 6c3ed26..11eb351 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -1,13 +1,10 @@ /* Contains Rocket code for chat/message functionality */ extern crate log; -extern crate rocket_contrib; use crate::message::Message; -extern crate serde_derive; -use rocket_contrib::json::{Json, JsonValue}; -use rocket::{data::FromData, response::Responder}; +use rocket::serde::json::{Json, JsonValue}; #[post("/api/message/send", format = "json", data = "")] -pub fn send_message(message: Json) -> JsonValue { +pub fn send_message(message: Json>) -> JsonValue { json!({ "status": "ok", "reason": "bruh" diff --git a/src/message.rs b/src/message.rs index 57801e9..ccb15f0 100644 --- a/src/message.rs +++ b/src/message.rs @@ -1,15 +1,12 @@ use uuid::Uuid; use chrono::prelude::*; use crate::user::User; -use serde::{Deserialize, Serialize}; +use rocket::serde::{Deserialize, Serialize}; #[derive(Deserialize, Serialize)] -pub struct Message { - /* +pub struct Message<'r> { pub id: Uuid, pub user: User, - pub body: String, - pub created_at: DateTime, */ - id: u8, - body: String, + pub body: &'r str, + pub created_at: DateTime, } From d7f07470903907072d9fd2ad903ec53744a18348 Mon Sep 17 00:00:00 2001 From: videogame hacker Date: Sun, 18 Jul 2021 01:32:57 +0100 Subject: [PATCH 03/10] Backport to Rocket v0.4, fix all warnings & errors --- Cargo.lock | 1261 ++++++++---------------------------------------- Cargo.toml | 11 +- src/auth.rs | 16 +- src/chat.rs | 2 +- src/main.rs | 38 +- src/message.rs | 2 +- src/user.rs | 3 +- 7 files changed, 229 insertions(+), 1104 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9376268..7382254 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,60 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "aead" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fc95d1bdb8e6666b2b217308eeeb09f2d6728d104be3e31916cc74d15420331" +dependencies = [ + "generic-array", +] + +[[package]] +name = "aes" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "884391ef1066acaa41e766ba8f596341b96e93ce34f9a43e7d24bf0a0eaf0561" +dependencies = [ + "aes-soft", + "aesni", + "cipher", +] + +[[package]] +name = "aes-gcm" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5278b5fabbb9bd46e24aa69b2fdea62c99088e0a950a9be40e3e0101298f88da" +dependencies = [ + "aead", + "aes", + "cipher", + "ctr", + "ghash", + "subtle", +] + +[[package]] +name = "aes-soft" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be14c7498ea50828a38d0e24a765ed2effe92a705885b57d029cd67d45744072" +dependencies = [ + "cipher", + "opaque-debug", +] + +[[package]] +name = "aesni" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea2e11f5e94c2f7d386164cc2aa1f97823fed6f259e486940a71c174dd01b0ce" +dependencies = [ + "cipher", + "opaque-debug", +] + [[package]] name = "aho-corasick" version = "0.7.18" @@ -11,47 +65,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "async-stream" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "171374e7e3b2504e0e5236e3b59260560f9fe94bfe9ac39ba5e4e929c5590625" -dependencies = [ - "async-stream-impl", - "futures-core", -] - -[[package]] -name = "async-stream-impl" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "648ed8c8d2ce5409ccd57453d9d1b214b342a0d69376a6feda1fd6cae3299308" -dependencies = [ - "proc-macro2 1.0.27", - "quote 1.0.9", - "syn 1.0.73", -] - -[[package]] -name = "async-trait" -version = "0.1.50" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b98e84bbb4cbcdd97da190ba0c58a1bb0de2c1fdf67d159e192ed766aeca722" -dependencies = [ - "proc-macro2 1.0.27", - "quote 1.0.9", - "syn 1.0.73", -] - -[[package]] -name = "atomic" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3410529e8288c463bedb5930f82833bc0c90e5d2fe639a56582a4d09220b281" -dependencies = [ - "autocfg", -] - [[package]] name = "atty" version = "0.2.14" @@ -69,12 +82,6 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" -[[package]] -name = "base-x" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4521f3e3d031370679b3b140beb36dfe4801b09ac77e30c61941f97df3ef28b" - [[package]] name = "base64" version = "0.9.3" @@ -91,12 +98,6 @@ version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" -[[package]] -name = "binascii" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "383d29d513d8764dcdc42ea295d979eb99c3c9f00607b3692cf68a431f7dca72" - [[package]] name = "bitflags" version = "1.2.1" @@ -104,10 +105,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" [[package]] -name = "bumpalo" -version = "3.7.0" +name = "block-buffer" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c59e7af012c713f529e7a3ee57ce9b31ddd858d4b512923602f74608b009631" +checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" +dependencies = [ + "generic-array", +] [[package]] name = "byteorder" @@ -115,18 +119,6 @@ version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" -[[package]] -name = "bytes" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b700ce4376041dcd0a327fd0097c41095743c4c8af8887265942faf1100bd040" - -[[package]] -name = "cc" -version = "1.0.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e70cc2f62c6ce1868963827bd677764c62d07c3d9a3e1fb1177ee1a9ab199eb2" - [[package]] name = "cfg-if" version = "0.1.10" @@ -149,21 +141,18 @@ dependencies = [ "num-integer", "num-traits", "serde", - "time 0.1.43", + "time", "winapi 0.3.9", ] [[package]] -name = "const_fn" -version = "0.4.8" +name = "cipher" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f92cfa0fd5690b3cf8c1ef2cabbd9b7ef22fa53cf5e1f92b05103f6d5d1cf6e7" - -[[package]] -name = "convert_case" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" +checksum = "12f8e7987cbd042a63249497f41aed09f8e65add917ea6566effbc56578d6801" +dependencies = [ + "generic-array", +] [[package]] name = "cookie" @@ -171,32 +160,48 @@ version = "0.11.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "80f6044740a4a516b8aac14c140cdf35c1a640b1bd6b98b6224e49143b2f1566" dependencies = [ + "aes-gcm", + "base64 0.13.0", + "hkdf", + "hmac", "percent-encoding 2.1.0", - "time 0.1.43", + "rand", + "sha2", + "time", ] [[package]] -name = "cookie" -version = "0.15.1" +name = "cpufeatures" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5f1c7727e460397e56abc4bddc1d49e07a1ad78fc98eb2e1c8f032a58a2f80d" +checksum = "66c99696f6c9dd7f35d486b9d04d7e6e202aa3e8c40d553f2fdf5e7e0c6a71ef" dependencies = [ - "percent-encoding 2.1.0", - "time 0.2.27", - "version_check 0.9.3", + "libc", ] [[package]] -name = "derive_more" -version = "0.99.16" +name = "cpuid-bool" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40eebddd2156ce1bb37b20bbe5151340a31828b1f2d22ba4141f3531710e38df" +checksum = "dcb25d077389e53838a8158c8e99174c5a9d902dee4904320db714f3c653ffba" + +[[package]] +name = "crypto-mac" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4857fd85a0c34b3c3297875b747c1e02e06b6a0ea32dd892d8192b9ce0813ea6" dependencies = [ - "convert_case", - "proc-macro2 1.0.27", - "quote 1.0.9", - "rustc_version 0.3.3", - "syn 1.0.73", + "generic-array", + "subtle", +] + +[[package]] +name = "ctr" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb4a30d54f7443bf3d6191dcd486aca19e67cb3c49fa7a06a319966346707e7f" +dependencies = [ + "cipher", ] [[package]] @@ -205,18 +210,8 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "74e04ba2d03c5fa0d954c061fc8c9c288badadffc272ebb87679a89846de3ed3" dependencies = [ - "devise_codegen 0.2.0", - "devise_core 0.2.0", -] - -[[package]] -name = "devise" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "411cf45ac38f00df3679689616649dc12607b846db171780bb790b514a042832" -dependencies = [ - "devise_codegen 0.3.0", - "devise_core 0.3.0", + "devise_codegen", + "devise_core", ] [[package]] @@ -225,20 +220,10 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "066ceb7928ca93a9bedc6d0e612a8a0424048b0ab1f75971b203d01420c055d7" dependencies = [ - "devise_core 0.2.0", + "devise_core", "quote 0.6.13", ] -[[package]] -name = "devise_codegen" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2cf7081f06822f1787e29359354426132cf832cc977d7a8ff747848631462ad1" -dependencies = [ - "devise_core 0.3.0", - "quote 1.0.9", -] - [[package]] name = "devise_core" version = "0.2.0" @@ -252,37 +237,12 @@ dependencies = [ ] [[package]] -name = "devise_core" -version = "0.3.0" +name = "digest" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80c23631758736875d7ce08f847f296b4001b72cf90878e85b47df7ac5442147" +checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" dependencies = [ - "bitflags", - "proc-macro2 1.0.27", - "proc-macro2-diagnostics", - "quote 1.0.9", - "syn 1.0.73", -] - -[[package]] -name = "discard" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0" - -[[package]] -name = "either" -version = "1.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" - -[[package]] -name = "encoding_rs" -version = "0.8.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80df024fbc5ac80f87dfef0d9f5209a252f2a497f7f42944cff24d8253cac065" -dependencies = [ - "cfg-if 1.0.0", + "generic-array", ] [[package]] @@ -298,20 +258,6 @@ dependencies = [ "termcolor", ] -[[package]] -name = "figment" -version = "0.10.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "790b4292c72618abbab50f787a477014fe15634f96291de45672ce46afe122df" -dependencies = [ - "atomic", - "pear 0.2.3", - "serde", - "toml 0.5.8", - "uncased", - "version_check 0.9.3", -] - [[package]] name = "filetime" version = "0.2.14" @@ -324,12 +270,6 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "fnv" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" - [[package]] name = "fsevent" version = "0.4.0" @@ -366,110 +306,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" [[package]] -name = "futures" -version = "0.3.15" +name = "generic-array" +version = "0.14.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e7e43a803dae2fa37c1f6a8fe121e1f7bf9548b4dfc0522a42f34145dadfc27" +checksum = "501466ecc8a30d1d3b7fc9229b122b2ce8ed6e9d9223f1138d4babb253e51817" dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e682a68b29a882df0545c143dc3646daefe80ba479bcdede94d5a703de2871e2" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0402f765d8a89a26043b889b26ce3c4679d268fa6bb22cd7c6aad98340e179d1" - -[[package]] -name = "futures-executor" -version = "0.3.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "badaa6a909fac9e7236d0620a2f57f7664640c56575b71a7552fbd68deafab79" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acc499defb3b348f8d8f3f66415835a9131856ff7714bf10dadfc4ec4bdb29a1" - -[[package]] -name = "futures-macro" -version = "0.3.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4c40298486cdf52cc00cd6d6987892ba502c7656a16a4192a9992b1ccedd121" -dependencies = [ - "autocfg", - "proc-macro-hack", - "proc-macro2 1.0.27", - "quote 1.0.9", - "syn 1.0.73", -] - -[[package]] -name = "futures-sink" -version = "0.3.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a57bead0ceff0d6dde8f465ecd96c9338121bb7717d3e7b108059531870c4282" - -[[package]] -name = "futures-task" -version = "0.3.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a16bef9fc1a4dddb5bee51c989e3fbba26569cbb0e31f5b303c184e3dd33dae" - -[[package]] -name = "futures-util" -version = "0.3.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "feb5c238d27e2bf94ffdfd27b2c29e3df4a68c4193bb6427384259e2bf191967" -dependencies = [ - "autocfg", - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "proc-macro-hack", - "proc-macro-nested", - "slab", -] - -[[package]] -name = "generator" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1d9279ca822891c1a4dae06d185612cf8fc6acfe5dff37781b41297811b12ee" -dependencies = [ - "cc", - "libc", - "log 0.4.14", - "rustversion", - "winapi 0.3.9", + "typenum", + "version_check 0.9.3", ] [[package]] @@ -483,31 +326,22 @@ dependencies = [ "wasi", ] +[[package]] +name = "ghash" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97304e4cd182c3846f7575ced3890c53012ce534ad9114046b0a9e00bb30a375" +dependencies = [ + "opaque-debug", + "polyval", +] + [[package]] name = "glob" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" -[[package]] -name = "h2" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "825343c4eef0b63f541f8903f395dc5beb362a979b5799a84062527ef1e37726" -dependencies = [ - "bytes", - "fnv", - "futures-core", - "futures-sink", - "futures-util", - "http", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", -] - [[package]] name = "hashbrown" version = "0.11.2" @@ -524,25 +358,23 @@ dependencies = [ ] [[package]] -name = "http" -version = "0.2.4" +name = "hkdf" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "527e8c9ac747e28542699a951517aa9a6945af506cd1f2e1b53a576c17b6cc11" +checksum = "51ab2f639c231793c5f6114bdb9bbe50a7dbbfcd7c7c6bd8475dec2d991e964f" dependencies = [ - "bytes", - "fnv", - "itoa", + "digest", + "hmac", ] [[package]] -name = "http-body" -version = "0.4.2" +name = "hmac" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60daa14be0e0786db0f03a9e57cb404c9d756eed2b6c62b9ea98ec5743ec75a9" +checksum = "c1441c6b1e930e2817404b5046f1f989899143a12bf92de603b69f4e0aee1e15" dependencies = [ - "bytes", - "http", - "pin-project-lite", + "crypto-mac", + "digest", ] [[package]] @@ -551,12 +383,6 @@ version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3a87b616e37e93c22fb19bcd386f02f3af5ea98a25670ad0fce773de23c5e68" -[[package]] -name = "httpdate" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6456b8a6c8f33fee7d958fcd1b60d55b11940a79e63ae87013e6d22e26034440" - [[package]] name = "humantime" version = "2.1.0" @@ -573,39 +399,15 @@ dependencies = [ "httparse", "language-tags", "log 0.3.9", - "mime 0.2.6", + "mime", "num_cpus", - "time 0.1.43", + "time", "traitobject", "typeable", "unicase", "url", ] -[[package]] -name = "hyper" -version = "0.14.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7728a72c4c7d72665fde02204bcbd93b247721025b222ef78606f14513e0fd03" -dependencies = [ - "bytes", - "futures-channel", - "futures-core", - "futures-util", - "h2", - "http", - "http-body", - "httparse", - "httpdate", - "itoa", - "pin-project-lite", - "socket2", - "tokio", - "tower-service", - "tracing", - "want", -] - [[package]] name = "idna" version = "0.1.5" @@ -625,15 +427,8 @@ checksum = "bc633605454125dec4b66843673f01c7df2b89479b32e0ed634e43a91cff62a5" dependencies = [ "autocfg", "hashbrown", - "serde", ] -[[package]] -name = "inlinable_string" -version = "0.1.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3094308123a0e9fd59659ce45e22de9f53fc1d2ac6e1feb9fef988e4f76cad77" - [[package]] name = "inotify" version = "0.7.1" @@ -654,15 +449,6 @@ dependencies = [ "libc", ] -[[package]] -name = "instant" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bee0328b1209d157ef001c94dd85b4f8f64139adb0eac2659f4b08382b2f474d" -dependencies = [ - "cfg-if 1.0.0", -] - [[package]] name = "iovec" version = "0.1.4" @@ -694,12 +480,6 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a91d884b6667cd606bb5a69aa0c99ba811a115fc68915e7056ec08a46e93199a" -[[package]] -name = "lazy_static" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" - [[package]] name = "lazycell" version = "1.3.0" @@ -712,15 +492,6 @@ version = "0.2.97" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12b8adadd720df158f4d70dfe7ccc6adb0472d7c55ca83445f6a5ab3e36f8fb6" -[[package]] -name = "lock_api" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0382880606dff6d15c9476c416d18690b72742aa7b605bb6dd6ec9030fbf07eb" -dependencies = [ - "scopeguard", -] - [[package]] name = "log" version = "0.3.9" @@ -739,19 +510,6 @@ dependencies = [ "cfg-if 1.0.0", ] -[[package]] -name = "loom" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2111607c723d7857e0d8299d5ce7a0bf4b844d3e44f8de136b13da513eaf8fc4" -dependencies = [ - "cfg-if 1.0.0", - "generator", - "scoped-tls", - "serde", - "serde_json", -] - [[package]] name = "matches" version = "0.1.8" @@ -773,12 +531,6 @@ dependencies = [ "log 0.3.9", ] -[[package]] -name = "mime" -version = "0.3.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" - [[package]] name = "mio" version = "0.6.23" @@ -792,25 +544,12 @@ dependencies = [ "kernel32-sys", "libc", "log 0.4.14", - "miow 0.2.2", + "miow", "net2", "slab", "winapi 0.2.8", ] -[[package]] -name = "mio" -version = "0.7.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c2bdb6314ec10835cd3293dd268473a835c02b7b352e788be788b3c6ca6bb16" -dependencies = [ - "libc", - "log 0.4.14", - "miow 0.3.7", - "ntapi", - "winapi 0.3.9", -] - [[package]] name = "mio-extras" version = "2.0.6" @@ -819,7 +558,7 @@ checksum = "52403fe290012ce777c4626790c8951324a2b9e3316b3143779c72b029742f19" dependencies = [ "lazycell", "log 0.4.14", - "mio 0.6.23", + "mio", "slab", ] @@ -835,36 +574,6 @@ dependencies = [ "ws2_32-sys", ] -[[package]] -name = "miow" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9f1c5b025cda876f66ef43a113f91ebc9f4ccef34843000e0adf6ebbab84e21" -dependencies = [ - "winapi 0.3.9", -] - -[[package]] -name = "multer" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fdd568fea4758b30d6423f013f7171e193c34aa97828d1bd9f924fb3af30a8c" -dependencies = [ - "bytes", - "derive_more", - "encoding_rs", - "futures-util", - "http", - "httparse", - "log 0.4.14", - "mime 0.3.16", - "spin", - "tokio", - "tokio-util", - "twoway", - "version_check 0.9.3", -] - [[package]] name = "net2" version = "0.2.37" @@ -888,21 +597,12 @@ dependencies = [ "fsevent-sys", "inotify", "libc", - "mio 0.6.23", + "mio", "mio-extras", "walkdir", "winapi 0.3.9", ] -[[package]] -name = "ntapi" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f6bb902e437b6d86e03cce10a7e2af662292c5dfef23b65899ea3ac9354ad44" -dependencies = [ - "winapi 0.3.9", -] - [[package]] name = "num-integer" version = "0.1.44" @@ -933,35 +633,10 @@ dependencies = [ ] [[package]] -name = "once_cell" -version = "1.8.0" +name = "opaque-debug" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56" - -[[package]] -name = "parking_lot" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d7744ac029df22dca6284efe4e898991d28e3085c706c972bcd7da4a27a15eb" -dependencies = [ - "instant", - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa7a782938e745763fe6907fc6ba86946d72f49fe7e21de074e08128a99fb018" -dependencies = [ - "cfg-if 1.0.0", - "instant", - "libc", - "redox_syscall", - "smallvec", - "winapi 0.3.9", -] +checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] name = "pear" @@ -969,18 +644,7 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5320f212db967792b67cfe12bd469d08afd6318a249bd917d5c19bc92200ab8a" dependencies = [ - "pear_codegen 0.1.4", -] - -[[package]] -name = "pear" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15e44241c5e4c868e3eaa78b7c1848cadd6344ed4f54d029832d32b415a58702" -dependencies = [ - "inlinable_string", - "pear_codegen 0.2.3", - "yansi", + "pear_codegen", ] [[package]] @@ -996,18 +660,6 @@ dependencies = [ "yansi", ] -[[package]] -name = "pear_codegen" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82a5ca643c2303ecb740d506539deba189e16f2754040a42901cd8105d0282d0" -dependencies = [ - "proc-macro2 1.0.27", - "proc-macro2-diagnostics", - "quote 1.0.9", - "syn 1.0.73", -] - [[package]] name = "percent-encoding" version = "1.0.1" @@ -1020,27 +672,6 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" -[[package]] -name = "pest" -version = "2.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10f4872ae94d7b90ae48754df22fd42ad52ce740b8f370b03da4835417403e53" -dependencies = [ - "ucd-trie", -] - -[[package]] -name = "pin-project-lite" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d31d11c69a6b52a174b42bdc0c30e5e11670f90788b2c471c31c1d17d449443" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - [[package]] name = "pogchat" version = "0.3.0" @@ -1048,33 +679,31 @@ dependencies = [ "chrono", "env_logger", "log 0.4.14", - "rocket 0.5.0-rc.1", + "rocket", "rocket_contrib", "serde", - "serde_derive", "serde_json", "sha1", "uuid", ] +[[package]] +name = "polyval" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eebcc4aa140b9abd2bc40d9c3f7ccec842679cd79045ac3a7ac698c1a064b7cd" +dependencies = [ + "cpuid-bool", + "opaque-debug", + "universal-hash", +] + [[package]] name = "ppv-lite86" version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" -[[package]] -name = "proc-macro-hack" -version = "0.5.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" - -[[package]] -name = "proc-macro-nested" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc881b2c22681370c6a780e47af9840ef841837bc98118431d4e1868bd0c1086" - [[package]] name = "proc-macro2" version = "0.4.30" @@ -1093,19 +722,6 @@ dependencies = [ "unicode-xid 0.2.2", ] -[[package]] -name = "proc-macro2-diagnostics" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bf29726d67464d49fa6224a1d07936a8c08bb3fba727c7493f6cf1616fdaada" -dependencies = [ - "proc-macro2 1.0.27", - "quote 1.0.9", - "syn 1.0.73", - "version_check 0.9.3", - "yansi", -] - [[package]] name = "quote" version = "0.6.13" @@ -1173,26 +789,6 @@ dependencies = [ "bitflags", ] -[[package]] -name = "ref-cast" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "300f2a835d808734ee295d45007adacb9ebb29dd3ae2424acfa17930cae541da" -dependencies = [ - "ref-cast-impl", -] - -[[package]] -name = "ref-cast-impl" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c38e3aecd2b21cb3959637b883bb3714bc7e43f0268b9a29d3743ee3e55cdd2" -dependencies = [ - "proc-macro2 1.0.27", - "quote 1.0.9", - "syn 1.0.73", -] - [[package]] name = "regex" version = "1.5.4" @@ -1210,15 +806,6 @@ version = "0.6.25" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" -[[package]] -name = "remove_dir_all" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" -dependencies = [ - "winapi 0.3.9", -] - [[package]] name = "rocket" version = "0.4.10" @@ -1230,50 +817,12 @@ dependencies = [ "log 0.4.14", "memchr", "num_cpus", - "pear 0.1.4", - "rocket_codegen 0.4.10", - "rocket_http 0.4.10", - "state 0.4.2", - "time 0.1.43", - "toml 0.4.10", - "version_check 0.9.3", - "yansi", -] - -[[package]] -name = "rocket" -version = "0.5.0-rc.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a71c18c42a0eb15bf3816831caf0dad11e7966f2a41aaf486a701979c4dd1f2" -dependencies = [ - "async-stream", - "async-trait", - "atomic", - "atty", - "binascii", - "bytes", - "either", - "figment", - "futures", - "indexmap", - "log 0.4.14", - "memchr", - "multer", - "num_cpus", - "parking_lot", - "pin-project-lite", - "rand", - "ref-cast", - "rocket_codegen 0.5.0-rc.1", - "rocket_http 0.5.0-rc.1", - "serde", - "state 0.5.2", - "tempfile", - "time 0.2.27", - "tokio", - "tokio-stream", - "tokio-util", - "ubyte", + "pear", + "rocket_codegen", + "rocket_http", + "state", + "time", + "toml", "version_check 0.9.3", "yansi", ] @@ -1284,31 +833,15 @@ version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1729e687d6d2cf434d174da84fb948f7fef4fac22d20ce94ca61c28b72dbcf9f" dependencies = [ - "devise 0.2.0", + "devise", "glob", "indexmap", "quote 0.6.13", - "rocket_http 0.4.10", + "rocket_http", "version_check 0.9.3", "yansi", ] -[[package]] -name = "rocket_codegen" -version = "0.5.0-rc.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66f5fa462f7eb958bba8710c17c5d774bbbd59809fa76fb1957af7e545aea8bb" -dependencies = [ - "devise 0.3.0", - "glob", - "indexmap", - "proc-macro2 1.0.27", - "quote 1.0.9", - "rocket_http 0.5.0-rc.1", - "syn 1.0.73", - "unicode-xid 0.2.2", -] - [[package]] name = "rocket_contrib" version = "0.4.10" @@ -1317,7 +850,7 @@ checksum = "6b6303dccab46dce6c7ac26c9b9d8d8cde1b19614b027c3f913be6611bff6d9b" dependencies = [ "log 0.4.14", "notify", - "rocket 0.4.10", + "rocket", "serde", "serde_json", ] @@ -1328,69 +861,17 @@ version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6131e6e6d38a9817f4a494ff5da95971451c2eb56a53915579fc9c80f6ef0117" dependencies = [ - "cookie 0.11.4", - "hyper 0.10.16", + "cookie", + "hyper", "indexmap", - "pear 0.1.4", + "pear", "percent-encoding 1.0.1", "smallvec", - "state 0.4.2", - "time 0.1.43", + "state", + "time", "unicode-xid 0.1.0", ] -[[package]] -name = "rocket_http" -version = "0.5.0-rc.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23c8b7d512d2fcac2316ebe590cde67573844b99e6cc9ee0f53375fa16e25ebd" -dependencies = [ - "cookie 0.15.1", - "either", - "http", - "hyper 0.14.10", - "indexmap", - "log 0.4.14", - "memchr", - "mime 0.3.16", - "parking_lot", - "pear 0.2.3", - "percent-encoding 2.1.0", - "pin-project-lite", - "ref-cast", - "serde", - "smallvec", - "stable-pattern", - "state 0.5.2", - "time 0.2.27", - "tokio", - "uncased", -] - -[[package]] -name = "rustc_version" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" -dependencies = [ - "semver 0.9.0", -] - -[[package]] -name = "rustc_version" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0dfe2087c51c460008730de8b57e6a320782fbfb312e1f4d520e6c6fae155ee" -dependencies = [ - "semver 0.11.0", -] - -[[package]] -name = "rustversion" -version = "1.0.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61b3909d758bb75c79f23d4736fac9433868679d3ad2ea7a61e3c25cfda9a088" - [[package]] name = "ryu" version = "1.0.5" @@ -1412,51 +893,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "scoped-tls" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea6a9290e3c9cf0f18145ef7ffa62d68ee0bf5fcd651017e586dc7fd5da448c2" - -[[package]] -name = "scopeguard" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" - -[[package]] -name = "semver" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" -dependencies = [ - "semver-parser 0.7.0", -] - -[[package]] -name = "semver" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f301af10236f6df4160f7c3f04eec6dbc70ace82d23326abad5edee88801c6b6" -dependencies = [ - "semver-parser 0.10.2", -] - -[[package]] -name = "semver-parser" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" - -[[package]] -name = "semver-parser" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0bef5b7f9e0df16536d3961cfb6e84331c065b4066afb39768d0e319411f7" -dependencies = [ - "pest", -] - [[package]] name = "serde" version = "1.0.126" @@ -1495,12 +931,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2579985fda508104f7587689507983eadd6a6e84dd35d6d115361f530916fa0d" [[package]] -name = "signal-hook-registry" -version = "1.4.0" +name = "sha2" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e51e73328dc4ac0c7ccbda3a494dfa03df1de2f46018127f60c693f2648455b0" +checksum = "b362ae5752fd2137731f9fa25fd4d9058af34666ca1966fb969119cc35719f12" dependencies = [ - "libc", + "block-buffer", + "cfg-if 1.0.0", + "cpufeatures", + "digest", + "opaque-debug", ] [[package]] @@ -1515,40 +955,6 @@ version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e" -[[package]] -name = "socket2" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e3dfc207c526015c632472a77be09cf1b6e46866581aecae5cc38fb4235dea2" -dependencies = [ - "libc", - "winapi 0.3.9", -] - -[[package]] -name = "spin" -version = "0.9.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "511254be0c5bcf062b019a6c89c01a664aa359ded62f78aa72c6fc137c0590e5" - -[[package]] -name = "stable-pattern" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4564168c00635f88eaed410d5efa8131afa8d8699a612c80c455a0ba05c21045" -dependencies = [ - "memchr", -] - -[[package]] -name = "standback" -version = "0.2.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e113fb6f3de07a243d434a56ec6f186dfd51cb08448239fe7bcae73f87ff28ff" -dependencies = [ - "version_check 0.9.3", -] - [[package]] name = "state" version = "0.4.2" @@ -1556,62 +962,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3015a7d0a5fd5105c91c3710d42f9ccf0abfb287d62206484dcc67f9569a6483" [[package]] -name = "state" -version = "0.5.2" +name = "subtle" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87cf4f5369e6d3044b5e365c9690f451516ac8f0954084622b49ea3fde2f6de5" -dependencies = [ - "loom", -] - -[[package]] -name = "stdweb" -version = "0.4.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d022496b16281348b52d0e30ae99e01a73d737b2f45d38fed4edf79f9325a1d5" -dependencies = [ - "discard", - "rustc_version 0.2.3", - "stdweb-derive", - "stdweb-internal-macros", - "stdweb-internal-runtime", - "wasm-bindgen", -] - -[[package]] -name = "stdweb-derive" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c87a60a40fccc84bef0652345bbbbbe20a605bf5d0ce81719fc476f5c03b50ef" -dependencies = [ - "proc-macro2 1.0.27", - "quote 1.0.9", - "serde", - "serde_derive", - "syn 1.0.73", -] - -[[package]] -name = "stdweb-internal-macros" -version = "0.2.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58fa5ff6ad0d98d1ffa8cb115892b6e69d67799f6763e162a1c9db421dc22e11" -dependencies = [ - "base-x", - "proc-macro2 1.0.27", - "quote 1.0.9", - "serde", - "serde_derive", - "serde_json", - "sha1", - "syn 1.0.73", -] - -[[package]] -name = "stdweb-internal-runtime" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "213701ba3370744dcd1a12960caa4843b3d68b4d1c0a5d575e0d65b2ee9d16c0" +checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" [[package]] name = "syn" @@ -1635,20 +989,6 @@ dependencies = [ "unicode-xid 0.2.2", ] -[[package]] -name = "tempfile" -version = "3.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dac1c663cfc93810f88aed9b8941d48cabf856a1b111c29a40439018d870eb22" -dependencies = [ - "cfg-if 1.0.0", - "libc", - "rand", - "redox_syscall", - "remove_dir_all", - "winapi 0.3.9", -] - [[package]] name = "termcolor" version = "1.1.2" @@ -1668,44 +1008,6 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "time" -version = "0.2.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4752a97f8eebd6854ff91f1c1824cd6160626ac4bd44287f7f4ea2035a02a242" -dependencies = [ - "const_fn", - "libc", - "standback", - "stdweb", - "time-macros", - "version_check 0.9.3", - "winapi 0.3.9", -] - -[[package]] -name = "time-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "957e9c6e26f12cb6d0dd7fc776bb67a706312e7299aed74c8dd5b17ebb27e2f1" -dependencies = [ - "proc-macro-hack", - "time-macros-impl", -] - -[[package]] -name = "time-macros-impl" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd3c141a1b43194f3f56a1411225df8646c55781d5f26db825b3d98507eb482f" -dependencies = [ - "proc-macro-hack", - "proc-macro2 1.0.27", - "quote 1.0.9", - "standback", - "syn 1.0.73", -] - [[package]] name = "tinyvec" version = "1.2.0" @@ -1721,61 +1023,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" -[[package]] -name = "tokio" -version = "1.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98c8b05dc14c75ea83d63dd391100353789f5f24b8b3866542a5e85c8be8e985" -dependencies = [ - "autocfg", - "bytes", - "libc", - "memchr", - "mio 0.7.13", - "num_cpus", - "once_cell", - "pin-project-lite", - "signal-hook-registry", - "tokio-macros", - "winapi 0.3.9", -] - -[[package]] -name = "tokio-macros" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54473be61f4ebe4efd09cec9bd5d16fa51d70ea0192213d754d2d500457db110" -dependencies = [ - "proc-macro2 1.0.27", - "quote 1.0.9", - "syn 1.0.73", -] - -[[package]] -name = "tokio-stream" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b2f3f698253f03119ac0102beaa64f67a67e08074d03a22d18784104543727f" -dependencies = [ - "futures-core", - "pin-project-lite", - "tokio", -] - -[[package]] -name = "tokio-util" -version = "0.6.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1caa0b0c8d94a049db56b5acf8cba99dc0623aab1b26d5b5f5e2d945846b3592" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "log 0.4.14", - "pin-project-lite", - "tokio", -] - [[package]] name = "toml" version = "0.4.10" @@ -1785,63 +1032,12 @@ dependencies = [ "serde", ] -[[package]] -name = "toml" -version = "0.5.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a31142970826733df8241ef35dc040ef98c679ab14d7c3e54d827099b3acecaa" -dependencies = [ - "serde", -] - -[[package]] -name = "tower-service" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6" - -[[package]] -name = "tracing" -version = "0.1.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09adeb8c97449311ccd28a427f96fb563e7fd31aabf994189879d9da2394b89d" -dependencies = [ - "cfg-if 1.0.0", - "pin-project-lite", - "tracing-core", -] - -[[package]] -name = "tracing-core" -version = "0.1.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9ff14f98b1a4b289c6248a023c1c2fa1491062964e9fed67ab29c4e4da4a052" -dependencies = [ - "lazy_static", -] - [[package]] name = "traitobject" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "efd1f82c56340fdf16f2a953d7bda4f8fdffba13d93b00844c25572110b26079" -[[package]] -name = "try-lock" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" - -[[package]] -name = "twoway" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c57ffb460d7c24cd6eda43694110189030a3d1dfe418416d9468fd1c1d290b47" -dependencies = [ - "memchr", - "unchecked-index", -] - [[package]] name = "typeable" version = "0.1.2" @@ -1849,35 +1045,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1410f6f91f21d1612654e7cc69193b0334f909dcf2c790c4826254fbb86f8887" [[package]] -name = "ubyte" -version = "0.10.1" +name = "typenum" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42756bb9e708855de2f8a98195643dff31a97f0485d90d8467b39dc24be9e8fe" -dependencies = [ - "serde", -] - -[[package]] -name = "ucd-trie" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56dee185309b50d1f11bfedef0fe6d036842e3fb77413abef29f8f8d1c5d4c1c" - -[[package]] -name = "uncased" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5baeed7327e25054889b9bd4f975f32e5f4c5d434042d59ab6cd4142c0a76ed0" -dependencies = [ - "serde", - "version_check 0.9.3", -] - -[[package]] -name = "unchecked-index" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eeba86d422ce181a719445e51872fa30f1f7413b62becb52e95ec91aa262d85c" +checksum = "879f6906492a7cd215bfa4cf595b600146ccfac0c79bcbd1f3000162af5e8b06" [[package]] name = "unicase" @@ -1918,6 +1089,16 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" +[[package]] +name = "universal-hash" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8326b2c654932e3e4f9196e69d08fdf7cfd718e1dc6f66b347e6024a0c961402" +dependencies = [ + "generic-array", + "subtle", +] + [[package]] name = "url" version = "1.7.2" @@ -1962,76 +1143,12 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "want" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" -dependencies = [ - "log 0.4.14", - "try-lock", -] - [[package]] name = "wasi" version = "0.10.2+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" -[[package]] -name = "wasm-bindgen" -version = "0.2.74" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d54ee1d4ed486f78874278e63e4069fc1ab9f6a18ca492076ffb90c5eb2997fd" -dependencies = [ - "cfg-if 1.0.0", - "wasm-bindgen-macro", -] - -[[package]] -name = "wasm-bindgen-backend" -version = "0.2.74" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b33f6a0694ccfea53d94db8b2ed1c3a8a4c86dd936b13b9f0a15ec4a451b900" -dependencies = [ - "bumpalo", - "lazy_static", - "log 0.4.14", - "proc-macro2 1.0.27", - "quote 1.0.9", - "syn 1.0.73", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-macro" -version = "0.2.74" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "088169ca61430fe1e58b8096c24975251700e7b1f6fd91cc9d59b04fb9b18bd4" -dependencies = [ - "quote 1.0.9", - "wasm-bindgen-macro-support", -] - -[[package]] -name = "wasm-bindgen-macro-support" -version = "0.2.74" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be2241542ff3d9f241f5e2cb6dd09b37efe786df8851c54957683a49f0987a97" -dependencies = [ - "proc-macro2 1.0.27", - "quote 1.0.9", - "syn 1.0.73", - "wasm-bindgen-backend", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-shared" -version = "0.2.74" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7cff876b8f18eed75a66cf49b65e7f967cb354a7aa16003fb55dbfd25b44b4f" - [[package]] name = "winapi" version = "0.2.8" diff --git a/Cargo.toml b/Cargo.toml index b177fb0..0b8ab7f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,17 +7,12 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -rocket = "0.5.0-rc.1" -serde = "1.0.126" +rocket = "0.4.10" +serde = { version = "1.0.126", features = ["derive"] } serde_json = "1.0" sha1 = "0.6.0" uuid = { version = "0.8.1", features = ["serde", "v4"] } log = "0.4.0" env_logger = "0.8.4" chrono = { version = "0.4.11", features = ["serde"] } -serde_derive = "1.0" - -[dependencies.rocket_contrib] -version = "0.4.10" -default-features = false -features = ["json"] +rocket_contrib = { version = "0.4.10", default-features = false, features = ["json"] } diff --git a/src/auth.rs b/src/auth.rs index 4fc38a7..4d3b80c 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -2,7 +2,7 @@ extern crate log; use crate::user::User; use crate::file_io::{read_json, append_json, write_json}; extern crate sha1; -use serde_json::Result; + #[get("/")] pub fn index() -> &'static str { @@ -23,7 +23,7 @@ pub fn index() -> &'static str { // Post request to register a user and pin #[post("/api/register///")] -pub fn register_user(name: &str, pin: i32, pronouns: &str) -> String { +pub fn register_user(name: String, pin: i32, pronouns: String) -> String { let mut users: Vec = read_json(); // Create an array of users out of parsed json for i in &users { // loop through elements of the vector if i.name == name.to_lowercase() { @@ -38,7 +38,7 @@ pub fn register_user(name: &str, pin: i32, pronouns: &str) -> String { name: name.to_string().to_lowercase(), pin_hashed: pin_hashed, pronouns: pronouns.to_string().to_lowercase(), - sessionToken: "NULL".to_string() + session_token: "NULL".to_string() }); // append the user to the vec // append to the json file @@ -53,7 +53,7 @@ pub fn register_user(name: &str, pin: i32, pronouns: &str) -> String { // Check if pin matches user #[get("/api/users//")] -pub fn check_pin(name: &str, pin: i32) -> String { +pub fn check_pin(name: String, pin: i32) -> String { let users: Vec = read_json(); let hashed_pin_input = sha1::Sha1::from(&pin.to_string()).digest().to_string(); for i in &users { // loop through the vector @@ -73,7 +73,7 @@ pub fn check_pin(name: &str, pin: i32) -> String { // Change a users pin/name #[post("/api/users/change////")] -pub fn change(name: &str, pin: i32, new_name: &str, new_pin: i32) -> String { +pub fn change(name: String, pin: i32, new_name: String, new_pin: i32) -> String { let mut users: Vec = read_json(); let hashed_pin_input = sha1::Sha1::from(&pin.to_string()).digest().to_string(); @@ -121,7 +121,7 @@ pub fn change(name: &str, pin: i32, new_name: &str, new_pin: i32) -> String { } #[get("/api/users/")] -pub fn get_user(name: &str) -> String { +pub fn get_user(name: String) -> String { let users: Vec = read_json(); let found_user = users.iter().filter(|u| u.name == name.to_lowercase()).next(); @@ -133,7 +133,7 @@ pub fn get_user(name: &str) -> String { /* Get data about a user */ #[get("/api/about/name/")] -pub fn get_user_name(name: &str) -> String { +pub fn get_user_name(name: String) -> String { let users: Vec = read_json(); let found_user = users.iter().filter(|u| u.name == name.to_lowercase()).next(); @@ -144,7 +144,7 @@ pub fn get_user_name(name: &str) -> String { } #[get("/api/about/pronouns/")] -pub fn get_user_pronouns(name: &str) -> String { +pub fn get_user_pronouns(name: String) -> String { let users: Vec = read_json(); let found_user = users.iter().filter(|u| u.name == name.to_lowercase()).next(); diff --git a/src/chat.rs b/src/chat.rs index 11eb351..7629ae0 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -1,7 +1,7 @@ /* Contains Rocket code for chat/message functionality */ extern crate log; use crate::message::Message; -use rocket::serde::json::{Json, JsonValue}; +use rocket_contrib::json::{Json, JsonValue}; #[post("/api/message/send", format = "json", data = "")] pub fn send_message(message: Json>) -> JsonValue { diff --git a/src/main.rs b/src/main.rs index 1c124a1..13d0f7f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,30 +1,42 @@ -#[macro_use] extern crate log; -#[macro_use] extern crate rocket; -#[macro_use] extern crate rocket_contrib; +#![feature(proc_macro_hygiene, decl_macro)] + +#[macro_use] +extern crate log; +#[macro_use] +extern crate rocket; +#[macro_use] +extern crate rocket_contrib; use rocket::fairing::AdHoc; mod auth; -mod user; -mod message; -mod file_io; mod chat; +mod file_io; +mod message; +mod user; -#[launch] -fn rocket() -> _ { +fn main() { env_logger::init(); info!("Started up rocket"); let cors_fairing = AdHoc::on_response("CORS", |_, res| { - Box::pin(async move { - res.set_raw_header("Access-Control-Allow-Origin", "*"); - }) + res.set_raw_header("Access-Control-Allow-Origin", "*"); }); info!("Built CORS fairing"); - rocket::build() + rocket::ignite() .mount( "/", - routes![auth::index, auth::get_user, auth::register_user, auth::check_pin, auth::change, auth::get_user_name, auth::get_user_pronouns, chat::send_message], + routes![ + auth::index, + auth::get_user, + auth::register_user, + auth::check_pin, + auth::change, + auth::get_user_name, + auth::get_user_pronouns, + chat::send_message + ], ) .attach(cors_fairing) + .launch(); } diff --git a/src/message.rs b/src/message.rs index ccb15f0..9020842 100644 --- a/src/message.rs +++ b/src/message.rs @@ -1,7 +1,7 @@ use uuid::Uuid; use chrono::prelude::*; use crate::user::User; -use rocket::serde::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; #[derive(Deserialize, Serialize)] pub struct Message<'r> { diff --git a/src/user.rs b/src/user.rs index 81fb782..ad2aff9 100644 --- a/src/user.rs +++ b/src/user.rs @@ -6,5 +6,6 @@ pub struct User { pub name: String, pub pin_hashed: String, pub pronouns: String, - pub sessionToken: String, + #[serde(rename = "sessionToken")] + pub session_token: String, } From 117ee9935e7682067634137a6408700fa4e88c4b Mon Sep 17 00:00:00 2001 From: videogame hacker Date: Sun, 18 Jul 2021 01:33:22 +0100 Subject: [PATCH 04/10] Run 'cargo fmt' --- src/auth.rs | 109 +++++++++++++++++++++++++++++++++++-------------- src/file_io.rs | 27 ++++++------ src/message.rs | 4 +- 3 files changed, 95 insertions(+), 45 deletions(-) diff --git a/src/auth.rs b/src/auth.rs index 4d3b80c..461d2dd 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -1,9 +1,8 @@ extern crate log; +use crate::file_io::{append_json, read_json, write_json}; use crate::user::User; -use crate::file_io::{read_json, append_json, write_json}; extern crate sha1; - #[get("/")] pub fn index() -> &'static str { "API Info: @@ -25,20 +24,21 @@ pub fn index() -> &'static str { #[post("/api/register///")] pub fn register_user(name: String, pin: i32, pronouns: String) -> String { let mut users: Vec = read_json(); // Create an array of users out of parsed json - for i in &users { // loop through elements of the vector + for i in &users { + // loop through elements of the vector if i.name == name.to_lowercase() { warn!("Cannot create user {}! User is already in system.", i.name); return "User already exists!".to_string(); }; - }; + } let pin_hashed = sha1::Sha1::from(&pin.to_string()).digest().to_string(); // hash the pin - users.push( User { + users.push(User { name: name.to_string().to_lowercase(), pin_hashed: pin_hashed, pronouns: pronouns.to_string().to_lowercase(), - session_token: "NULL".to_string() + session_token: "NULL".to_string(), }); // append the user to the vec // append to the json file @@ -47,8 +47,16 @@ pub fn register_user(name: String, pin: i32, pronouns: String) -> String { Ok(()) => info!("Succesfully appended to json"), }; - info!("succesfully created user {} with pin hash {}", users[users.len()-1].name.to_string(), users[users.len()-1].pin_hashed); - return format!("User {} registered with pin hash: {}", users[users.len()-1].name.to_string().to_lowercase(), users[users.len()-1].pin_hashed); + info!( + "succesfully created user {} with pin hash {}", + users[users.len() - 1].name.to_string(), + users[users.len() - 1].pin_hashed + ); + return format!( + "User {} registered with pin hash: {}", + users[users.len() - 1].name.to_string().to_lowercase(), + users[users.len() - 1].pin_hashed + ); } // Check if pin matches user @@ -56,7 +64,8 @@ pub fn register_user(name: String, pin: i32, pronouns: String) -> String { pub fn check_pin(name: String, pin: i32) -> String { let users: Vec = read_json(); let hashed_pin_input = sha1::Sha1::from(&pin.to_string()).digest().to_string(); - for i in &users { // loop through the vector + for i in &users { + // loop through the vector if i.name == name.to_lowercase() { if i.pin_hashed == hashed_pin_input { info!("pin correct for user {}", i.name); @@ -66,8 +75,11 @@ pub fn check_pin(name: String, pin: i32) -> String { return "Incorrect pin".to_string(); }; }; - }; - warn!("cannot check pin for user {} as they do not exist", name.to_string().to_lowercase()); + } + warn!( + "cannot check pin for user {} as they do not exist", + name.to_string().to_lowercase() + ); return format!("User {} does not exist.", name.to_string().to_lowercase()); } @@ -80,35 +92,60 @@ pub fn change(name: String, pin: i32, new_name: String, new_pin: i32) -> String // Loop over elements in vector for i in 0..users.len() { - if users[i].name == name.to_lowercase() { // make sure name exists - if users[i].pin_hashed == hashed_pin_input { // check if pin is correct + if users[i].name == name.to_lowercase() { + // make sure name exists + if users[i].pin_hashed == hashed_pin_input { + // check if pin is correct // Check wether to change name or name+pin if users[i].name == new_name.to_lowercase() { // check if new name already exists - users[i].pin_hashed = sha1::Sha1::from(&new_pin.to_string()).digest().to_string(); - match write_json(&users) { - Err(why) => panic!("Cannot write to json! {}", why), - Ok(()) => info!("succesfully wrote to json file"), - } - info!("Changed pin of {}", name.to_string().to_lowercase()); - return format!("User {}'s new pin hash is {}.", name.to_string().to_lowercase(), users[i].pin_hashed); + users[i].pin_hashed = + sha1::Sha1::from(&new_pin.to_string()).digest().to_string(); + match write_json(&users) { + Err(why) => panic!("Cannot write to json! {}", why), + Ok(()) => info!("succesfully wrote to json file"), + } + info!("Changed pin of {}", name.to_string().to_lowercase()); + return format!( + "User {}'s new pin hash is {}.", + name.to_string().to_lowercase(), + users[i].pin_hashed + ); } else { // check if new name already exists for n in &users { if n.name == new_name.to_lowercase() { - warn!("Could not change name of {} to {}, as new name is already taken.", name.to_lowercase(), new_name.to_lowercase()); - return format!("New name {} is already taken!", new_name.to_lowercase()); + warn!( + "Could not change name of {} to {}, as new name is already taken.", + name.to_lowercase(), + new_name.to_lowercase() + ); + return format!( + "New name {} is already taken!", + new_name.to_lowercase() + ); } } users[i].name = new_name.to_string().to_lowercase(); - users[i].pin_hashed = sha1::Sha1::from(&new_pin.to_string()).digest().to_string(); - + users[i].pin_hashed = + sha1::Sha1::from(&new_pin.to_string()).digest().to_string(); + match write_json(&users) { Err(why) => panic!("couldn't write to json file! {}", why), Ok(()) => info!("succesfully wrote to json file"), } - info!("Changed name of {} to {}. New pin hash is {}", name.to_string(), users[i].name.to_string(), users[i].pin_hashed.to_string()); - return format!("User previously known as {} is now {}. Pin hash, if different, is {}", name.to_string(), users[i].name.to_string(), users[i].pin_hashed.to_string()); + info!( + "Changed name of {} to {}. New pin hash is {}", + name.to_string(), + users[i].name.to_string(), + users[i].pin_hashed.to_string() + ); + return format!( + "User previously known as {} is now {}. Pin hash, if different, is {}", + name.to_string(), + users[i].name.to_string(), + users[i].pin_hashed.to_string() + ); } } else { warn!("Incorrect pin given for user {}!", name.to_string()); @@ -116,14 +153,20 @@ pub fn change(name: String, pin: i32, new_name: String, new_pin: i32) -> String } } } - warn!("User {} not found, could not change pin and/or name.", name.to_string()); + warn!( + "User {} not found, could not change pin and/or name.", + name.to_string() + ); return format!("User {} not found.", name.to_string()); } #[get("/api/users/")] pub fn get_user(name: String) -> String { let users: Vec = read_json(); - let found_user = users.iter().filter(|u| u.name == name.to_lowercase()).next(); + let found_user = users + .iter() + .filter(|u| u.name == name.to_lowercase()) + .next(); match found_user { Some(user) => format!("User {}", &user.name), @@ -135,7 +178,10 @@ pub fn get_user(name: String) -> String { #[get("/api/about/name/")] pub fn get_user_name(name: String) -> String { let users: Vec = read_json(); - let found_user = users.iter().filter(|u| u.name == name.to_lowercase()).next(); + let found_user = users + .iter() + .filter(|u| u.name == name.to_lowercase()) + .next(); match found_user { Some(user) => user.name.to_string(), @@ -146,7 +192,10 @@ pub fn get_user_name(name: String) -> String { #[get("/api/about/pronouns/")] pub fn get_user_pronouns(name: String) -> String { let users: Vec = read_json(); - let found_user = users.iter().filter(|u| u.name == name.to_lowercase()).next(); + let found_user = users + .iter() + .filter(|u| u.name == name.to_lowercase()) + .next(); match found_user { Some(user) => user.pronouns.to_string(), diff --git a/src/file_io.rs b/src/file_io.rs index 0efecdc..94dacca 100644 --- a/src/file_io.rs +++ b/src/file_io.rs @@ -7,7 +7,9 @@ use crate::user::User; use serde_json::Result; fn read_lines

(filename: P) -> io::Result>> -where P: AsRef, { +where + P: AsRef, +{ let file = File::open(filename)?; Ok(io::BufReader::new(file).lines()) } @@ -35,22 +37,23 @@ pub fn read_json() -> Vec { } // Function to append the last value of the users vector to the file -pub fn append_json(users_list: &Vec) -> Result<()> { +pub fn append_json(users_list: &Vec) -> Result<()> { // Create a file to write to let path = Path::new("users.json"); let display = path.display(); let mut file = match OpenOptions::new() - .write(true) - .create(true) - .append(true) - .open(&path){ + .write(true) + .create(true) + .append(true) + .open(&path) + { Err(why) => panic!("couldn't create {}: {}", display, why), Ok(file) => file, }; // Serialize the last user value - let users_json = serde_json::to_string(&users_list[users_list.len()-1])?; + let users_json = serde_json::to_string(&users_list[users_list.len() - 1])?; // Write to the file match file.write_all(users_json.as_bytes()) { @@ -71,19 +74,17 @@ pub fn write_json(users_list: &Vec) -> Result<()> { let path = Path::new("users.json"); let display = path.display(); - let mut file = match OpenOptions::new() - .write(true) - .create(true) - .open(&path){ + let mut file = match OpenOptions::new().write(true).create(true).open(&path) { Err(why) => panic!("couldn't create {}: {}", display, why), Ok(file) => file, }; - + let mut users_json = String::new(); for i in 0..users_list.len() { // Serialize the users users_json += &serde_json::to_string(&users_list[i])?; - if i != users_list.len()-1 { // don't append newline if it's the last element + if i != users_list.len() - 1 { + // don't append newline if it's the last element users_json += "\n"; } } diff --git a/src/message.rs b/src/message.rs index 9020842..45179ac 100644 --- a/src/message.rs +++ b/src/message.rs @@ -1,7 +1,7 @@ -use uuid::Uuid; -use chrono::prelude::*; use crate::user::User; +use chrono::prelude::*; use serde::{Deserialize, Serialize}; +use uuid::Uuid; #[derive(Deserialize, Serialize)] pub struct Message<'r> { From e95022e994a053bbaf7dfb58cd1a1aa81df1a99f Mon Sep 17 00:00:00 2001 From: Erin Nova Date: Sat, 17 Jul 2021 22:27:05 -0400 Subject: [PATCH 05/10] Add more messaging funcionality --- README.md | 12 +++++++++++- src/chat.rs | 33 ++++++++++++++++++++++++++++++--- src/message.rs | 11 +++++++++-- src/user.rs | 2 +- 4 files changed, 51 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 73e5848..90baca3 100644 --- a/README.md +++ b/README.md @@ -27,8 +27,18 @@ Whenever user sends a message, client will send message & token and backend will - [x] Basic auth api - [ ] Basic messaging system + - [ ] Finish up `chat::create_message()` + - [ ] Create `chat::read_messages()` + - [ ] Create `chat::delete_message()` + - [ ] Different types of message events? eg. default, announcement, command + - [ ] Emote support? - [ ] Token generation & storage + - [ ] API to refresh token + - [ ] Store token in json + - [ ] API to check token? - [x] Pronouns -- [ ] Change pronouns + - [ ] Change pronouns + - [ ] Multiple sets of pronouns +- [ ] Some form of plural support? - [ ] User management (banning, etc.) - [ ] Blacklist words from chat/names diff --git a/src/chat.rs b/src/chat.rs index 7629ae0..05d23c7 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -1,12 +1,39 @@ /* Contains Rocket code for chat/message functionality */ extern crate log; -use crate::message::Message; +use crate::file_io::{read_json}; +use crate::message::{Message, MessageInput}; use rocket_contrib::json::{Json, JsonValue}; +use chrono::prelude::*; +use uuid::Uuid; +use crate::user::User; +// Check if user can create the message, and then create more info about the message +fn create_message(message: Json, file: &str, token: &str) { + // check if token is correct for name given + // create full message object + // append message to file + + let date_split: Vec<&str> = message.date.split("-").collect(); + let year: i32 = match date_split[0].trim().parse() { + Err(why) => panic!("could not extract year from given date: {}", why), + Ok(year) => year, + }; + let date: DateTime = Utc.ymd(year, 7, 7).and_hms(9, 10, 11); + let message_obj: Message = Message { + id: Uuid::new_v4(), + user: User { name: message.name.to_string(), pin_hashed: "no".to_string(), pronouns: "she/her".to_string(), session_token: "NULL".to_string() }, + body: message.body.to_string(), + created_at: Utc.ymd(2005, 7, 8).and_hms(9, 10, 11), + }; + println!("{:?}", message_obj); +} + +// Receive a basic message #[post("/api/message/send", format = "json", data = "")] -pub fn send_message(message: Json>) -> JsonValue { +pub fn send_message(message: Json>) -> JsonValue { + create_message(message, "messages.json", "token"); json!({ "status": "ok", - "reason": "bruh" + "reason": "" }) } diff --git a/src/message.rs b/src/message.rs index 45179ac..ae6502e 100644 --- a/src/message.rs +++ b/src/message.rs @@ -4,9 +4,16 @@ use serde::{Deserialize, Serialize}; use uuid::Uuid; #[derive(Deserialize, Serialize)] -pub struct Message<'r> { +pub struct MessageInput<'r> { + pub name: &'r str, + pub body: &'r str, + pub date: &'r str, +} + +#[derive(Debug)] +pub struct Message { pub id: Uuid, pub user: User, - pub body: &'r str, + pub body: String, pub created_at: DateTime, } diff --git a/src/user.rs b/src/user.rs index ad2aff9..915bd4a 100644 --- a/src/user.rs +++ b/src/user.rs @@ -1,7 +1,7 @@ use serde::{Deserialize, Serialize}; // Struct to store basic user data -#[derive(Clone, Serialize, Deserialize)] +#[derive(Clone, Serialize, Deserialize, Debug)] pub struct User { pub name: String, pub pin_hashed: String, From 915ae722d505a50c6b892bf220a4609d4f536c71 Mon Sep 17 00:00:00 2001 From: Erin Nova Date: Sun, 18 Jul 2021 10:16:55 -0400 Subject: [PATCH 06/10] Add info about returning json --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 90baca3..7047b82 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,9 @@ Whenever user sends a message, client will send message & token and backend will ## To-Do: - [x] Basic auth api +- [ ] Return json instead of string + - status is main thing to deal with, ok/fail/panic + - reason is for more details, mainly just for debugging? - [ ] Basic messaging system - [ ] Finish up `chat::create_message()` - [ ] Create `chat::read_messages()` From bedb5ea9743974851dfb2dd91467df5a568f30b2 Mon Sep 17 00:00:00 2001 From: Erin Nova Date: Sun, 18 Jul 2021 10:17:29 -0400 Subject: [PATCH 07/10] Add basic token validation --- src/chat.rs | 35 ++++++++++++++++++++++++++++------- src/message.rs | 1 + 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/chat.rs b/src/chat.rs index 05d23c7..5ee6e48 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -8,8 +8,33 @@ use uuid::Uuid; use crate::user::User; // Check if user can create the message, and then create more info about the message -fn create_message(message: Json, file: &str, token: &str) { +fn create_message(message: Json, file: &str) -> JsonValue { // check if token is correct for name given + let users: Vec = read_json(); // create vector out of users in json file + + for i in &users { + // loop through elements + if i.name == message.name.to_lowercase() { // if it finds the user in the file + if i.session_token == message.token { // if token matches + info!("user exists and given token matches"); + return json!({ + "status": "ok", + "reason": "token matches" + }) + } else { + warn!("token does not match!"); + return json!({ + "status": "fail", + "reason": "token does not match" + }) + }; + }; + }; + json!({ + "status": "fail", + "reason": "user not found" + }) +/* // create full message object // append message to file @@ -25,15 +50,11 @@ fn create_message(message: Json, file: &str, token: &str) { body: message.body.to_string(), created_at: Utc.ymd(2005, 7, 8).and_hms(9, 10, 11), }; - println!("{:?}", message_obj); + println!("{:?}", message_obj);*/ } // Receive a basic message #[post("/api/message/send", format = "json", data = "")] pub fn send_message(message: Json>) -> JsonValue { - create_message(message, "messages.json", "token"); - json!({ - "status": "ok", - "reason": "" - }) + create_message(message, "messages.json") } diff --git a/src/message.rs b/src/message.rs index ae6502e..c6f0d9d 100644 --- a/src/message.rs +++ b/src/message.rs @@ -8,6 +8,7 @@ pub struct MessageInput<'r> { pub name: &'r str, pub body: &'r str, pub date: &'r str, + pub token: &'r str, } #[derive(Debug)] From 0302f816ec61e590e9545116cda7de100269f7c4 Mon Sep 17 00:00:00 2001 From: Erin Nova Date: Sun, 18 Jul 2021 10:34:27 -0400 Subject: [PATCH 08/10] Create full message object out of sent message --- src/chat.rs | 66 ++++++++++++++++++++++++++++++++++------------------- 1 file changed, 42 insertions(+), 24 deletions(-) diff --git a/src/chat.rs b/src/chat.rs index 5ee6e48..835889a 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -1,14 +1,51 @@ /* Contains Rocket code for chat/message functionality */ extern crate log; -use crate::file_io::{read_json}; +use crate::file_io::read_json; use crate::message::{Message, MessageInput}; use rocket_contrib::json::{Json, JsonValue}; use chrono::prelude::*; use uuid::Uuid; use crate::user::User; +// Create full message object and write to file +fn create_message(message: Json, file: &str, user: &User) -> JsonValue { + // create full message object + // append message to file + + // Create proper datetime format out of string + let date_split: Vec<&str> = message.date.split("-").collect(); + + let year: i32 = match date_split[0].trim().parse() { // extract year + Err(why) => panic!("could not extract year from given date: {}", why), + Ok(year) => year, + }; + + let month: u32 = match date_split[1].trim().parse() { // extract month + Err(why) => panic!("could not extract month from given date: {}", why), + Ok(month) => month, + }; + + let day: u32 = match date_split[2].trim().parse() { // extract day + Err(why) => panic!("could not extract day from given date: {}", why), + Ok(month) => month, + }; + + let date: DateTime = Utc.ymd(year, month, day).and_hms(9, 10, 11); + let message_obj: Message = Message { + id: Uuid::new_v4(), + user: user.to_owned(), + body: message.body.to_string(), + created_at: date, + }; + println!("{:?}", message_obj); + return json!({ + "status": "ok", + "reason": "message created", + }); +} + // Check if user can create the message, and then create more info about the message -fn create_message(message: Json, file: &str) -> JsonValue { +fn check_token(message: Json) -> JsonValue { // check if token is correct for name given let users: Vec = read_json(); // create vector out of users in json file @@ -17,10 +54,7 @@ fn create_message(message: Json, file: &str) -> JsonValue { if i.name == message.name.to_lowercase() { // if it finds the user in the file if i.session_token == message.token { // if token matches info!("user exists and given token matches"); - return json!({ - "status": "ok", - "reason": "token matches" - }) + return create_message(message, "messages.json", i); } else { warn!("token does not match!"); return json!({ @@ -30,31 +64,15 @@ fn create_message(message: Json, file: &str) -> JsonValue { }; }; }; + warn!("user not found"); json!({ "status": "fail", "reason": "user not found" }) -/* - // create full message object - // append message to file - - let date_split: Vec<&str> = message.date.split("-").collect(); - let year: i32 = match date_split[0].trim().parse() { - Err(why) => panic!("could not extract year from given date: {}", why), - Ok(year) => year, - }; - let date: DateTime = Utc.ymd(year, 7, 7).and_hms(9, 10, 11); - let message_obj: Message = Message { - id: Uuid::new_v4(), - user: User { name: message.name.to_string(), pin_hashed: "no".to_string(), pronouns: "she/her".to_string(), session_token: "NULL".to_string() }, - body: message.body.to_string(), - created_at: Utc.ymd(2005, 7, 8).and_hms(9, 10, 11), - }; - println!("{:?}", message_obj);*/ } // Receive a basic message #[post("/api/message/send", format = "json", data = "")] pub fn send_message(message: Json>) -> JsonValue { - create_message(message, "messages.json") + check_token(message) } From aef1bbd2a7a41ab3b51b93aa3c9273822f2c5f8d Mon Sep 17 00:00:00 2001 From: Erin Nova Date: Sun, 18 Jul 2021 11:37:11 -0400 Subject: [PATCH 09/10] Add message storage and fetching --- Cargo.lock | 7 +++++++ Cargo.toml | 1 + README.md | 4 ++-- message.zsh | 1 + src/chat.rs | 17 ++++++++++++++++- src/main.rs | 3 ++- src/message.rs | 2 +- 7 files changed, 30 insertions(+), 5 deletions(-) create mode 100755 message.zsh diff --git a/Cargo.lock b/Cargo.lock index 7382254..16038bc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -632,6 +632,12 @@ dependencies = [ "libc", ] +[[package]] +name = "once_cell" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56" + [[package]] name = "opaque-debug" version = "0.3.0" @@ -679,6 +685,7 @@ dependencies = [ "chrono", "env_logger", "log 0.4.14", + "once_cell", "rocket", "rocket_contrib", "serde", diff --git a/Cargo.toml b/Cargo.toml index 0b8ab7f..ae04496 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,3 +16,4 @@ log = "0.4.0" env_logger = "0.8.4" chrono = { version = "0.4.11", features = ["serde"] } rocket_contrib = { version = "0.4.10", default-features = false, features = ["json"] } +once_cell = "1.8.0" diff --git a/README.md b/README.md index 7047b82..c9890d2 100644 --- a/README.md +++ b/README.md @@ -30,8 +30,8 @@ Whenever user sends a message, client will send message & token and backend will - status is main thing to deal with, ok/fail/panic - reason is for more details, mainly just for debugging? - [ ] Basic messaging system - - [ ] Finish up `chat::create_message()` - - [ ] Create `chat::read_messages()` + - [x] Finish up `chat::create_message()` + - [x] Create `chat::fetch_messages()` - [ ] Create `chat::delete_message()` - [ ] Different types of message events? eg. default, announcement, command - [ ] Emote support? diff --git a/message.zsh b/message.zsh new file mode 100755 index 0000000..f80ed8b --- /dev/null +++ b/message.zsh @@ -0,0 +1 @@ +http POST 'http://localhost:8000/api/message/send' name=Sarah body="meow" date=2021-07-01 token=NULL diff --git a/src/chat.rs b/src/chat.rs index 835889a..c96c33c 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -1,5 +1,7 @@ /* Contains Rocket code for chat/message functionality */ extern crate log; +use once_cell::sync::Lazy; +use std::sync::Mutex; use crate::file_io::read_json; use crate::message::{Message, MessageInput}; use rocket_contrib::json::{Json, JsonValue}; @@ -7,6 +9,17 @@ use chrono::prelude::*; use uuid::Uuid; use crate::user::User; +static MESSAGES: Lazy>> = Lazy::new(|| Mutex::new(Vec::new())); + +#[get("/api/message/messages.json")] +pub fn fetch_messages() -> Json> { + let messages = { + let messages = MESSAGES.lock().unwrap(); + messages.to_vec() + }; + Json(messages) +} + // Create full message object and write to file fn create_message(message: Json, file: &str, user: &User) -> JsonValue { // create full message object @@ -37,7 +50,9 @@ fn create_message(message: Json, file: &str, user: &User) -> JsonV body: message.body.to_string(), created_at: date, }; - println!("{:?}", message_obj); + info!("created mesage: {:?}", message_obj); + let mut messages = MESSAGES.lock().unwrap(); + messages.push(message_obj.to_owned()); return json!({ "status": "ok", "reason": "message created", diff --git a/src/main.rs b/src/main.rs index 13d0f7f..23a6d43 100644 --- a/src/main.rs +++ b/src/main.rs @@ -34,7 +34,8 @@ fn main() { auth::change, auth::get_user_name, auth::get_user_pronouns, - chat::send_message + chat::send_message, + chat::fetch_messages ], ) .attach(cors_fairing) diff --git a/src/message.rs b/src/message.rs index c6f0d9d..f85a865 100644 --- a/src/message.rs +++ b/src/message.rs @@ -11,7 +11,7 @@ pub struct MessageInput<'r> { pub token: &'r str, } -#[derive(Debug)] +#[derive(Debug, Deserialize, Serialize, Clone)] pub struct Message { pub id: Uuid, pub user: User, From 376fe024ca90bb534eb3931e52601344af9a2971 Mon Sep 17 00:00:00 2001 From: Erin Nova Date: Sun, 18 Jul 2021 12:06:05 -0400 Subject: [PATCH 10/10] Switch to returning json for all http requests --- README.md | 41 ++++++++++++++---- src/auth.rs | 120 +++++++++++++++++++++++++--------------------------- src/main.rs | 2 - 3 files changed, 90 insertions(+), 73 deletions(-) diff --git a/README.md b/README.md index c9890d2..ef84d26 100644 --- a/README.md +++ b/README.md @@ -6,16 +6,39 @@ Send it the unhashed username and pin, and it'll store it in the `users.json` fi ## API Documentation `POST /api/register///` Register the username with the pin provided if it doesn't already exist +Returns status & reason json. `GET /api/users/` Check if the user exists +Returns either + +`{ + "status": "fail", + "reason": "user not found", +}` + +or + +`{ + "status": "ok", + "user": { + "name": "", + "pronouns": "", + }, +}` `GET /api/users//` Check if the user exists, and if the pin provided matches +Returns status & reason json. `POST /api/users/change////` Change a users pin/name +Returns status & reason json. -`GET /api/about/name/` Get's the name of a user, probably just for checking if they exist -`GET /api/about/pronouns/` Get's the pronouns of a user +## Chat Documentation + +`POST /api/message/send {"name":"username","body":"message body","date":"yyy-mm-dd","token":"USER_TOKEN"}` Post a json message. +Returns status & reason json. + +`GET /api/message/messages.json` Get a json file of all the messages ## Chat Planning @@ -25,23 +48,25 @@ Whenever user sends a message, client will send message & token and backend will ## To-Do: -- [x] Basic auth api +- [x] Basic auth API - [ ] Return json instead of string - - status is main thing to deal with, ok/fail/panic - - reason is for more details, mainly just for debugging? -- [ ] Basic messaging system + - "status" shows wether request was succesful or not, either "ok" or "fail" + - "reason" is for more details, mainly just for debugging? +- [x] Basic messaging system - [x] Finish up `chat::create_message()` - [x] Create `chat::fetch_messages()` - [ ] Create `chat::delete_message()` - - [ ] Different types of message events? eg. default, announcement, command - - [ ] Emote support? - [ ] Token generation & storage - [ ] API to refresh token - [ ] Store token in json - [ ] API to check token? - [x] Pronouns + - [x] Set pronouns - [ ] Change pronouns - [ ] Multiple sets of pronouns - [ ] Some form of plural support? - [ ] User management (banning, etc.) - [ ] Blacklist words from chat/names +- [ ] More advanced chat features + - [ ] Different types of message events? eg. default, announcement, command + - [ ] Emote support? diff --git a/src/auth.rs b/src/auth.rs index 461d2dd..898d0d5 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -1,6 +1,7 @@ extern crate log; use crate::file_io::{append_json, read_json, write_json}; use crate::user::User; +use rocket_contrib::json::{Json, JsonValue}; extern crate sha1; #[get("/")] @@ -22,13 +23,16 @@ pub fn index() -> &'static str { // Post request to register a user and pin #[post("/api/register///")] -pub fn register_user(name: String, pin: i32, pronouns: String) -> String { +pub fn register_user(name: String, pin: i32, pronouns: String) -> JsonValue { let mut users: Vec = read_json(); // Create an array of users out of parsed json for i in &users { // loop through elements of the vector if i.name == name.to_lowercase() { warn!("Cannot create user {}! User is already in system.", i.name); - return "User already exists!".to_string(); + return json!({ + "status": "fail", + "reason": "user already exists", + }); }; } @@ -52,16 +56,15 @@ pub fn register_user(name: String, pin: i32, pronouns: String) -> String { users[users.len() - 1].name.to_string(), users[users.len() - 1].pin_hashed ); - return format!( - "User {} registered with pin hash: {}", - users[users.len() - 1].name.to_string().to_lowercase(), - users[users.len() - 1].pin_hashed - ); + return json!({ + "status": "ok", + "reason": format!("user {} registered", users[users.len()-1].name.to_string().to_lowercase()), + }); } // Check if pin matches user #[get("/api/users//")] -pub fn check_pin(name: String, pin: i32) -> String { +pub fn check_pin(name: String, pin: i32) -> JsonValue { let users: Vec = read_json(); let hashed_pin_input = sha1::Sha1::from(&pin.to_string()).digest().to_string(); for i in &users { @@ -69,10 +72,16 @@ pub fn check_pin(name: String, pin: i32) -> String { if i.name == name.to_lowercase() { if i.pin_hashed == hashed_pin_input { info!("pin correct for user {}", i.name); - return "pin matches".to_string(); + return json!({ + "status": "ok", + "reason": "pin matches", + }); } else { warn!("pin incorrect for user {}", i.name); - return "Incorrect pin".to_string(); + return json!({ + "status": "fail", + "reason": "incorrect pin", + }); }; }; } @@ -80,12 +89,15 @@ pub fn check_pin(name: String, pin: i32) -> String { "cannot check pin for user {} as they do not exist", name.to_string().to_lowercase() ); - return format!("User {} does not exist.", name.to_string().to_lowercase()); + return json!({ + "status": "fail", + "reason": format!("user {} doesn't exist", name.to_string().to_lowercase()), + }); } // Change a users pin/name #[post("/api/users/change////")] -pub fn change(name: String, pin: i32, new_name: String, new_pin: i32) -> String { +pub fn change(name: String, pin: i32, new_name: String, new_pin: i32) -> JsonValue { let mut users: Vec = read_json(); let hashed_pin_input = sha1::Sha1::from(&pin.to_string()).digest().to_string(); @@ -99,18 +111,16 @@ pub fn change(name: String, pin: i32, new_name: String, new_pin: i32) -> String // Check wether to change name or name+pin if users[i].name == new_name.to_lowercase() { // check if new name already exists - users[i].pin_hashed = - sha1::Sha1::from(&new_pin.to_string()).digest().to_string(); + users[i].pin_hashed = sha1::Sha1::from(&new_pin.to_string()).digest().to_string(); match write_json(&users) { Err(why) => panic!("Cannot write to json! {}", why), Ok(()) => info!("succesfully wrote to json file"), } info!("Changed pin of {}", name.to_string().to_lowercase()); - return format!( - "User {}'s new pin hash is {}.", - name.to_string().to_lowercase(), - users[i].pin_hashed - ); + return json!({ + "status": "ok", + "reason": format!("changed {}'s pin", name.to_string().to_lowercase()), + }); } else { // check if new name already exists for n in &users { @@ -120,10 +130,10 @@ pub fn change(name: String, pin: i32, new_name: String, new_pin: i32) -> String name.to_lowercase(), new_name.to_lowercase() ); - return format!( - "New name {} is already taken!", - new_name.to_lowercase() - ); + return json!({ + "status": "fail", + "reason": format!("new name {} is already taken", new_name.to_lowercase()), + }); } } users[i].name = new_name.to_string().to_lowercase(); @@ -140,16 +150,17 @@ pub fn change(name: String, pin: i32, new_name: String, new_pin: i32) -> String users[i].name.to_string(), users[i].pin_hashed.to_string() ); - return format!( - "User previously known as {} is now {}. Pin hash, if different, is {}", - name.to_string(), - users[i].name.to_string(), - users[i].pin_hashed.to_string() - ); + return json!({ + "status": "ok", + "reason": "successfully changed name and/or pin", + }); } } else { warn!("Incorrect pin given for user {}!", name.to_string()); - return format!("Incorrect pin for user {}!", name.to_string()); + return json!({ + "status": "fail", + "reason": "incorrect pin for user", + }); } } } @@ -157,11 +168,14 @@ pub fn change(name: String, pin: i32, new_name: String, new_pin: i32) -> String "User {} not found, could not change pin and/or name.", name.to_string() ); - return format!("User {} not found.", name.to_string()); + return json!({ + "status": "fail", + "reason": format!("user {} not found", name.to_string().to_lowercase()), + }); } #[get("/api/users/")] -pub fn get_user(name: String) -> String { +pub fn get_user(name: String) -> JsonValue { let users: Vec = read_json(); let found_user = users .iter() @@ -169,36 +183,16 @@ pub fn get_user(name: String) -> String { .next(); match found_user { - Some(user) => format!("User {}", &user.name), - None => "User does not exist".to_string(), - } -} - -/* Get data about a user */ -#[get("/api/about/name/")] -pub fn get_user_name(name: String) -> String { - let users: Vec = read_json(); - let found_user = users - .iter() - .filter(|u| u.name == name.to_lowercase()) - .next(); - - match found_user { - Some(user) => user.name.to_string(), - None => "NULL".to_string(), - } -} - -#[get("/api/about/pronouns/")] -pub fn get_user_pronouns(name: String) -> String { - let users: Vec = read_json(); - let found_user = users - .iter() - .filter(|u| u.name == name.to_lowercase()) - .next(); - - match found_user { - Some(user) => user.pronouns.to_string(), - None => "NULL".to_string(), + Some(user) => json!({ + "status":"ok", + "user": { + "name": user.name, + "pronouns": user.pronouns, + }, + }), + None => json!({ + "status": "fail", + "reason": format!("user {} not found", name), + }), } } diff --git a/src/main.rs b/src/main.rs index 23a6d43..3814f0e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -32,8 +32,6 @@ fn main() { auth::register_user, auth::check_pin, auth::change, - auth::get_user_name, - auth::get_user_pronouns, chat::send_message, chat::fetch_messages ],