adding working mission trip forms
This commit is contained in:
parent
6603d2c6bc
commit
67fb7b0f00
16 changed files with 104 additions and 581 deletions
|
@ -1,164 +0,0 @@
|
|||
use actix_multipart::form::{text::Text, MultipartForm};
|
||||
use actix_web::{post, HttpResponse};
|
||||
use lettre::{message::MultiPart, Message};
|
||||
use tracing::info;
|
||||
|
||||
use crate::email::send_email;
|
||||
|
||||
#[derive(Debug, MultipartForm, Default)]
|
||||
struct ChurchForm {
|
||||
#[multipart(rename = "firstname")]
|
||||
first_name: Option<Text<String>>,
|
||||
#[multipart(rename = "lastname")]
|
||||
last_name: Option<Text<String>>,
|
||||
#[multipart(rename = "studentfirstname")]
|
||||
student_first_name: Option<Text<String>>,
|
||||
#[multipart(rename = "studentlastname")]
|
||||
student_last_name: Option<Text<String>>,
|
||||
relationship: Option<Text<String>>,
|
||||
#[multipart(rename = "walk-with-jesus")]
|
||||
walk: Option<Text<String>>,
|
||||
commitment: Option<Text<String>>,
|
||||
teachable: Option<Text<String>>,
|
||||
#[multipart(rename = "pos-characteristics")]
|
||||
positive: Option<Text<String>>,
|
||||
#[multipart(rename = "neg-characteristics")]
|
||||
negative: Option<Text<String>>,
|
||||
#[multipart(rename = "extra-info")]
|
||||
notes: Option<Text<String>>,
|
||||
}
|
||||
|
||||
#[post("/church-form")]
|
||||
pub async fn church_form(MultipartForm(form): MultipartForm<ChurchForm>) -> HttpResponse {
|
||||
let first = form.first_name.as_ref().unwrap().0.clone();
|
||||
let last = form.last_name.as_ref().unwrap().0.clone();
|
||||
let student = format!(
|
||||
"{} {}",
|
||||
form.student_first_name.as_ref().unwrap().0.clone(),
|
||||
form.student_last_name.as_ref().unwrap().0.clone()
|
||||
);
|
||||
let email_subject = format!(
|
||||
"{} {} filled out a Church Reference form for {}!",
|
||||
first, last, student
|
||||
);
|
||||
let relationship = form
|
||||
.relationship
|
||||
.as_ref()
|
||||
.unwrap_or(&Text(String::from("")))
|
||||
.0
|
||||
.clone();
|
||||
let walk = form
|
||||
.walk
|
||||
.as_ref()
|
||||
.unwrap_or(&Text(String::from("")))
|
||||
.0
|
||||
.clone();
|
||||
let positive = form
|
||||
.positive
|
||||
.as_ref()
|
||||
.unwrap_or(&Text(String::from("")))
|
||||
.0
|
||||
.clone();
|
||||
let negative = form
|
||||
.negative
|
||||
.as_ref()
|
||||
.unwrap_or(&Text(String::from("")))
|
||||
.0
|
||||
.clone();
|
||||
let commitment = form
|
||||
.commitment
|
||||
.as_ref()
|
||||
.unwrap_or(&Text(String::from("")))
|
||||
.0
|
||||
.clone();
|
||||
let teachable = form
|
||||
.teachable
|
||||
.as_ref()
|
||||
.unwrap_or(&Text(String::from("")))
|
||||
.0
|
||||
.clone();
|
||||
let notes = form
|
||||
.notes
|
||||
.as_ref()
|
||||
.unwrap_or(&Text(String::from("")))
|
||||
.0
|
||||
.clone();
|
||||
info!("{first} {last} filled out a Church Reference form!");
|
||||
let email = markup::new! {
|
||||
@markup::doctype()
|
||||
html {
|
||||
head {
|
||||
title { @format!("{} {} filled out a Church Reference form for {}!", first, last, student) }
|
||||
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!("Church Reference form for {}!", student) }
|
||||
hr;
|
||||
table {
|
||||
tr {
|
||||
th { "Name" }
|
||||
td { @format!("{} {}", first, last) }
|
||||
}
|
||||
tr {
|
||||
th { "Student" }
|
||||
td { @student }
|
||||
}
|
||||
tr {
|
||||
th { "Relationship to teen" }
|
||||
td { @relationship }
|
||||
}
|
||||
tr {
|
||||
th { "Walk with Jesus" }
|
||||
td { @walk }
|
||||
}
|
||||
tr {
|
||||
th { "Commitment to church" }
|
||||
td { @commitment }
|
||||
}
|
||||
tr {
|
||||
th { "Teachable spirit" }
|
||||
td { @teachable }
|
||||
}
|
||||
tr {
|
||||
th { "Positive Attributes" }
|
||||
td { @positive }
|
||||
}
|
||||
tr {
|
||||
th { "Negaitive Attributes" }
|
||||
td { @negative }
|
||||
}
|
||||
tr {
|
||||
th { "Other Notes" }
|
||||
td { @notes }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
let multi = MultiPart::alternative_plain_html(String::from("Testing"), email.to_string());
|
||||
|
||||
if let Ok(m) = Message::builder()
|
||||
.from(
|
||||
"TFC ADMIN <no-reply@mail.tfcconnection.org>"
|
||||
.parse()
|
||||
.unwrap(),
|
||||
)
|
||||
.to("Chris Cochrun <chris@tfcconnection.org>".parse().unwrap())
|
||||
.to("Ethan Rose <ethan@tfcconnection.org>".parse().unwrap())
|
||||
.subject(email_subject)
|
||||
.multipart(multi)
|
||||
{
|
||||
let _ = send_email(m);
|
||||
} else {
|
||||
info!("Email incorrect");
|
||||
}
|
||||
|
||||
HttpResponse::Ok().body("hi")
|
||||
}
|
|
@ -1,5 +1,4 @@
|
|||
pub mod camp_form;
|
||||
pub mod church_form;
|
||||
// pub mod errors;
|
||||
pub mod health_form;
|
||||
pub mod local_trip_form;
|
||||
|
@ -7,5 +6,3 @@ pub mod mt_church_form;
|
|||
pub mod mt_form;
|
||||
pub mod mt_parent_form;
|
||||
pub mod mt_teacher_form;
|
||||
pub mod parent_form;
|
||||
pub mod teacher_form;
|
||||
|
|
|
@ -65,7 +65,7 @@ impl MtChurchForm {
|
|||
meta charset="utf-8";
|
||||
html {
|
||||
head {
|
||||
title { (self.first_name.0) " " (self.last_name.0) " signed up for mission trip!" }
|
||||
title { (self.first_name.0) " " (self.last_name.0) " filled out a church reference form for " (self.student_first_name.0) " " (self.student_last_name.0) "!" }
|
||||
style {
|
||||
"table { border-collapse: collapse; width: 100% }"
|
||||
"td, th { padding: 8px }"
|
||||
|
@ -76,7 +76,7 @@ impl MtChurchForm {
|
|||
}
|
||||
}
|
||||
body {
|
||||
h1 { "Mission trip form for " (self.first_name.0) " " (self.last_name.0) "!" }
|
||||
h1 { "Church reference form for " (self.student_first_name.0) " " (self.student_last_name.0) "!" }
|
||||
hr;
|
||||
table {
|
||||
tr {
|
||||
|
@ -148,10 +148,10 @@ impl MtChurchForm {
|
|||
}
|
||||
|
||||
async fn send_email(&mut self) -> Result<()> {
|
||||
let first = self.first_name.clone();
|
||||
let last = self.last_name.clone();
|
||||
let email_subject = format!("{} {} signed up for mission trip!", first, last);
|
||||
info!("{first} {last} signed up for mission trip!");
|
||||
let first = self.student_first_name.clone();
|
||||
let last = self.student_last_name.clone();
|
||||
let email_subject = format!("Church reference form for {} {}!", first, last);
|
||||
info!("{first} {last} church reference form!");
|
||||
let email = self.build_email().await;
|
||||
let email = SinglePart::html(email.into_string());
|
||||
|
||||
|
@ -172,8 +172,8 @@ impl MtChurchForm {
|
|||
}
|
||||
}
|
||||
|
||||
#[post("/api/mt-teacher-form")]
|
||||
pub async fn mt_form(MultipartForm(mut form): MultipartForm<MtChurchForm>) -> HttpResponse {
|
||||
#[post("/api/mt-church-form")]
|
||||
pub async fn mt_church_form(MultipartForm(mut form): MultipartForm<MtChurchForm>) -> HttpResponse {
|
||||
match form.store_form().await {
|
||||
Ok(_) => info!("Successfully sent form to nextcloud!"),
|
||||
Err(e) => error!("There was an erroring sending form to nextcloud: {e}"),
|
||||
|
@ -196,9 +196,9 @@ mod test {
|
|||
|
||||
fn form() -> MtChurchForm {
|
||||
MtChurchForm {
|
||||
first_name: Text(String::from("Frodo")),
|
||||
first_name: Text(String::from("Bilbo")),
|
||||
last_name: Text(String::from("Braggins")),
|
||||
student_first_name: Text(String::from("Bilbo")),
|
||||
student_first_name: Text(String::from("Frodo")),
|
||||
student_last_name: Text(String::from("Braggins")),
|
||||
relationship: Text(String::from("Uncle")),
|
||||
positive: Text(String::from("Nimble and brave")),
|
||||
|
|
|
@ -22,6 +22,7 @@ struct MtParentForm {
|
|||
first_name: Text<String>,
|
||||
#[multipart(rename = "lastname")]
|
||||
last_name: Text<String>,
|
||||
email: Text<String>,
|
||||
#[multipart(rename = "studentfirstname")]
|
||||
student_first_name: Text<String>,
|
||||
#[multipart(rename = "studentlastname")]
|
||||
|
@ -42,18 +43,19 @@ struct MtParentForm {
|
|||
impl From<&MtParentForm> for HashMap<i32, String> {
|
||||
fn from(form: &MtParentForm) -> Self {
|
||||
let mut map = HashMap::new();
|
||||
map.insert(158, format!("{} {}", form.first_name.0, form.last_name.0));
|
||||
map.insert(167, format!("{} {}", form.first_name.0, form.last_name.0));
|
||||
map.insert(
|
||||
159,
|
||||
168,
|
||||
format!("{} {}", form.student_first_name.0, form.student_last_name.0),
|
||||
);
|
||||
map.insert(160, form.authority.0.clone());
|
||||
map.insert(163, form.positive.0.clone());
|
||||
map.insert(164, form.negative.0.clone());
|
||||
map.insert(161, form.family.0.clone());
|
||||
map.insert(162, form.previous_trip.0.clone());
|
||||
map.insert(165, form.feelings.0.clone());
|
||||
map.insert(166, form.extra_info.0.clone());
|
||||
map.insert(169, form.authority.0.clone());
|
||||
map.insert(170, form.positive.0.clone());
|
||||
map.insert(171, form.negative.0.clone());
|
||||
map.insert(172, form.family.0.clone());
|
||||
map.insert(173, form.previous_trip.0.clone());
|
||||
map.insert(174, form.feelings.0.clone());
|
||||
map.insert(175, form.extra_info.0.clone());
|
||||
map.insert(176, form.email.0.clone());
|
||||
map
|
||||
}
|
||||
}
|
||||
|
@ -65,7 +67,7 @@ impl MtParentForm {
|
|||
meta charset="utf-8";
|
||||
html {
|
||||
head {
|
||||
title { (self.first_name.0) " " (self.last_name.0) " signed up for mission trip!" }
|
||||
title { (self.first_name.0) " " (self.last_name.0) " filled out a parent form for " (self.student_first_name.0) " " (self.student_last_name.0) "!" }
|
||||
style {
|
||||
"table { border-collapse: collapse; width: 100% }"
|
||||
"td, th { padding: 8px }"
|
||||
|
@ -76,7 +78,7 @@ impl MtParentForm {
|
|||
}
|
||||
}
|
||||
body {
|
||||
h1 { "Mission trip form for " (self.first_name.0) " " (self.last_name.0) "!" }
|
||||
h1 { "Parent reference form for " (self.student_first_name.0) " " (self.student_last_name.0) "!" }
|
||||
hr;
|
||||
table {
|
||||
tr {
|
||||
|
@ -87,6 +89,10 @@ impl MtParentForm {
|
|||
th { "Student" }
|
||||
td { (self.student_first_name.0) " " (self.student_last_name.0) }
|
||||
}
|
||||
tr {
|
||||
th { "Email" }
|
||||
td { (self.email.0) }
|
||||
}
|
||||
tr {
|
||||
th { "Authority" }
|
||||
td { (self.authority.0) }
|
||||
|
@ -127,9 +133,9 @@ impl MtParentForm {
|
|||
let mut json = HashMap::new();
|
||||
json.insert("data", map);
|
||||
|
||||
let link = r#"https://staff.tfcconnection.org/apps/tables/#/table/13/row/757"#;
|
||||
let link = r#"https://staff.tfcconnection.org/apps/tables/#/table/14/row/757"#;
|
||||
let res = client
|
||||
.post("https://staff.tfcconnection.org/ocs/v2.php/apps/tables/api/2/tables/13/rows")
|
||||
.post("https://staff.tfcconnection.org/ocs/v2.php/apps/tables/api/2/tables/14/rows")
|
||||
.basic_auth("chris", Some("2VHeGxeC^Zf9KqFK^G@Pt!zu2q^6@b"))
|
||||
.header("OCS-APIRequest", "true")
|
||||
.header("Content-Type", "application/json")
|
||||
|
@ -148,10 +154,10 @@ impl MtParentForm {
|
|||
}
|
||||
|
||||
async fn send_email(&mut self) -> Result<()> {
|
||||
let first = self.first_name.clone();
|
||||
let last = self.last_name.clone();
|
||||
let email_subject = format!("{} {} signed up for mission trip!", first, last);
|
||||
info!("{first} {last} signed up for mission trip!");
|
||||
let first = self.student_first_name.clone();
|
||||
let last = self.student_last_name.clone();
|
||||
let email_subject = format!("Parent reference form for {} {}!", first, last);
|
||||
info!("{first} {last} parent reference form!");
|
||||
let email = self.build_email().await;
|
||||
let email = SinglePart::html(email.into_string());
|
||||
|
||||
|
@ -172,8 +178,8 @@ impl MtParentForm {
|
|||
}
|
||||
}
|
||||
|
||||
#[post("/api/mt-teacher-form")]
|
||||
pub async fn mt_form(MultipartForm(mut form): MultipartForm<MtParentForm>) -> HttpResponse {
|
||||
#[post("/api/mt-parent-form")]
|
||||
pub async fn mt_parent_form(MultipartForm(mut form): MultipartForm<MtParentForm>) -> HttpResponse {
|
||||
match form.store_form().await {
|
||||
Ok(_) => info!("Successfully sent form to nextcloud!"),
|
||||
Err(e) => error!("There was an erroring sending form to nextcloud: {e}"),
|
||||
|
@ -196,10 +202,11 @@ mod test {
|
|||
|
||||
fn form() -> MtParentForm {
|
||||
MtParentForm {
|
||||
first_name: Text(String::from("Frodo")),
|
||||
first_name: Text(String::from("Bilbo")),
|
||||
last_name: Text(String::from("Braggins")),
|
||||
student_first_name: Text(String::from("Bilbo")),
|
||||
student_first_name: Text(String::from("Frodo")),
|
||||
student_last_name: Text(String::from("Braggins")),
|
||||
email: Text(String::from("biblo@hobbits.us")),
|
||||
authority: Text(String::from("Uncle")),
|
||||
positive: Text(String::from("Nimble and brave")),
|
||||
negative: Text(String::from("Small")),
|
||||
|
|
|
@ -61,7 +61,7 @@ impl MtTeacherForm {
|
|||
meta charset="utf-8";
|
||||
html {
|
||||
head {
|
||||
title { (self.first_name.0) " " (self.last_name.0) " signed up for mission trip!" }
|
||||
title { (self.first_name.0) " " (self.last_name.0) " filled out a teacher reference form for " (self.student_first_name.0) " " (self.student_last_name.0) "!" }
|
||||
style {
|
||||
"table { border-collapse: collapse; width: 100% }"
|
||||
"td, th { padding: 8px }"
|
||||
|
@ -72,7 +72,7 @@ impl MtTeacherForm {
|
|||
}
|
||||
}
|
||||
body {
|
||||
h1 { "Mission trip form for " (self.first_name.0) " " (self.last_name.0) "!" }
|
||||
h1 { "Teacher reference form for " (self.student_first_name.0) " " (self.student_last_name.0) "!" }
|
||||
hr;
|
||||
table {
|
||||
tr {
|
||||
|
@ -140,10 +140,10 @@ impl MtTeacherForm {
|
|||
}
|
||||
|
||||
async fn send_email(&mut self) -> Result<()> {
|
||||
let first = self.first_name.clone();
|
||||
let last = self.last_name.clone();
|
||||
let email_subject = format!("{} {} signed up for mission trip!", first, last);
|
||||
info!("{first} {last} signed up for mission trip!");
|
||||
let first = self.student_first_name.clone();
|
||||
let last = self.student_last_name.clone();
|
||||
let email_subject = format!("Teacher reference form for {} {}!", first, last);
|
||||
info!("{first} {last} teacher reference form!");
|
||||
let email = self.build_email().await;
|
||||
let email = SinglePart::html(email.into_string());
|
||||
|
||||
|
@ -165,7 +165,9 @@ impl MtTeacherForm {
|
|||
}
|
||||
|
||||
#[post("/api/mt-teacher-form")]
|
||||
pub async fn mt_form(MultipartForm(mut form): MultipartForm<MtTeacherForm>) -> HttpResponse {
|
||||
pub async fn mt_teacher_form(
|
||||
MultipartForm(mut form): MultipartForm<MtTeacherForm>,
|
||||
) -> HttpResponse {
|
||||
match form.store_form().await {
|
||||
Ok(_) => info!("Successfully sent form to nextcloud!"),
|
||||
Err(e) => error!("There was an erroring sending form to nextcloud: {e}"),
|
||||
|
@ -188,9 +190,9 @@ mod test {
|
|||
|
||||
fn form() -> MtTeacherForm {
|
||||
MtTeacherForm {
|
||||
first_name: Text(String::from("Frodo")),
|
||||
first_name: Text(String::from("Bilbo")),
|
||||
last_name: Text(String::from("Braggins")),
|
||||
student_first_name: Text(String::from("Bilbo")),
|
||||
student_first_name: Text(String::from("Frodo")),
|
||||
student_last_name: Text(String::from("Braggins")),
|
||||
relationship: Text(String::from("Uncle")),
|
||||
positive: Text(String::from("Nimble and brave")),
|
||||
|
|
|
@ -1,175 +0,0 @@
|
|||
use actix_multipart::form::{text::Text, MultipartForm};
|
||||
use actix_web::{post, HttpResponse};
|
||||
use lettre::{message::MultiPart, Message};
|
||||
use tracing::info;
|
||||
|
||||
use crate::email::send_email;
|
||||
|
||||
#[derive(Debug, MultipartForm, Default)]
|
||||
struct ParentForm {
|
||||
#[multipart(rename = "firstname")]
|
||||
first_name: Option<Text<String>>,
|
||||
#[multipart(rename = "lastname")]
|
||||
last_name: Option<Text<String>>,
|
||||
#[multipart(rename = "studentfirstname")]
|
||||
student_first_name: Option<Text<String>>,
|
||||
#[multipart(rename = "studentlastname")]
|
||||
student_last_name: Option<Text<String>>,
|
||||
email: Option<Text<String>>,
|
||||
authority: Option<Text<String>>,
|
||||
positive: Option<Text<String>>,
|
||||
negative: Option<Text<String>>,
|
||||
#[multipart(rename = "family-relation")]
|
||||
family_relation: Option<Text<String>>,
|
||||
#[multipart(rename = "previous-trip-info")]
|
||||
previous_trip_info: Option<Text<String>>,
|
||||
#[multipart(rename = "trip-feelings")]
|
||||
trip_feelings: Option<Text<String>>,
|
||||
#[multipart(rename = "extra-info")]
|
||||
notes: Option<Text<String>>,
|
||||
}
|
||||
|
||||
#[post("/parent-form")]
|
||||
pub async fn parent_form(MultipartForm(form): MultipartForm<ParentForm>) -> HttpResponse {
|
||||
let first = form.first_name.as_ref().unwrap().0.clone();
|
||||
let last = form.last_name.as_ref().unwrap().0.clone();
|
||||
let student = format!(
|
||||
"{} {}",
|
||||
form.student_first_name.as_ref().unwrap().0.clone(),
|
||||
form.student_last_name.as_ref().unwrap().0.clone()
|
||||
);
|
||||
let email_subject = format!(
|
||||
"{} {} filled out a parent form for {}!",
|
||||
first, last, student
|
||||
);
|
||||
let email = form
|
||||
.email
|
||||
.as_ref()
|
||||
.unwrap_or(&Text(String::from("")))
|
||||
.0
|
||||
.clone();
|
||||
let authority = form
|
||||
.authority
|
||||
.as_ref()
|
||||
.unwrap_or(&Text(String::from("")))
|
||||
.0
|
||||
.clone();
|
||||
let positive = form
|
||||
.positive
|
||||
.as_ref()
|
||||
.unwrap_or(&Text(String::from("")))
|
||||
.0
|
||||
.clone();
|
||||
let negative = form
|
||||
.negative
|
||||
.as_ref()
|
||||
.unwrap_or(&Text(String::from("")))
|
||||
.0
|
||||
.clone();
|
||||
let family = form
|
||||
.family_relation
|
||||
.as_ref()
|
||||
.unwrap_or(&Text(String::from("")))
|
||||
.0
|
||||
.clone();
|
||||
let previous_trip_info = form
|
||||
.previous_trip_info
|
||||
.as_ref()
|
||||
.unwrap_or(&Text(String::from("")))
|
||||
.0
|
||||
.clone();
|
||||
let feelings = form
|
||||
.trip_feelings
|
||||
.as_ref()
|
||||
.unwrap_or(&Text(String::from("")))
|
||||
.0
|
||||
.clone();
|
||||
let notes = form
|
||||
.notes
|
||||
.as_ref()
|
||||
.unwrap_or(&Text(String::from("")))
|
||||
.0
|
||||
.clone();
|
||||
info!("{first} {last} filled out a parent form!");
|
||||
let email = markup::new! {
|
||||
@markup::doctype()
|
||||
html {
|
||||
head {
|
||||
title { @format!("{} {} filled out a Parent Reference form for {}!", first, last, student) }
|
||||
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!("Parent Reference form for {}!", student) }
|
||||
hr;
|
||||
table {
|
||||
tr {
|
||||
th { "Name" }
|
||||
td { @format!("{} {}", first, last) }
|
||||
}
|
||||
tr {
|
||||
th { "Student" }
|
||||
td { @student }
|
||||
}
|
||||
tr {
|
||||
th { "Email" }
|
||||
td { @email }
|
||||
}
|
||||
tr {
|
||||
th { "Response to authority" }
|
||||
td { @authority }
|
||||
}
|
||||
tr {
|
||||
th { "Positive Attributes" }
|
||||
td { @positive }
|
||||
}
|
||||
tr {
|
||||
th { "Negaitive Attributes" }
|
||||
td { @negative }
|
||||
}
|
||||
tr {
|
||||
th { "Relations to Family" }
|
||||
td { @family }
|
||||
}
|
||||
tr {
|
||||
th { "Previous trip info" }
|
||||
td { @previous_trip_info }
|
||||
}
|
||||
tr {
|
||||
th { "Feelings about the trip" }
|
||||
td { @feelings }
|
||||
}
|
||||
tr {
|
||||
th { "Other Notes" }
|
||||
td { @notes }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
let multi = MultiPart::alternative_plain_html(String::from("Testing"), email.to_string());
|
||||
|
||||
if let Ok(m) = Message::builder()
|
||||
.from(
|
||||
"TFC ADMIN <no-reply@mail.tfcconnection.org>"
|
||||
.parse()
|
||||
.unwrap(),
|
||||
)
|
||||
.to("Chris Cochrun <chris@tfcconnection.org>".parse().unwrap())
|
||||
.to("Ethan Rose <ethan@tfcconnection.org>".parse().unwrap())
|
||||
.subject(email_subject)
|
||||
.multipart(multi)
|
||||
{
|
||||
let _ = send_email(m);
|
||||
} else {
|
||||
info!("Email incorrect");
|
||||
}
|
||||
|
||||
HttpResponse::Ok().body("hi")
|
||||
}
|
|
@ -1,151 +0,0 @@
|
|||
use actix_multipart::form::{text::Text, MultipartForm};
|
||||
use actix_web::{post, HttpResponse};
|
||||
use lettre::{message::MultiPart, Message};
|
||||
use tracing::info;
|
||||
|
||||
use crate::email::send_email;
|
||||
|
||||
#[derive(Debug, MultipartForm, Default)]
|
||||
struct TeacherForm {
|
||||
#[multipart(rename = "firstname")]
|
||||
first_name: Option<Text<String>>,
|
||||
#[multipart(rename = "lastname")]
|
||||
last_name: Option<Text<String>>,
|
||||
#[multipart(rename = "studentfirstname")]
|
||||
student_first_name: Option<Text<String>>,
|
||||
#[multipart(rename = "studentlastname")]
|
||||
student_last_name: Option<Text<String>>,
|
||||
relationship: Option<Text<String>>,
|
||||
attitudes: Option<Text<String>>,
|
||||
positive: Option<Text<String>>,
|
||||
negative: Option<Text<String>>,
|
||||
#[multipart(rename = "team-challenges")]
|
||||
team: Option<Text<String>>,
|
||||
#[multipart(rename = "extra-info")]
|
||||
notes: Option<Text<String>>,
|
||||
}
|
||||
|
||||
#[post("/teacher-form")]
|
||||
pub async fn teacher_form(MultipartForm(form): MultipartForm<TeacherForm>) -> HttpResponse {
|
||||
let first = form.first_name.as_ref().unwrap().0.clone();
|
||||
let last = form.last_name.as_ref().unwrap().0.clone();
|
||||
let student = format!(
|
||||
"{} {}",
|
||||
form.student_first_name.as_ref().unwrap().0.clone(),
|
||||
form.student_last_name.as_ref().unwrap().0.clone()
|
||||
);
|
||||
let email_subject = format!(
|
||||
"{} {} filled out a teacher form for {}!",
|
||||
first, last, student
|
||||
);
|
||||
let relationship = form
|
||||
.relationship
|
||||
.as_ref()
|
||||
.unwrap_or(&Text(String::from("")))
|
||||
.0
|
||||
.clone();
|
||||
let attitudes = form
|
||||
.attitudes
|
||||
.as_ref()
|
||||
.unwrap_or(&Text(String::from("")))
|
||||
.0
|
||||
.clone();
|
||||
let positive = form
|
||||
.positive
|
||||
.as_ref()
|
||||
.unwrap_or(&Text(String::from("")))
|
||||
.0
|
||||
.clone();
|
||||
let negative = form
|
||||
.negative
|
||||
.as_ref()
|
||||
.unwrap_or(&Text(String::from("")))
|
||||
.0
|
||||
.clone();
|
||||
let team = form
|
||||
.team
|
||||
.as_ref()
|
||||
.unwrap_or(&Text(String::from("")))
|
||||
.0
|
||||
.clone();
|
||||
let notes = form
|
||||
.notes
|
||||
.as_ref()
|
||||
.unwrap_or(&Text(String::from("")))
|
||||
.0
|
||||
.clone();
|
||||
info!("{first} {last} filled out a teacher form!");
|
||||
let email = markup::new! {
|
||||
@markup::doctype()
|
||||
html {
|
||||
head {
|
||||
title { @format!("{} {} filled out a teacher form for {}!", first, last, student) }
|
||||
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!("Teacher Reference form for {}!", student) }
|
||||
hr;
|
||||
table {
|
||||
tr {
|
||||
th { "Name" }
|
||||
td { @format!("{} {}", first, last) }
|
||||
}
|
||||
tr {
|
||||
th { "Student" }
|
||||
td { @student }
|
||||
}
|
||||
tr {
|
||||
th { "Relationship to teen" }
|
||||
td { @relationship }
|
||||
}
|
||||
tr {
|
||||
th { "Attitude in classroom" }
|
||||
td { @attitudes }
|
||||
}
|
||||
tr {
|
||||
th { "Positive Attributes" }
|
||||
td { @positive }
|
||||
}
|
||||
tr {
|
||||
th { "Negaitive Attributes" }
|
||||
td { @negative }
|
||||
}
|
||||
tr {
|
||||
th { "Teamwork" }
|
||||
td { @team }
|
||||
}
|
||||
tr {
|
||||
th { "Other Notes" }
|
||||
td { @notes }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
let multi = MultiPart::alternative_plain_html(String::from("Testing"), email.to_string());
|
||||
|
||||
if let Ok(m) = Message::builder()
|
||||
.from(
|
||||
"TFC ADMIN <no-reply@mail.tfcconnection.org>"
|
||||
.parse()
|
||||
.unwrap(),
|
||||
)
|
||||
.to("Chris Cochrun <chris@tfcconnection.org>".parse().unwrap())
|
||||
.to("Ethan Rose <ethan@tfcconnection.org>".parse().unwrap())
|
||||
.subject(email_subject)
|
||||
.multipart(multi)
|
||||
{
|
||||
let _ = send_email(m);
|
||||
} else {
|
||||
info!("Email incorrect");
|
||||
}
|
||||
|
||||
HttpResponse::Ok().body("hi")
|
||||
}
|
13
src/main.rs
13
src/main.rs
|
@ -7,12 +7,13 @@ use actix_web::body::MessageBody;
|
|||
use actix_web::dev::{ServiceRequest, ServiceResponse};
|
||||
use actix_web::{web, App, Error, 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 api::{
|
||||
mt_church_form::mt_church_form, mt_parent_form::mt_parent_form,
|
||||
mt_teacher_form::mt_teacher_form,
|
||||
};
|
||||
use color_eyre::eyre::Context;
|
||||
use color_eyre::Result;
|
||||
use sqlx::{Connection, SqliteConnection};
|
||||
|
@ -89,9 +90,9 @@ async fn main() -> std::io::Result<()> {
|
|||
.app_data(TempFileConfig::default().directory("./tmp"))
|
||||
.service(mt_form)
|
||||
.service(health_form)
|
||||
.service(parent_form)
|
||||
.service(teacher_form)
|
||||
.service(church_form)
|
||||
.service(mt_parent_form)
|
||||
.service(mt_teacher_form)
|
||||
.service(mt_church_form)
|
||||
.service(local_form)
|
||||
.service(camp_form)
|
||||
.service(Files::new("/", "./public").index_file("index.html"))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue