diff --git a/Cargo.lock b/Cargo.lock index 76ca06a..8b994ff 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -32,12 +32,6 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "autocfg" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d49d90015b3c36167a20fe2810c5cd875ad504b39cff3d4eae7977e6b7c1cb2" - [[package]] name = "autocfg" version = "1.0.1" @@ -119,16 +113,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "771fe0050b883fcc3ea2359b1a96bcfbc090b7116eae7c3c512c7a083fdf23d3" -[[package]] -name = "buf_redux" -version = "0.8.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b953a6887648bb07a535631f2bc00fbdb2a2216f135552cb3f534ed136b9c07f" -dependencies = [ - "memchr", - "safemem", -] - [[package]] name = "byte-tools" version = "0.3.1" @@ -174,15 +158,6 @@ dependencies = [ "vec_map", ] -[[package]] -name = "cloudabi" -version = "0.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" -dependencies = [ - "bitflags", -] - [[package]] name = "const_fn" version = "0.4.3" @@ -230,7 +205,7 @@ version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "02d96d1e189ef58269ebe5b97953da3274d83a93af647c2ddd6f9dab28cedb8d" dependencies = [ - "autocfg 1.0.1", + "autocfg", "cfg-if 1.0.0", "lazy_static", ] @@ -311,12 +286,6 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "fuchsia-cprng" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" - [[package]] name = "fuchsia-zircon" version = "0.3.3" @@ -380,9 +349,6 @@ name = "futures-task" version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7c554eb5bf48b2426c4771ab68c6b14468b6e76cc90996f528c3338d761a4d0d" -dependencies = [ - "once_cell", -] [[package]] name = "futures-util" @@ -395,7 +361,6 @@ dependencies = [ "futures-task", "pin-project 1.0.2", "pin-utils", - "slab", ] [[package]] @@ -447,7 +412,7 @@ dependencies = [ "handlebars", "hex", "http", - "rand 0.7.3", + "rand", "serde", "serde_json", "sha2", @@ -487,7 +452,7 @@ dependencies = [ "log", "pest", "pest_derive", - "quick-error 2.0.0", + "quick-error", "serde", "serde_json", ] @@ -510,7 +475,7 @@ dependencies = [ "headers-core", "http", "mime", - "sha-1 0.8.2", + "sha-1", "time", ] @@ -621,19 +586,10 @@ version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "55e2e4c765aa53a0424761bf9f41aa7a6ac1efa87238f59560640e27fca028f2" dependencies = [ - "autocfg 1.0.1", + "autocfg", "hashbrown", ] -[[package]] -name = "input_buffer" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19a8a95243d5a0398cae618ec29477c6e3cb631152be5c19481f80bc71559754" -dependencies = [ - "bytes", -] - [[package]] name = "instant" version = "0.1.9" @@ -722,7 +678,7 @@ version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "157b4208e3059a8f9e78d559edc658e13df41410cb3ae03979c83130067fdd87" dependencies = [ - "autocfg 1.0.1", + "autocfg", ] [[package]] @@ -772,24 +728,6 @@ dependencies = [ "ws2_32-sys", ] -[[package]] -name = "multipart" -version = "0.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8209c33c951f07387a8497841122fc6f712165e3f9bda3e6be4645b58188f676" -dependencies = [ - "buf_redux", - "httparse", - "log", - "mime", - "mime_guess", - "quick-error 1.2.3", - "rand 0.6.5", - "safemem", - "tempfile", - "twoway", -] - [[package]] name = "net2" version = "0.2.36" @@ -811,12 +749,6 @@ dependencies = [ "libc", ] -[[package]] -name = "once_cell" -version = "1.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13bd41f508810a131401606d54ac32a467c97172d74ba7662562ebba5ad07fa0" - [[package]] name = "opaque-debug" version = "0.2.3" @@ -900,7 +832,7 @@ checksum = "54be6e404f5317079812fc8f9f5279de376d8856929e21c184ecf6bbd692a11d" dependencies = [ "maplit", "pest", - "sha-1 0.8.2", + "sha-1", ] [[package]] @@ -1000,12 +932,6 @@ dependencies = [ "unicode-xid", ] -[[package]] -name = "quick-error" -version = "1.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" - [[package]] name = "quick-error" version = "2.0.0" @@ -1021,25 +947,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "rand" -version = "0.6.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca" -dependencies = [ - "autocfg 0.1.7", - "libc", - "rand_chacha 0.1.1", - "rand_core 0.4.2", - "rand_hc 0.1.0", - "rand_isaac", - "rand_jitter", - "rand_os", - "rand_pcg", - "rand_xorshift", - "winapi 0.3.9", -] - [[package]] name = "rand" version = "0.7.3" @@ -1048,19 +955,9 @@ checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" dependencies = [ "getrandom", "libc", - "rand_chacha 0.2.2", - "rand_core 0.5.1", - "rand_hc 0.2.0", -] - -[[package]] -name = "rand_chacha" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef" -dependencies = [ - "autocfg 0.1.7", - "rand_core 0.3.1", + "rand_chacha", + "rand_core", + "rand_hc", ] [[package]] @@ -1070,24 +967,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" dependencies = [ "ppv-lite86", - "rand_core 0.5.1", + "rand_core", ] -[[package]] -name = "rand_core" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" -dependencies = [ - "rand_core 0.4.2", -] - -[[package]] -name = "rand_core" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" - [[package]] name = "rand_core" version = "0.5.1" @@ -1097,84 +979,13 @@ dependencies = [ "getrandom", ] -[[package]] -name = "rand_hc" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4" -dependencies = [ - "rand_core 0.3.1", -] - [[package]] name = "rand_hc" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" dependencies = [ - "rand_core 0.5.1", -] - -[[package]] -name = "rand_isaac" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08" -dependencies = [ - "rand_core 0.3.1", -] - -[[package]] -name = "rand_jitter" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1166d5c91dc97b88d1decc3285bb0a99ed84b05cfd0bc2341bdf2d43fc41e39b" -dependencies = [ - "libc", - "rand_core 0.4.2", - "winapi 0.3.9", -] - -[[package]] -name = "rand_os" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071" -dependencies = [ - "cloudabi", - "fuchsia-cprng", - "libc", - "rand_core 0.4.2", - "rdrand", - "winapi 0.3.9", -] - -[[package]] -name = "rand_pcg" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44" -dependencies = [ - "autocfg 0.1.7", - "rand_core 0.4.2", -] - -[[package]] -name = "rand_xorshift" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c" -dependencies = [ - "rand_core 0.3.1", -] - -[[package]] -name = "rdrand" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" -dependencies = [ - "rand_core 0.3.1", + "rand_core", ] [[package]] @@ -1194,15 +1005,6 @@ dependencies = [ "rust-argon2", ] -[[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 = "rust-argon2" version = "0.8.3" @@ -1221,12 +1023,6 @@ 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 = "scoped-tls" version = "1.0.0" @@ -1294,19 +1090,6 @@ dependencies = [ "opaque-debug 0.2.3", ] -[[package]] -name = "sha-1" -version = "0.9.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce3cdf1b5e620a498ee6f2a171885ac7e22f0e12089ec4b3d22b84921792507c" -dependencies = [ - "block-buffer 0.9.0", - "cfg-if 1.0.0", - "cpuid-bool", - "digest 0.9.0", - "opaque-debug 0.3.0", -] - [[package]] name = "sha2" version = "0.9.2" @@ -1401,20 +1184,6 @@ dependencies = [ "unicode-xid", ] -[[package]] -name = "tempfile" -version = "3.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9" -dependencies = [ - "cfg-if 0.1.10", - "libc", - "rand 0.7.3", - "redox_syscall", - "remove_dir_all", - "winapi 0.3.9", -] - [[package]] name = "textwrap" version = "0.11.0" @@ -1480,19 +1249,6 @@ dependencies = [ "syn", ] -[[package]] -name = "tokio-tungstenite" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d9e878ad426ca286e4dcae09cbd4e1973a7f8987d97570e2469703dd7f5720c" -dependencies = [ - "futures-util", - "log", - "pin-project 0.4.27", - "tokio", - "tungstenite", -] - [[package]] name = "tokio-util" version = "0.3.1" @@ -1550,34 +1306,6 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" -[[package]] -name = "tungstenite" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0308d80d86700c5878b9ef6321f020f29b1bb9d5ff3cab25e75e23f3a492a23" -dependencies = [ - "base64 0.12.3", - "byteorder", - "bytes", - "http", - "httparse", - "input_buffer", - "log", - "rand 0.7.3", - "sha-1 0.9.2", - "url", - "utf-8", -] - -[[package]] -name = "twoway" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59b11b2b5241ba34be09c3cc85a36e56e48f9888862e19cedf23336d35316ed1" -dependencies = [ - "memchr", -] - [[package]] name = "typenum" version = "1.12.0" @@ -1653,12 +1381,6 @@ version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c9232eb53352b4442e40d7900465dfc534e8cb2dc8f18656fcb2ac16112b5593" -[[package]] -name = "utf-8" -version = "0.7.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05e42f7c18b8f902290b009cde6d651262f956c98bc51bca4cd1d511c9cd85c7" - [[package]] name = "vec_map" version = "0.8.2" @@ -1695,14 +1417,12 @@ dependencies = [ "log", "mime", "mime_guess", - "multipart", "pin-project 0.4.27", "scoped-tls", "serde", "serde_json", "serde_urlencoded", "tokio", - "tokio-tungstenite", "tower-service", "tracing", "tracing-futures", diff --git a/Cargo.toml b/Cargo.toml index eeb16b2..99fc94d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,4 +19,4 @@ sled = "0.34.6" structopt = "0.3.21" tokio = { version = "0.2.22", features = ["macros", "rt-threaded"] } urlencoding = "1.1.1" -warp = "0.2.5" +warp = { version = "0.2.5", default-features = false } diff --git a/src/server.rs b/src/server.rs index 21425f3..e530f2a 100644 --- a/src/server.rs +++ b/src/server.rs @@ -63,7 +63,7 @@ pub async fn start_server( let handle_index = { let cache_ads = cache_ads.clone(); let templates = templates.clone(); - move |errors: &[ErrorTemplate]| { + move |errors: &[ErrorTemplate], new_ad_form_refill| { warp::reply::html( templates .hb @@ -73,6 +73,7 @@ pub async fn start_server( lang: "fr", errors, ads: &*cache_ads.read().unwrap(), + new_ad_form_refill, }, ) .unwrap_or_else(|e| e.to_string()), @@ -127,14 +128,11 @@ pub async fn start_server( let cache_ads = cache_ads.clone(); move |query: NewAdQuery| { let mut hasher = Sha512Trunc256::new(); - hasher.update(query.psw); + hasher.update(&query.psw); dbs.ads .insert( AdId::random(), bincode::serialize(&Ad { - author: query.author, - password: hasher.finalize()[..].try_into().unwrap(), - price: query.price, pubkey: if query.pubkey.is_empty() { None } else { @@ -143,9 +141,12 @@ pub async fn start_server( Err(e) => return handle_index(&[ErrorTemplate{text: match e { PubkeyDecodeError::BadChecksum => "La somme de contrôle de la clé publique est incorrecte.", PubkeyDecodeError::BadFormat => "Le format de la clé publique est incorrect.", - }}]) + }}], Some(query)) }) }, + author: query.author, + password: hasher.finalize()[..].try_into().unwrap(), + price: query.price, quantity: query.quantity, time: 0, title: query.title, @@ -215,9 +216,12 @@ pub async fn start_server( .collect::>(), ); } else { - return handle_index(&[ErrorTemplate { - text: "Le mot de passe de l'annonce est incorrect.", - }]); + return handle_index( + &[ErrorTemplate { + text: "Le mot de passe de l'annonce est incorrect.", + }], + None, + ); } } } @@ -253,7 +257,7 @@ pub async fn start_server( } }; - let route_index = warp::path::end().and(warp::get().map(move || handle_index(&[])).or( + let route_index = warp::path::end().and(warp::get().map(move || handle_index(&[], None)).or( warp::post().and( warp::body::form::().map(move |query: Query| match query { Query::NewAdQuery(query) => handle_new_ad(query), @@ -345,6 +349,7 @@ struct IndexTemplate<'a> { lang: &'a str, errors: &'a [ErrorTemplate<'a>], ads: &'a Json, + new_ad_form_refill: Option, } #[derive(Serialize)] @@ -365,7 +370,7 @@ struct ErrorTemplate<'a> { text: &'a str, } -#[derive(Clone, Debug, Deserialize)] +#[derive(Clone, Debug, Deserialize, Serialize)] struct NewAdQuery { author: String, price: String, diff --git a/templates/index.html b/templates/index.html index 71b21a6..b8ea0a0 100644 --- a/templates/index.html +++ b/templates/index.html @@ -45,13 +45,12 @@
- - +
Supprimer l'annonce sélectionnée
- +

@@ -63,17 +62,17 @@
Nouvelle annonce -
+
-
+
-
+
-
+
-
+
-
+
Le mot de passe sera demandé pour modifier ou supprimer l'annonce.