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