From 9e5acd6aa5ec98c5b6c3a7f44e8a2572ae61bd04 Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Wed, 10 Jan 2024 10:25:22 -0600 Subject: [PATCH] adding the local trip form --- content/local-trip-form.md | 16 ++ content/mt-form.md | 2 +- layouts/shortcodes/local-trip-form.html | 241 +++++++++++++++++ src/api/local_trip_form.rs | 335 ++++++++++++++++++++++++ src/api/mod.rs | 1 + src/main.rs | 2 + 6 files changed, 596 insertions(+), 1 deletion(-) create mode 100644 content/local-trip-form.md create mode 100644 layouts/shortcodes/local-trip-form.html create mode 100644 src/api/local_trip_form.rs diff --git a/content/local-trip-form.md b/content/local-trip-form.md new file mode 100644 index 0000000..6eb9199 --- /dev/null +++ b/content/local-trip-form.md @@ -0,0 +1,16 @@ +--- +title: Local Mission Trip Form +layout: simple +sharingLinks: false +--- + +If you'd like to still do a mission trip of some kind, but the other dates do not work for you or you do not feel ready for a longer trip, then this is the trip for you! Sign up here now! + +## Mission Trip Agreement +> In order to fill out the application, you must agree to the following! + +- I agree to obey all rules and guidelines that TFC Connection and other associated ministries establish, realizing they have my best interest and welfare in mind. I will trust their judgment and obey them. **The staff have the right to confront me if they see a problem in my attitude or in my obeying the rules.** +- I acknowledge that I am expected to do my share of the work on the mission trip and I will be willing to do what is asked of me with an "I'd be glad to" attitude. +- **I will work at making this mission trip a priority!** even if other events come up after I am accepted on a mission trip, I will commit to still go on this trip. + +{{< local-trip-form >}} diff --git a/content/mt-form.md b/content/mt-form.md index 2c77a05..e30dd6a 100644 --- a/content/mt-form.md +++ b/content/mt-form.md @@ -41,7 +41,7 @@ It’s easy to forget just how big Mexico is, and how far our location is from t ## 1-2 Day Local Trip - TBD Formerly known as the SPLASH trip, this trip will be within 2 hours of the TFC office in Phillipsburg, KS and will be a 2 day trip where you can get a taste for a longer mission trip. If you don’t feel ready to go on a longer trip, or have scheduling conflicts with the other trips, this is the trip for you! You will still have the opportunity to serve and grow in your faith in Jesus. Click the button below to sign up for this trip! -{{< button href="/mash-form">}} +{{< button href="/local-trip-form">}} Local Trip {{< /button >}} diff --git a/layouts/shortcodes/local-trip-form.html b/layouts/shortcodes/local-trip-form.html new file mode 100644 index 0000000..4ac3608 --- /dev/null +++ b/layouts/shortcodes/local-trip-form.html @@ -0,0 +1,241 @@ +{{ $formClasses := "bg-neutral-500 text-neutral-50 placeholder-neutral-300 focus:ring-2 focus:ring-primary-500 focus:ring-offset-2 focus:ring-offset-transparent m-2 p-3 rounded-lg hover:bg-neutral-500 checked:text-neutral-500" }} +{{ $requiredField := "* required" }} + + + +
+
+ + +
+
+ + +
+
+ +
+
+

Mission Trip Application

