From dc15b66627af843cec786d6912b0fcb512667c3b Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Thu, 21 Mar 2024 10:00:13 -0500 Subject: [PATCH] basic camp form system --- content/_index.md | 37 ++-- content/camp-form.md | 36 ++-- justfile | 2 + layouts/shortcodes/camp-form.html | 36 ++-- src/api/camp_form.rs | 286 ++++++++++++++++++++++++++++++ src/api/mod.rs | 1 + src/main.rs | 22 +-- 7 files changed, 340 insertions(+), 80 deletions(-) create mode 100644 src/api/camp_form.rs diff --git a/content/_index.md b/content/_index.md index 0500f89..1bd9e90 100644 --- a/content/_index.md +++ b/content/_index.md @@ -8,32 +8,27 @@ showTitle: false Teens For Christ Connection (TFC) is a rural ministry reaching out to the mission field of teenagers in rural communities across Northwest Kansas and Southwest Nebraska. In rural communities where youth ministry programs and resources are limited, TFC desires to partner with churches to meet this need. Whether this is through providing community youth groups, coaching those already working with youth, or supplying resources and extra curricular activities for area ministries, TFC desires to connect teens with the truth of Jesus Christ and equip them to live out the Great Commission. - - - - - - +
+ +{{< typeit tag=h2 lifeLike=true >}} +Camp registration is now open!! +{{< /typeit >}} + - + - - - - - - + +{{< button href="/camp-form" >}} +Fill out now! +{{< /button >}} + +
- +{{< spacing height=h-4 >}} -> If you need to fill out a health form, please do so [here](/health-form). -> -> Please also fill out the: -> - [parent reference form](/mt-parent-form) -> - [teacher reference form](/mt-teacher-form) -> - [church reference form](/mt-church-form) +> If you need to fill out a camp health form, please do so [here](/camp-health-form). -{{< pt src="https://videos.tfcconnection.org/videos/embed/c92fc5dd-ebfd-4d13-b486-d08d281868f2" >}} +{{< pt src="https://videos.tfcconnection.org/videos/embed/757dc0dd-9bdc-4d79-8f81-754249ff23d2" >}} ## Our Vision Our vision is to change the world from the heart of America by providing disciple making opportunities that serve communities where student ministries are limited. diff --git a/content/camp-form.md b/content/camp-form.md index f7909b5..27de843 100644 --- a/content/camp-form.md +++ b/content/camp-form.md @@ -6,29 +6,29 @@ sharingLinks: false --- -We are currently working on updating the form!! Check back soon to get signed up for camp!! + - - +{{< floating-button icon="chevron-down" text="To the form!" link="#form" >}} +{{< pt src="https://videos.tfcconnection.org/videos/embed/757dc0dd-9bdc-4d79-8f81-754249ff23d2" width="700" height="576">}} - +We hope you are as excited about camp as we are! If there is anything we can do to answer your questions and help you to get signed up for camp, please let us know! You can email any of us by going to the [contact page](/contact). - - - +## Dates +- Week 1 - July 22 - July 26 +- Week 2 - July 29 - Aug 2 - - - - - +## Cost +We have an early bird registration, so if you register by certain dates, you'll save some money! +- By May 8: $65 with registration plus $100 due at camp and a free t shirt! +- By June 28: $85 with registration plus $100 due at camp and a free t shirt! +- After June 28: $85 with registration plus $100 due at camp... _NO FREE T SHIRT!!!_ - - +## Location +Camp Joy in Republican City, NE - - +[70790 Corp Rd 23, Republican City, NE 68971](https://maps.google.com/maps?z=16&q=70790%2Bcorp%2Brd%2B23%2Brepublican%2Bcity%2C%2Bne%2B68971) + - +{{< map mapName="campmap_888075" >}} - +{{< camp-form >}} diff --git a/justfile b/justfile index 980a05b..9c5a727 100644 --- a/justfile +++ b/justfile @@ -6,6 +6,8 @@ server: hugo server --noHTTPCache --disableFastRender dev: NODE_ENV=development ./themes/blowfish/node_modules/tailwindcss/lib/cli.js -c ./themes/blowfish/tailwind.config.js -i ./themes/blowfish/assets/css/main.css -o ./assets/css/compiled/main.css --jit -w +api: + cargo build clean: cargo clean rm -rf bld/ diff --git a/layouts/shortcodes/camp-form.html b/layouts/shortcodes/camp-form.html index 13c6fa4..79ed948 100644 --- a/layouts/shortcodes/camp-form.html +++ b/layouts/shortcodes/camp-form.html @@ -23,13 +23,17 @@ document.getElementById('warning-email').style.margin = '0'; } - var xhr = new XMLHttpRequest(); - xhr.onreadystatechange = function() { - if (this.readyState == 4 && this.status == 200) { + let base = "http://localhost:4242/camp-form"; + /* let base = "https://api.tfcconnection.org/camp-form"; */ + + fetch(base, { + method: "POST", + body: data + }).then((res) => { + console.log(res); + if (res.ok) { let payment = data.get('registration'); - console.log(payment); let health = data.get('health'); - console.log(health); if (health === 'later') { if (payment === 'now') window.location.href = 'https://secure.myvanco.com/L-Z772/campaign/C-13JPJ'; @@ -39,20 +43,10 @@ window.location.href = '/thankyou/'; } else { - if (payment === 'later') - window.location.href = '/thankyou/'; - else - window.location.href = '/camp-health-form?registration=' + payment; + window.location.href = '/camp-health-form?registration=' + payment; } - } - }; - /* xhr.open("POST", "https://n8n.tfcconnection.org/webhook/mt-application"); */ - xhr.open("POST", "https://api.tfcconnection.org/camp-form"); - xhr.send(data); - console.log(data); - console.log("Hallo!"); - /* return false; */ + }); } function calculate_age(dob) { @@ -168,8 +162,8 @@ @@ -218,7 +212,7 @@
@@ -232,7 +226,7 @@
diff --git a/src/api/camp_form.rs b/src/api/camp_form.rs new file mode 100644 index 0000000..c51d8f3 --- /dev/null +++ b/src/api/camp_form.rs @@ -0,0 +1,286 @@ +use std::fs; + +use actix_multipart::form::{tempfile::TempFile, text::Text, MultipartForm}; +use actix_web::{post, HttpResponse}; +use lettre::{ + message::{header::ContentType, Attachment, MultiPart, SinglePart}, + transport::smtp::authentication::{Credentials, Mechanism}, + Message, SmtpTransport, Transport, +}; + +#[derive(Debug, MultipartForm, Default)] +struct CampForm { + #[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>, + parentphone: Option>, + parentemail: Option>, + grade: Option>, + shirt: Option>, + allergies: Option>, + week: Option>, + registration: Option>, +} + +#[post("/camp-form")] +pub async fn camp_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 camp!", 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 parentphone = form + .parentphone + .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 grade = form + .grade + .as_ref() + .unwrap_or(&Text { + 0: String::from(""), + }) + .0 + .clone(); + let shirt = form + .shirt + .as_ref() + .unwrap_or(&Text { + 0: String::from(""), + }) + .0 + .clone(); + let allergies = form + .allergies + .as_ref() + .unwrap_or(&Text { + 0: String::from(""), + }) + .0 + .clone(); + let week = form + .week + .as_ref() + .unwrap_or(&Text { + 0: String::from(""), + }) + .0 + .clone(); + let registration = form + .registration + .as_ref() + .unwrap_or(&Text { + 0: String::from(""), + }) + .0 + .clone(); + log::info!("{first} {last} signed up for camp!"); + let email = markup::new! { + @markup::doctype() + html { + head { + title { @format!("{} {} signed up for camp!", 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 { "Parent Phone" } + td { @parentphone } + } + tr { + th { "Parent Email" } + td { @parentemail } + } + tr { + th { "Grade" } + td { @grade } + } + tr { + th { "Camper Allergies" } + td { @allergies } + } + tr { + th { "T-Shirt Size" } + td { @shirt } + } + tr { + th { "Week Choice" } + td { @week } + } + tr { + th { "Registration" } + td { @registration } + } + } + } + } + }; + let multi = MultiPart::alternative_plain_html( + String::from("A camp form was filled out!"), + 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 78cad7a..e291cc9 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -1,3 +1,4 @@ +pub mod camp_form; pub mod church_form; pub mod health_form; pub mod local_trip_form; diff --git a/src/main.rs b/src/main.rs index ea26997..d98546b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,16 +1,14 @@ mod api; -use std::collections::HashMap; - use actix_multipart::form::tempfile::TempFileConfig; use actix_web::{middleware, App, HttpServer}; +use api::camp_form::camp_form; 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; -use serde_json::{Number, Value}; #[actix_web::main] async fn main() -> std::io::Result<()> { @@ -21,23 +19,6 @@ async fn main() -> std::io::Result<()> { log::info!("starting HTTP server at http://localhost:4242"); - // let mut fields = HashMap::new(); - // fields.insert("value", Value::String("Frodo".to_string())); - // fields.insert("columnId", Value::Number(Number::from(106))); - - // let mut data = HashMap::new(); - // data.insert("data", vec![fields]); - // // let vec = vec![data]; - // log::info!("{:?}", serde_json::to_string(&data).unwrap()); - - // let req = reqwest::Client::new() - // .post("https://staff.tfcconnection.org/apps/tables/api/1/tables/9/rows") - // .basic_auth("chris", Some("2VHeGxeC^Zf9KqFK^G@Pt!zu2q^6@b")) - // .json(&data) - // .send() - // .await; - // log::info!("{:?}", req.unwrap().text().await.unwrap()); - HttpServer::new(|| { App::new() .wrap(middleware::Logger::default()) @@ -48,6 +29,7 @@ async fn main() -> std::io::Result<()> { .service(teacher_form) .service(church_form) .service(local_form) + .service(camp_form) }) .bind(("127.0.0.1", 4242))? .workers(2)