all reference forms and health apis are done
This commit is contained in:
parent
65f186fadc
commit
3f8b9cb5d8
10 changed files with 630 additions and 29 deletions
176
src/api/teacher_form.rs
Normal file
176
src/api/teacher_form.rs
Normal file
|
@ -0,0 +1,176 @@
|
|||
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 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 {
|
||||
0: String::from(""),
|
||||
})
|
||||
.0
|
||||
.clone();
|
||||
let attitudes = form
|
||||
.attitudes
|
||||
.as_ref()
|
||||
.unwrap_or(&Text {
|
||||
0: String::from(""),
|
||||
})
|
||||
.0
|
||||
.clone();
|
||||
let positive = form
|
||||
.positive
|
||||
.as_ref()
|
||||
.unwrap_or(&Text {
|
||||
0: String::from(""),
|
||||
})
|
||||
.0
|
||||
.clone();
|
||||
let negative = form
|
||||
.negative
|
||||
.as_ref()
|
||||
.unwrap_or(&Text {
|
||||
0: String::from(""),
|
||||
})
|
||||
.0
|
||||
.clone();
|
||||
let team = form
|
||||
.team
|
||||
.as_ref()
|
||||
.unwrap_or(&Text {
|
||||
0: String::from(""),
|
||||
})
|
||||
.0
|
||||
.clone();
|
||||
let notes = form
|
||||
.notes
|
||||
.as_ref()
|
||||
.unwrap_or(&Text {
|
||||
0: String::from(""),
|
||||
})
|
||||
.0
|
||||
.clone();
|
||||
log::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 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("hi")
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue