From bce6a85536a765ec7558d8e2d5b545f3764c9e12 Mon Sep 17 00:00:00 2001 From: Pierre Hubert Date: Thu, 25 May 2023 09:22:49 +0200 Subject: [PATCH] Check email --- geneit_backend/Cargo.lock | 26 +++++++++++++++++++ geneit_backend/Cargo.toml | 3 ++- .../src/controllers/auth_controller.rs | 5 +++- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/geneit_backend/Cargo.lock b/geneit_backend/Cargo.lock index f04cac2..e216052 100644 --- a/geneit_backend/Cargo.lock +++ b/geneit_backend/Cargo.lock @@ -302,6 +302,12 @@ version = "1.0.71" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c7d0618f0e0b7e8ff11427422b64564d5fb0be1940354bfe2e0529b18a9d9b8" +[[package]] +name = "ascii_utils" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71938f30533e4d95a6d17aa530939da3842c2ab6f4f84b9dae68447e4129f74a" + [[package]] name = "autocfg" version = "1.1.0" @@ -570,6 +576,15 @@ dependencies = [ "libc", ] +[[package]] +name = "fast_chemail" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "495a39d30d624c2caabe6312bfead73e7717692b44e0b32df168c275a2e8e9e4" +dependencies = [ + "ascii_utils", +] + [[package]] name = "flate2" version = "1.0.26" @@ -650,6 +665,7 @@ dependencies = [ "env_logger", "lazy_static", "log", + "mailchecker", "serde", ] @@ -868,6 +884,16 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "mailchecker" +version = "5.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c64fa7af9860896bdfe496f323ac278f256006fd248dd7730e37c5faa648b05" +dependencies = [ + "fast_chemail", + "once_cell", +] + [[package]] name = "memchr" version = "2.5.0" diff --git a/geneit_backend/Cargo.toml b/geneit_backend/Cargo.toml index 3ca33cd..3411579 100644 --- a/geneit_backend/Cargo.toml +++ b/geneit_backend/Cargo.toml @@ -14,4 +14,5 @@ anyhow = "1.0.71" actix-web = "4.3.1" diesel = { version = "2.0.4", features = ["postgres"] } serde = { version = "1.0.163", features = ["derive"] } -actix-remote-ip = "0.1.0" \ No newline at end of file +actix-remote-ip = "0.1.0" +mailchecker = "5.0.9" \ No newline at end of file diff --git a/geneit_backend/src/controllers/auth_controller.rs b/geneit_backend/src/controllers/auth_controller.rs index 51f4d7a..be86373 100644 --- a/geneit_backend/src/controllers/auth_controller.rs +++ b/geneit_backend/src/controllers/auth_controller.rs @@ -17,7 +17,10 @@ pub async fn create_account( ) -> actix_web::Result { // TODO : rate limiting - // TODO : check if email is valid + // Check if email is valid + if !mailchecker::is_valid(&req.email) { + return Ok(HttpResponse::BadRequest().json("Email address is invalid!")); + } // Check parameters let constraints = StaticConstraints::default();