diff --git a/src/api/camp_form.rs b/src/api/camp_form.rs index 64e4f0e..72e932a 100644 --- a/src/api/camp_form.rs +++ b/src/api/camp_form.rs @@ -10,6 +10,7 @@ use lettre::{ use maud::html; use maud::DOCTYPE; use reqwest::{Client, Error}; +use tracing::info; use crate::email::send_email; @@ -45,7 +46,7 @@ struct CampForm { #[post("/camp-form")] pub async fn camp_form(MultipartForm(form): MultipartForm) -> HttpResponse { - log::info!("a new form"); + info!("a new form"); let first = form .first_name .as_ref() @@ -154,9 +155,9 @@ pub async fn camp_form(MultipartForm(form): MultipartForm) -> HttpResp .clone(); let reg = registration.clone(); - log::info!("Sending post to database"); + info!("Sending post to database"); - log::info!("{first} {last} signed up for camp!"); + info!("{first} {last} signed up for camp!"); let email = html! { (DOCTYPE) meta charset="utf-8"; @@ -262,17 +263,17 @@ pub async fn camp_form(MultipartForm(form): MultipartForm) -> HttpResp { let _ = send_email(m); } else { - log::info!("Email incorrect"); + info!("Email incorrect"); } match store_camp_form(form).await { - Ok(_) => log::info!("Successfully posted to nextcloud tables"), + Ok(_) => info!("Successfully posted to nextcloud tables"), Err(e) => log::error!("Error in posting camp data: {:?}", e), } match health.as_str() { "now" => { - log::info!("Sending them to fill out the health form"); + info!("Sending them to fill out the health form"); HttpResponse::Ok() .insert_header(("Access-Control-Expose-Headers", "*")) .insert_header(( @@ -286,7 +287,7 @@ pub async fn camp_form(MultipartForm(form): MultipartForm) -> HttpResp } "later" => match reg.as_str() { "now" => { - log::info!("Sending them to pay for registration now"); + info!("Sending them to pay for registration now"); HttpResponse::Ok() .insert_header(("Access-Control-Expose-Headers", "*")) .insert_header(( @@ -296,7 +297,7 @@ pub async fn camp_form(MultipartForm(form): MultipartForm) -> HttpResp .finish() } "full" => { - log::info!("Sending them to pay for the full registration now"); + info!("Sending them to pay for the full registration now"); HttpResponse::Ok() .insert_header(("Access-Control-Expose-Headers", "*")) .insert_header(( @@ -306,7 +307,7 @@ pub async fn camp_form(MultipartForm(form): MultipartForm) -> HttpResp .finish() } "later" => { - log::info!("{} would like to pay later", full_name); + info!("{} would like to pay later", full_name); let html = html! { div class="mt-8" { h2 { diff --git a/src/api/church_form.rs b/src/api/church_form.rs index 32294a7..d83b4c1 100644 --- a/src/api/church_form.rs +++ b/src/api/church_form.rs @@ -5,6 +5,9 @@ use lettre::{ transport::smtp::authentication::{Credentials, Mechanism}, Message, SmtpTransport, Transport, }; +use tracing::info; + +use crate::email::send_email; #[derive(Debug, MultipartForm, Default)] struct ChurchForm { @@ -84,7 +87,7 @@ pub async fn church_form(MultipartForm(form): MultipartForm) -> Http .unwrap_or(&Text(String::from(""))) .0 .clone(); - log::info!("{first} {last} filled out a Church Reference form!"); + info!("{first} {last} filled out a Church Reference form!"); let email = markup::new! { @markup::doctype() html { @@ -156,21 +159,9 @@ pub async fn church_form(MultipartForm(form): MultipartForm) -> Http .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}"), - } + let _ = send_email(m); } else { - log::info!("Email incorrect"); + info!("Email incorrect"); } HttpResponse::Ok().body("hi") diff --git a/src/api/health_form.rs b/src/api/health_form.rs index eb67078..de3b794 100644 --- a/src/api/health_form.rs +++ b/src/api/health_form.rs @@ -9,6 +9,9 @@ use lettre::{ }; use maud::html; use reqwest::{Client, Error}; +use tracing::info; + +use crate::email::send_email; #[derive(Debug, MultipartForm, Default)] struct HealthForm { @@ -254,7 +257,7 @@ pub async fn health_form(MultipartForm(form): MultipartForm) -> Http .unwrap_or(&Text(String::from(""))) .0 .clone(); - log::info!("{first} {last} filled out a health form!"); + info!("{first} {last} filled out a health form!"); let email = html! { html { head { @@ -387,10 +390,10 @@ pub async fn health_form(MultipartForm(form): MultipartForm) -> Http let mut path: Option = Some(String::from("")); let mut file_exists = false; let mut filename = String::from(""); - log::info!("Does the file exist? {:?}", file_exists); + info!("Does the file exist? {:?}", file_exists); match store_health_form(&form).await { - Ok(_) => log::info!("Successfully posted the health form in nextcloud tables"), + Ok(_) => info!("Successfully posted the health form in nextcloud tables"), Err(e) => log::error!("Error posting health form to nextcloud tables: {:?}", e), } @@ -403,10 +406,10 @@ pub async fn health_form(MultipartForm(form): MultipartForm) -> Http path = Some(format!("./tmp/{}", file)); } // let path = format!("./tmp/{}", file); - log::info!("saving to {}", path.clone().unwrap()); + info!("saving to {}", path.clone().unwrap()); match f.file.persist(path.clone().unwrap()) { Ok(f) => { - log::info!( + info!( "Hey! We got a file! {:?}", f.metadata().expect("Something bad happened mate") ); @@ -414,7 +417,7 @@ pub async fn health_form(MultipartForm(form): MultipartForm) -> Http file_exists = true; } } - Err(e) => log::info!("{:?}: Probably a missing image", e), + Err(e) => info!("{:?}: Probably a missing image", e), } } } @@ -423,7 +426,7 @@ pub async fn health_form(MultipartForm(form): MultipartForm) -> Http let filebody = fs::read(path.clone().unwrap_or_default()); let content_type = ContentType::parse("image/jpg").unwrap(); let attachment = Attachment::new(filename).body(filebody.unwrap(), content_type); - // log::info!("The attachment is: {:?}", attachment.headers()); + // info!("The attachment is: {:?}", attachment.headers()); MultiPart::mixed() .singlepart(SinglePart::html(email.into_string())) .singlepart(attachment) @@ -431,7 +434,7 @@ pub async fn health_form(MultipartForm(form): MultipartForm) -> Http MultiPart::alternative_plain_html(String::from("Testing"), email.into_string()) }; - // log::info!("{:?}", multi); + // info!("{:?}", multi); if let Ok(m) = Message::builder() .from( @@ -444,26 +447,14 @@ pub async fn health_form(MultipartForm(form): MultipartForm) -> Http .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}"), - } + let _ = send_email(m); } else { - log::info!("Email incorrect"); + info!("Email incorrect"); } match registration.as_str() { "now" => { - log::info!("Sending them to pay for registration now"); + info!("Sending them to pay for registration now"); HttpResponse::Ok() .insert_header(("Access-Control-Expose-Headers", "*")) .insert_header(( @@ -473,7 +464,7 @@ pub async fn health_form(MultipartForm(form): MultipartForm) -> Http .finish() } "full" => { - log::info!("Sending them to pay for the full registration now"); + info!("Sending them to pay for the full registration now"); HttpResponse::Ok() .insert_header(("Access-Control-Expose-Headers", "*")) .insert_header(( @@ -483,7 +474,7 @@ pub async fn health_form(MultipartForm(form): MultipartForm) -> Http .finish() } "later" => { - log::info!("{} would like to pay later", full_name); + info!("{} would like to pay later", full_name); let html = html! { div class="mt-8" { h2 { diff --git a/src/api/local_trip_form.rs b/src/api/local_trip_form.rs index fa38b2b..1ded80e 100644 --- a/src/api/local_trip_form.rs +++ b/src/api/local_trip_form.rs @@ -5,6 +5,9 @@ use lettre::{ transport::smtp::authentication::{Credentials, Mechanism}, Message, SmtpTransport, Transport, }; +use tracing::info; + +use crate::email::send_email; #[derive(Debug, MultipartForm, Default)] struct LocalForm { @@ -165,7 +168,7 @@ pub async fn local_form(MultipartForm(form): MultipartForm) -> HttpRe .unwrap_or(&Text(String::from(""))) .0 .clone(); - log::info!("{first} {last} signed up for the local mission trip!"); + info!("{first} {last} signed up for the local mission trip!"); let email = markup::new! { @markup::doctype() html { @@ -260,7 +263,7 @@ pub async fn local_form(MultipartForm(form): MultipartForm) -> HttpRe } } }; - log::info!("{:?}", form); + info!("{:?}", form); let multi = MultiPart::alternative_plain_html(String::from("Testing"), email.to_string()); if let Ok(m) = Message::builder() @@ -274,21 +277,9 @@ pub async fn local_form(MultipartForm(form): MultipartForm) -> HttpRe .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}"), - } + let _ = send_email(m); } else { - log::info!("Email incorrect"); + info!("Email incorrect"); } HttpResponse::Ok().body("thankyou") diff --git a/src/api/mt_form.rs b/src/api/mt_form.rs index 213fb5a..63fe267 100644 --- a/src/api/mt_form.rs +++ b/src/api/mt_form.rs @@ -1,17 +1,13 @@ use std::fs; use actix_multipart::form::{tempfile::TempFile, text::Text, MultipartForm}; -use actix_rt::Runtime; use actix_web::{post, HttpResponse}; -use color_eyre::Result; use lettre::{ message::{header::ContentType, Attachment, MultiPart, SinglePart}, - transport::smtp::authentication::{Credentials, Mechanism}, - Message, SmtpTransport, Transport, + Message, }; -use markup::DynRender; use maud::{html, PreEscaped, DOCTYPE}; -use tracing::{error, info, warn}; +use tracing::{error, info}; #[derive(Debug, MultipartForm)] struct MtForm { @@ -228,7 +224,7 @@ pub async fn mt_form(MultipartForm(form): MultipartForm) -> HttpResponse let last = form.last_name.clone(); let email_subject = format!("{} {} signed up for mission trip!", first, last); let filename_noext = format!("{}_{}", first, last); - log::info!("{first} {last} signed up for mission trip!"); + info!("{first} {last} signed up for mission trip!"); let email = form.build_email().await; let mut path = String::from(""); let mut file_exists = false; @@ -250,7 +246,7 @@ pub async fn mt_form(MultipartForm(form): MultipartForm) -> HttpResponse file_exists = true; } } - Err(e) => log::info!("{:?}: Probably a missing image", e), + Err(e) => info!("{:?}: Probably a missing image", e), } } diff --git a/src/api/parent_form.rs b/src/api/parent_form.rs index b7f133d..c9fe58b 100644 --- a/src/api/parent_form.rs +++ b/src/api/parent_form.rs @@ -5,6 +5,9 @@ use lettre::{ transport::smtp::authentication::{Credentials, Mechanism}, Message, SmtpTransport, Transport, }; +use tracing::info; + +use crate::email::send_email; #[derive(Debug, MultipartForm, Default)] struct ParentForm { @@ -91,7 +94,7 @@ pub async fn parent_form(MultipartForm(form): MultipartForm) -> Http .unwrap_or(&Text(String::from(""))) .0 .clone(); - log::info!("{first} {last} filled out a parent form!"); + info!("{first} {last} filled out a parent form!"); let email = markup::new! { @markup::doctype() html { @@ -167,21 +170,9 @@ pub async fn parent_form(MultipartForm(form): MultipartForm) -> Http .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}"), - } + let _ = send_email(m); } else { - log::info!("Email incorrect"); + info!("Email incorrect"); } HttpResponse::Ok().body("hi") diff --git a/src/api/teacher_form.rs b/src/api/teacher_form.rs index e3e4831..5d734d7 100644 --- a/src/api/teacher_form.rs +++ b/src/api/teacher_form.rs @@ -5,6 +5,9 @@ use lettre::{ transport::smtp::authentication::{Credentials, Mechanism}, Message, SmtpTransport, Transport, }; +use tracing::info; + +use crate::email::send_email; #[derive(Debug, MultipartForm, Default)] struct TeacherForm { @@ -75,7 +78,7 @@ pub async fn teacher_form(MultipartForm(form): MultipartForm) -> Ht .unwrap_or(&Text(String::from(""))) .0 .clone(); - log::info!("{first} {last} filled out a teacher form!"); + info!("{first} {last} filled out a teacher form!"); let email = markup::new! { @markup::doctype() html { @@ -143,21 +146,9 @@ pub async fn teacher_form(MultipartForm(form): MultipartForm) -> Ht .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}"), - } + let _ = send_email(m); } else { - log::info!("Email incorrect"); + info!("Email incorrect"); } HttpResponse::Ok().body("hi")