From fc79a7fa530acb9974eeaa92b068a1d95e46d205 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Th=C3=A9riault?= Date: Wed, 15 Jan 2020 15:58:14 -0500 Subject: [PATCH] Fixed random id generation --- src/routes.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/routes.rs b/src/routes.rs index c8e397f..6acf90b 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -186,12 +186,13 @@ macro_rules! delete { /// Verify if an entry exists macro_rules! random_id { ($m:ident) => { - use rand::Rng; + use rand::distributions::Distribution; pub async fn random_id(pool: &actix_web::web::Data) -> Result { let mut rng = rand::thread_rng(); + let distribution = rand::distributions::Uniform::from(0..i32::max_value()); loop { - let id = rng.gen(); + let id = distribution.sample(&mut rng); let pool = pool.clone(); match actix_web::web::block(move || crate::queries::$m::find(id, pool)).await { Ok(_) => continue, @@ -646,7 +647,7 @@ pub mod texts { /// Request body when PUTting texts #[derive(Deserialize)] - pub struct PutText { + pub struct PutPostText { pub contents: String, pub highlight: bool, } @@ -655,7 +656,7 @@ pub mod texts { pub async fn put( request: HttpRequest, path: web::Path, - body: web::Json, + body: web::Json, pool: web::Data, identity: Identity, password_hash: web::Data>, @@ -672,7 +673,7 @@ pub mod texts { /// PUT a new text entry pub async fn post( request: HttpRequest, - body: web::Json, + body: web::Json, pool: web::Data, identity: Identity, password_hash: web::Data>,