+
+ +
+ + +
+
+ + + +
+
+
+ + +
+
+ + +
+
+
+ + + + + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ + + + +
+ +
+ + +
+ + +
+ + +
+ + +
+ + +
+
+ + + + +
+
+ + + +
+ + +
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+
+ +
+
+
diff --git a/src/api/local_trip_form.rs b/src/api/local_trip_form.rs new file mode 100644 index 0000000..c24524f --- /dev/null +++ b/src/api/local_trip_form.rs @@ -0,0 +1,335 @@ +use actix_multipart::form::{text::Text, MultipartForm}; +use actix_web::{post, HttpResponse}; +use lettre::{ + message::MultiPart, + transport::smtp::authentication::{Credentials, Mechanism}, + Message, SmtpTransport, Transport, +}; + +#[derive(Debug, MultipartForm, Default)] +struct LocalForm { + #[multipart(rename = "firstname")] + first_name: Option>, + #[multipart(rename = "lastname")] + last_name: Option>, + #[multipart(rename = "parentfirstname")] + parent_first_name: Option>, + #[multipart(rename = "parentlastname")] + parent_last_name: Option>, + birthdate: Option>, + gender: Option>, + street: Option>, + city: Option>, + state: Option>, + zip: Option>, + cellphone: Option>, + parentphone: Option>, + email: Option>, + parentemail: Option>, + school: Option>, + grade: Option>, + #[multipart(rename = "pastorfirstname")] + pastor_first_name: Option>, + #[multipart(rename = "pastorlastname")] + pastor_last_name: Option>, + #[multipart(rename = "churchattendance")] + church_attendance: Option>, + #[multipart(rename = "tfcgroup")] + tfc_group: Option>, + shirt: Option>, +} + +#[post("/local-trip-form")] +pub async fn local_form(MultipartForm(form): MultipartForm) -> HttpResponse { + let first = form + .first_name + .as_ref() + .unwrap_or(&Text { + 0: String::from(""), + }) + .0 + .clone(); + let last = form + .last_name + .as_ref() + .unwrap_or(&Text { + 0: String::from(""), + }) + .0 + .clone(); + let email_subject = format!("{} {} signed up for the local mission trip!", first, last); + let parent = format!( + "{} {}", + form.parent_first_name + .as_ref() + .unwrap_or(&Text { + 0: String::from("") + }) + .0 + .clone(), + form.parent_last_name + .as_ref() + .unwrap_or(&Text { + 0: String::from("") + }) + .0 + .clone() + ); + let birthdate = form + .birthdate + .as_ref() + .unwrap_or(&Text { + 0: String::from(""), + }) + .0 + .clone(); + let gender = form + .gender + .as_ref() + .unwrap_or(&Text { + 0: String::from(""), + }) + .0 + .clone(); + let street = form + .street + .as_ref() + .unwrap_or(&Text { + 0: String::from(""), + }) + .0 + .clone(); + let city = form + .city + .as_ref() + .unwrap_or(&Text { + 0: String::from(""), + }) + .0 + .clone(); + let state = form + .state + .as_ref() + .unwrap_or(&Text { + 0: String::from(""), + }) + .0 + .clone(); + let zip = form.zip.as_ref().unwrap_or(&Text { 0: 0 }).0.clone(); + let cellphone = form + .cellphone + .as_ref() + .unwrap_or(&Text { + 0: String::from(""), + }) + .0 + .clone(); + let parentphone = form + .parentphone + .as_ref() + .unwrap_or(&Text { + 0: String::from(""), + }) + .0 + .clone(); + let email = form + .email + .as_ref() + .unwrap_or(&Text { + 0: String::from(""), + }) + .0 + .clone(); + let parentemail = form + .parentemail + .as_ref() + .unwrap_or(&Text { + 0: String::from(""), + }) + .0 + .clone(); + let school = form + .school + .as_ref() + .unwrap_or(&Text { + 0: String::from(""), + }) + .0 + .clone(); + let grade = form + .grade + .as_ref() + .unwrap_or(&Text { + 0: String::from(""), + }) + .0 + .clone(); + let pastor = format!( + "{} {}", + form.pastor_first_name + .as_ref() + .unwrap_or(&Text { + 0: String::from(""), + }) + .0 + .clone(), + form.pastor_last_name + .as_ref() + .unwrap_or(&Text { + 0: String::from("") + }) + .0 + .clone() + ); + let church_attendance = form + .church_attendance + .as_ref() + .unwrap_or(&Text { + 0: String::from(""), + }) + .0 + .clone(); + let tfc_group = form + .tfc_group + .as_ref() + .unwrap_or(&Text { + 0: String::from(""), + }) + .0 + .clone(); + let shirt = form + .shirt + .as_ref() + .unwrap_or(&Text { + 0: String::from(""), + }) + .0 + .clone(); + log::info!("{first} {last} signed up for the local mission trip!"); + let email = markup::new! { + @markup::doctype() + html { + head { + title { @format!("{} {} signed up for the local mission trip!", first, last) } + style { + "table { border-collapse: collapse; width: 100% }" + "td, th { padding: 8px }" + "td { text-align: left; width: 70%; word-wrap: break-word }" + "th { text-align: right; border-right: 1px solid #ddd }" + "tr { border-bottom: 1px solid #ddd }" + "h1 { text-align: center }" + } + } + body { + h1 { @format!("Mission trip form for {} {}!", first, last) } + hr; + table { + tr { + th { "Name" } + td { @format!("{} {}", first, last) } + } + tr { + th { "Parent" } + td { @parent } + } + tr { + th { "Birthdate" } + td { @birthdate } + } + tr { + th { "Gender" } + td { @gender } + } + tr { + th { "Street" } + td { @street } + } + tr { + th { "City" } + td { @city } + } + tr { + th { "State" } + td { @state } + } + tr { + th { "Zip" } + td { @zip } + } + tr { + th { "Phone" } + td { @cellphone } + } + tr { + th { "Parent Phone" } + td { @parentphone } + } + tr { + th { "Email" } + td { @email } + } + tr { + th { "Parent Email" } + td { @parentemail } + } + tr { + th { "School" } + td { @school } + } + tr { + th { "Grade" } + td { @grade } + } + tr { + th { "Pastor" } + td { @pastor } + } + tr { + th { "Church Attendance" } + td { @church_attendance } + } + tr { + th { "TFC Group" } + td { @tfc_group } + } + tr { + th { "T-Shirt Size" } + td { @shirt } + } + } + } + } + }; + log::info!("{:?}", form); + let multi = MultiPart::alternative_plain_html(String::from("Testing"), email.to_string()); + + if let Ok(m) = Message::builder() + .from( + "TFC ADMIN " + .parse() + .unwrap(), + ) + .to("Chris Cochrun ".parse().unwrap()) + .to("Ethan Rose ".parse().unwrap()) + .subject(email_subject) + .multipart(multi) + { + let sender = SmtpTransport::relay("mail.tfcconnection.org") + .ok() + .unwrap() + .credentials(Credentials::new( + "no-reply@mail.tfcconnection.org".to_owned(), + "r9f36mNZFtiW4f".to_owned(), + )) + .authentication(vec![Mechanism::Plain]) + .build(); + match sender.send(&m) { + Ok(res) => log::info!("{:?}", res), + Err(e) => log::info!("{e}"), + } + } else { + log::info!("Email incorrect"); + } + + HttpResponse::Ok().body("thankyou") +} diff --git a/src/api/mod.rs b/src/api/mod.rs index 92d4be5..78cad7a 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -1,5 +1,6 @@ pub mod church_form; pub mod health_form; +pub mod local_trip_form; pub mod mt_form; pub mod parent_form; pub mod teacher_form; diff --git a/src/main.rs b/src/main.rs index 63e6b85..ea26997 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,6 +6,7 @@ use actix_multipart::form::tempfile::TempFileConfig; use actix_web::{middleware, App, HttpServer}; use api::church_form::church_form; use api::health_form::health_form; +use api::local_trip_form::local_form; use api::mt_form::mt_form; use api::parent_form::parent_form; use api::teacher_form::teacher_form; @@ -46,6 +47,7 @@ async fn main() -> std::io::Result<()> { .service(parent_form) .service(teacher_form) .service(church_form) + .service(local_form) }) .bind(("127.0.0.1", 4242))? .workers(2)