updating mission trip and health forms
This commit is contained in:
parent
710ebb6031
commit
29bb3cb04e
4 changed files with 114 additions and 13 deletions
|
@ -364,6 +364,14 @@ pub async fn health_form(MultipartForm(mut form): MultipartForm<HealthForm>) ->
|
|||
Err(e) => error!("There was an error sending email: {e}"),
|
||||
}
|
||||
|
||||
let map = HashMap::from(&form);
|
||||
actix_rt::spawn(store_form(map).map(|r| match r {
|
||||
Ok(_) => {
|
||||
info!("Successfully stored health form in nextcloud!")
|
||||
}
|
||||
Err(e) => error!("There was an error storing form in nextcloud: {e}"),
|
||||
}));
|
||||
|
||||
let full_name = format!("{} {}", form.first_name.0, form.last_name.0);
|
||||
match form.registration.0.as_str() {
|
||||
"now" => {
|
||||
|
@ -372,7 +380,7 @@ pub async fn health_form(MultipartForm(mut form): MultipartForm<HealthForm>) ->
|
|||
.insert_header(("Access-Control-Expose-Headers", "*"))
|
||||
.insert_header((
|
||||
"HX-Redirect",
|
||||
"https://secure.myvanco.com/L-Z772/campaign/C-13JPJ",
|
||||
"https://secure.myvanco.com/L-Z772/campaign/C-13DM3",
|
||||
))
|
||||
.finish()
|
||||
}
|
||||
|
@ -393,10 +401,9 @@ pub async fn health_form(MultipartForm(mut form): MultipartForm<HealthForm>) ->
|
|||
h2 {
|
||||
"Thank you, " (full_name) "!"
|
||||
}
|
||||
p { "Can't wait to see you at camp!" }
|
||||
p {
|
||||
class { "" }
|
||||
"If you'd like to pay for your registration go to the donate tab in the top right when you are ready and find the camp registration option."
|
||||
"If you'd like to pay for your registration go to the donate tab in the top right when you are ready and find the right registration option."
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -423,3 +430,27 @@ pub async fn health_form(MultipartForm(mut form): MultipartForm<HealthForm>) ->
|
|||
}
|
||||
// HttpResponse::Ok().body("hi")
|
||||
}
|
||||
|
||||
async fn store_form(map: HashMap<i32, String>) -> Result<()> {
|
||||
let client = Client::new();
|
||||
let mut json = HashMap::new();
|
||||
json.insert("data", map);
|
||||
|
||||
let res = client
|
||||
.post("https://staff.tfcconnection.org/ocs/v2.php/apps/tables/api/2/tables/4/rows")
|
||||
.basic_auth("chris", Some("2VHeGxeC^Zf9KqFK^G@Pt!zu2q^6@b"))
|
||||
.header("OCS-APIRequest", "true")
|
||||
.header("Content-Type", "application/json")
|
||||
.json(&json)
|
||||
.send()
|
||||
.await?;
|
||||
if res.status().is_success() {
|
||||
let res = res.text().await.unwrap();
|
||||
Ok(())
|
||||
} else {
|
||||
Err(eyre!(
|
||||
"Problem in storing data: {:?}",
|
||||
res.error_for_status()
|
||||
))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -68,6 +68,8 @@ struct MtForm {
|
|||
#[multipart(rename = "final-agreement")]
|
||||
final_agreement: Text<String>,
|
||||
registration: Text<String>,
|
||||
#[multipart(rename = "health-form")]
|
||||
health_form: Text<String>,
|
||||
#[multipart(rename = "image")]
|
||||
file: Option<TempFile>,
|
||||
}
|
||||
|
@ -364,7 +366,7 @@ impl MtForm {
|
|||
.unwrap(),
|
||||
)
|
||||
.to("Chris Cochrun <chris@tfcconnection.org>".parse().unwrap())
|
||||
.to("Ethan Rose <ethan@tfcconnection.org>".parse().unwrap())
|
||||
// .to("Ethan Rose <ethan@tfcconnection.org>".parse().unwrap())
|
||||
.subject(email_subject)
|
||||
.multipart(multi)
|
||||
.wrap_err("problemss")
|
||||
|
@ -391,7 +393,58 @@ pub async fn mt_form(MultipartForm(form): MultipartForm<MtForm>) -> HttpResponse
|
|||
}
|
||||
Err(e) => error!("error sending email {e}"),
|
||||
};
|
||||
HttpResponse::Ok().body(format!("Thank you {}, you can ", name))
|
||||
match form.registration.0.as_str() {
|
||||
"now" => {
|
||||
if form.health_form.0.as_str() == "yes" {
|
||||
HttpResponse::Ok()
|
||||
.insert_header(("Access-Control-Expose-Headers", "*"))
|
||||
.insert_header(("HX-Redirect", "/health-form?registration=now"))
|
||||
.finish()
|
||||
} else {
|
||||
HttpResponse::Ok()
|
||||
.insert_header(("Access-Control-Expose-Headers", "*"))
|
||||
.insert_header((
|
||||
"HX-Redirect",
|
||||
"https://secure.myvanco.com/L-Z772/campaign/C-13DM3",
|
||||
))
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
"later" => {
|
||||
if form.health_form.0.as_str() == "yes" {
|
||||
HttpResponse::Ok()
|
||||
.insert_header(("Access-Control-Expose-Headers", "*"))
|
||||
.insert_header(("HX-Redirect", "/health-form?registration=later"))
|
||||
.finish()
|
||||
} else {
|
||||
HttpResponse::Ok().body(
|
||||
html! {
|
||||
h2 { "Thank you! {}" (name)}
|
||||
p { "You can go to the health form "
|
||||
a href="/health-form" { "here" }
|
||||
" or you can pay for mission trip "
|
||||
a href="https://secure.myvanco.com/L-Z772/campaign/C-13DM3" { "here" }
|
||||
}
|
||||
}
|
||||
.into_string(),
|
||||
)
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
error!("There wasn't an option for the registration passed in.");
|
||||
HttpResponse::Ok().body(
|
||||
html! {
|
||||
h2 { "Thank you! {}" (name)}
|
||||
p { "You can go to the health form "
|
||||
a href="/health-form" { "here" }
|
||||
" or you can pay for mission trip "
|
||||
a href="https://secure.myvanco.com/L-Z772/campaign/C-13DM3" { "here" }
|
||||
}
|
||||
}
|
||||
.into_string(),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn store_form(map: HashMap<i32, String>) -> Result<()> {
|
||||
|
@ -465,6 +518,7 @@ mod test {
|
|||
relevant_notes: Text(String::from("Willing to take the ring")),
|
||||
final_agreement: Text(String::from("yes")),
|
||||
registration: Text(String::from("later")),
|
||||
health_form: Text(String::from("yes")),
|
||||
file: None,
|
||||
}
|
||||
}
|
||||
|
@ -484,7 +538,7 @@ mod test {
|
|||
async fn test_email() {
|
||||
let mut form = form();
|
||||
assert!(!form.first_name.is_empty());
|
||||
match form.send_email().await {
|
||||
match form.send_email() {
|
||||
Ok(_) => assert!(true, "passed emailing test"),
|
||||
Err(e) => assert!(false, "Failed emailing test: {e}"),
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue