diff --git a/src/api/newsletter.rs b/src/api/newsletter.rs index 4ca906fe..43d5bb83 100644 --- a/src/api/newsletter.rs +++ b/src/api/newsletter.rs @@ -6,6 +6,7 @@ use actix_web::{ use basket::{Basket, SubscribeOpts, YesNo}; use diesel::PgConnection; use serde::{Deserialize, Serialize}; +use validator::Validate; use crate::{ api::error::ApiError, @@ -31,8 +32,9 @@ struct Subscribed { pub subscribed: bool, } -#[derive(Deserialize, Serialize)] +#[derive(Deserialize, Serialize, Validate)] pub struct SubscriptionRequest { + #[validate(email(message = "must be an email address"))] pub email: String, } @@ -53,6 +55,7 @@ pub async fn subscribe_anonymous_handler( basket: Data>, subscription_req: web::Json, ) -> Result { + subscription_req.validate()?; if let Some(basket) = &**basket { basket .subscribe(