feat(api): added email regex validation on registration
This commit is contained in:
parent
040d338ae0
commit
eadfdca689
|
@ -1610,6 +1610,7 @@ dependencies = [
|
||||||
"log",
|
"log",
|
||||||
"mail-send",
|
"mail-send",
|
||||||
"pbkdf2 0.12.2",
|
"pbkdf2 0.12.2",
|
||||||
|
"regex",
|
||||||
"serde",
|
"serde",
|
||||||
"sha2",
|
"sha2",
|
||||||
"sqlx",
|
"sqlx",
|
||||||
|
|
|
@ -21,3 +21,4 @@ sqlx = { version = "0.7.1", features = ["runtime-tokio", "mysql", "chrono"] }
|
||||||
uuid = { version = "1.4.1", features = ["v4"] }
|
uuid = { version = "1.4.1", features = ["v4"] }
|
||||||
chrono = "0.4"
|
chrono = "0.4"
|
||||||
mail-send = "0.4.0"
|
mail-send = "0.4.0"
|
||||||
|
regex = "1.9.3"
|
|
@ -5,7 +5,7 @@ use crate::{
|
||||||
};
|
};
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use log::info;
|
use log::info;
|
||||||
use mail_send::{mail_builder::MessageBuilder, SmtpClient, SmtpClientBuilder};
|
use mail_send::{mail_builder::MessageBuilder, SmtpClientBuilder};
|
||||||
use sqlx::MySqlPool;
|
use sqlx::MySqlPool;
|
||||||
|
|
||||||
fn is_sql_injection(string: &String) -> bool {
|
fn is_sql_injection(string: &String) -> bool {
|
||||||
|
@ -33,6 +33,12 @@ pub async fn register(
|
||||||
return Ok(data::RegisterResponse::Blocked);
|
return Ok(data::RegisterResponse::Blocked);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let email_regex = regex::Regex::new(r"^([a-z0-9_+]([a-z0-9_+.]*[a-z0-9_+])?)@([a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,6})")?;
|
||||||
|
|
||||||
|
if !email_regex.is_match(&request.email) {
|
||||||
|
return Ok(data::RegisterResponse::MalformedEmail);
|
||||||
|
}
|
||||||
|
|
||||||
if Account::from_username(pool, &request.username)
|
if Account::from_username(pool, &request.username)
|
||||||
.await?
|
.await?
|
||||||
.is_some()
|
.is_some()
|
||||||
|
|
Loading…
Reference in New Issue