#[post("/verify/sendMail", format = "application/json", data = "<email>")]pub fn send_mail(email: Json<Email>) -> Json<Response<String>> { println!("Email: {}", email.email); // Check if email is already in use let user = true; // Database check would go here if user { return Json(Response { data: "ERR_USER_EXISTS".to_string(), status: 400, message: "E-Mail Adresse wird bereits verwendet, möchtest du stattdessen deinen Account wechseln?".to_string(), }); } let email_regex = regex::Regex::new(r"^[a-zA-Z0-9_.+-][email protected]$").unwrap(); // Check if the email is valid if !email_regex.is_match(&email.email) { return Json(Response { data: "FAILTHIS".to_string(), status: 400, message: "Ungültige E-Mail Adresse".to_string(), }); } Json(Response { data: "SUCCESS".to_string(), status: 200, message: "E-Mail wurde erfolgreich versendet".to_string(), })}
The current implementation has a placeholder for database checks. In production, this should query the database:
// Pseudocode for production implementationlet user = sqlx::query_as::<sqlx::Postgres, VerifiedUsers>( "SELECT * FROM verified_users WHERE user_email = $1").bind(&email.email).fetch_optional(pool).await.map_err(Error::Database)?;