diff --git a/src/pages/auth/register.rs b/src/pages/auth/register.rs index 5c51f23..03fa49e 100644 --- a/src/pages/auth/register.rs +++ b/src/pages/auth/register.rs @@ -71,10 +71,15 @@ pub fn services(cfg: &mut web::ServiceConfig) { #[my_codegen::post(path = "PAGES.auth.register")] pub async fn register_submit( - payload: web::Form, + mut payload: web::Form, data: AppData, db: crate::DB, ) -> PageResult { + if let Some(email) = &payload.email { + if email.is_empty() { + payload.email = None; + } + } data.register(&(**db), &payload) .await .map_err(|e| PageError::new(Register::new(&data.settings, Some(&payload)), e))?; diff --git a/src/pages/auth/test.rs b/src/pages/auth/test.rs index a78daac..71e6b58 100644 --- a/src/pages/auth/test.rs +++ b/src/pages/auth/test.rs @@ -67,6 +67,23 @@ async fn auth_works(data: Arc, db: BoxDB) { assert_eq!(headers.get(header::LOCATION).unwrap(), PAGES.auth.login); let _ = data.delete_user(&db, NAME, PASSWORD).await; + // 1. Register with email == "" // Form request handler converts empty emails to None + let msg = Register { + username: NAME.into(), + password: PASSWORD.into(), + confirm_password: PASSWORD.into(), + email: Some("".into()), + }; + let resp = test::call_service( + &app, + post_request!(&msg, PAGES.auth.register, FORM).to_request(), + ) + .await; + assert_eq!(resp.status(), StatusCode::FOUND); + let headers = resp.headers(); + assert_eq!(headers.get(header::LOCATION).unwrap(), PAGES.auth.login); + let _ = data.delete_user(&db, NAME, PASSWORD).await; + // 1. Register with email let msg = Register { username: NAME.into(),