Adjust routes
This commit is contained in:
parent
f3f5ce5145
commit
57471181f3
2 changed files with 15 additions and 21 deletions
|
@ -1,5 +1,6 @@
|
||||||
mod captcha_solutions;
|
mod captcha_solutions;
|
||||||
mod config;
|
mod config;
|
||||||
|
mod context;
|
||||||
mod forms;
|
mod forms;
|
||||||
mod mailer;
|
mod mailer;
|
||||||
mod routes;
|
mod routes;
|
||||||
|
|
|
@ -2,28 +2,18 @@ use rocket::form::{Form, Strict};
|
||||||
use rocket::response::status::BadRequest;
|
use rocket::response::status::BadRequest;
|
||||||
use rocket::response::Redirect;
|
use rocket::response::Redirect;
|
||||||
use rocket::{get, post, uri, State};
|
use rocket::{get, post, uri, State};
|
||||||
use rocket_dyn_templates::Template;
|
use rocket_dyn_templates::{context, Template};
|
||||||
use serde::Serialize;
|
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
|
||||||
use crate::captcha_solutions;
|
use crate::captcha_solutions;
|
||||||
use crate::config;
|
use crate::config;
|
||||||
|
use crate::context;
|
||||||
use crate::forms;
|
use crate::forms;
|
||||||
use crate::mailer;
|
use crate::mailer;
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[get("/?<was_validated>&<name>&<email>&<telefon>&<message>")]
|
||||||
struct FormContext<'a> {
|
|
||||||
path_prefix: &'a str,
|
|
||||||
id: u16,
|
|
||||||
name: Option<&'a str>,
|
|
||||||
email: Option<&'a str>,
|
|
||||||
telefon: Option<&'a str>,
|
|
||||||
message: Option<&'a str>,
|
|
||||||
captcha: &'a str,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[get("/?<name>&<email>&<telefon>&<message>")]
|
|
||||||
pub fn index(
|
pub fn index(
|
||||||
|
was_validated: Option<bool>,
|
||||||
name: Option<&str>,
|
name: Option<&str>,
|
||||||
email: Option<&str>,
|
email: Option<&str>,
|
||||||
telefon: Option<&str>,
|
telefon: Option<&str>,
|
||||||
|
@ -39,17 +29,18 @@ pub fn index(
|
||||||
|
|
||||||
let id = captcha_solutions.store_solution(&captcha.chars_as_string());
|
let id = captcha_solutions.store_solution(&captcha.chars_as_string());
|
||||||
|
|
||||||
let form_context = FormContext {
|
let form_context = context::FormContext::new(
|
||||||
path_prefix: &config.path_prefix,
|
&config.path_prefix,
|
||||||
|
was_validated,
|
||||||
id,
|
id,
|
||||||
name,
|
name,
|
||||||
email,
|
email,
|
||||||
telefon,
|
telefon,
|
||||||
message,
|
message,
|
||||||
captcha: &captcha_base64,
|
&captcha_base64,
|
||||||
};
|
);
|
||||||
|
|
||||||
Ok(Template::render("form", &form_context))
|
Ok(Template::render("form", form_context))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[post("/submit", data = "<form>")]
|
#[post("/submit", data = "<form>")]
|
||||||
|
@ -70,6 +61,7 @@ pub fn submit(
|
||||||
return Redirect::to(
|
return Redirect::to(
|
||||||
path_prefix
|
path_prefix
|
||||||
+ &uri!(index(
|
+ &uri!(index(
|
||||||
|
Some(true),
|
||||||
Some(&name),
|
Some(&name),
|
||||||
Some(&email),
|
Some(&email),
|
||||||
Some(&telefon),
|
Some(&telefon),
|
||||||
|
@ -85,6 +77,7 @@ pub fn submit(
|
||||||
return Redirect::to(
|
return Redirect::to(
|
||||||
path_prefix
|
path_prefix
|
||||||
+ &uri!(index(
|
+ &uri!(index(
|
||||||
|
Some(true),
|
||||||
Some(&name),
|
Some(&name),
|
||||||
Some(&email),
|
Some(&email),
|
||||||
Some(&telefon),
|
Some(&telefon),
|
||||||
|
@ -99,6 +92,6 @@ pub fn submit(
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/success")]
|
#[get("/success")]
|
||||||
pub fn success() -> &'static str {
|
pub fn success() -> Template {
|
||||||
"Ihre Anfrage wurde übermittelt! Wir melden uns bald bei Ihnen zurück."
|
Template::render("success", context! {})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue