Make email_signups::create return ErrorPage on error

This commit is contained in:
Kitaiti Makoto 2022-01-12 09:20:20 +09:00
parent 9bbfc71fc8
commit 43b46a8be4

View File

@ -70,7 +70,7 @@ pub fn create(
conn: DbConn, conn: DbConn,
rockets: PlumeRocket, rockets: PlumeRocket,
_enabled: signups::Email, _enabled: signups::Email,
) -> Result<RespondOrRedirect, Ructe> { ) -> Result<RespondOrRedirect, ErrorPage> {
let registration_open = Instance::get_local() let registration_open = Instance::get_local()
.map(|i| i.open_registrations) .map(|i| i.open_registrations)
.unwrap_or(true); .unwrap_or(true);
@ -87,14 +87,15 @@ pub fn create(
} }
let mut form = form.into_inner(); let mut form = form.into_inner();
form.email = form.email.trim().to_owned(); form.email = form.email.trim().to_owned();
form.validate().map_err(|err| { if let Err(err) = form.validate() {
render!(email_signups::new( return Ok(render!(email_signups::new(
&(&conn, &rockets).to_context(), &(&conn, &rockets).to_context(),
registration_open, registration_open,
&form, &form,
err err
)) ))
})?; .into());
}
let res = EmailSignup::start(&conn, &form.email); let res = EmailSignup::start(&conn, &form.email);
if let Some(err) = res.as_ref().err() { if let Some(err) = res.as_ref().err() {
return Ok(match err { return Ok(match err {