health_form is ready for unit tests

This commit is contained in:
Chris Cochrun 2024-12-12 15:09:10 -06:00
parent cc1b57a3a0
commit 39b83d4e6d
2 changed files with 309 additions and 649 deletions

View file

@ -2,266 +2,121 @@ use std::{collections::HashMap, fs};
use actix_multipart::form::{tempfile::TempFile, text::Text, MultipartForm}; use actix_multipart::form::{tempfile::TempFile, text::Text, MultipartForm};
use actix_web::{post, HttpResponse}; use actix_web::{post, HttpResponse};
use color_eyre::{eyre::eyre, Result};
use lettre::{ use lettre::{
message::{header::ContentType, Attachment, MultiPart, SinglePart}, message::{header::ContentType, Attachment, MultiPart, SinglePart},
Message, Message,
}; };
use maud::{html, DOCTYPE}; use maud::{html, Markup, DOCTYPE};
use reqwest::{Client, Error}; use reqwest::Client;
use tracing::info; use tracing::{error, info};
use crate::email::send_email; use crate::email::send_email;
#[derive(Debug, MultipartForm, Default)] #[derive(Debug, MultipartForm)]
struct HealthForm { struct HealthForm {
#[multipart(rename = "first-name")] #[multipart(rename = "first-name")]
first_name: Option<Text<String>>, first_name: Text<String>,
#[multipart(rename = "last-name")] #[multipart(rename = "last-name")]
last_name: Option<Text<String>>, last_name: Text<String>,
#[multipart(rename = "parent-first-name")] #[multipart(rename = "parent-first-name")]
parent_first_name: Option<Text<String>>, parent_first_name: Text<String>,
#[multipart(rename = "parent-last-name")] #[multipart(rename = "parent-last-name")]
parent_last_name: Option<Text<String>>, parent_last_name: Text<String>,
#[multipart(rename = "birth-date")] #[multipart(rename = "birth-date")]
birthdate: Option<Text<String>>, birthdate: Text<String>,
street: Option<Text<String>>, street: Text<String>,
city: Option<Text<String>>, city: Text<String>,
state: Option<Text<String>>, state: Text<String>,
zip: Option<Text<String>>, zip: Text<String>,
#[multipart(rename = "cell-phone")] #[multipart(rename = "cell-phone")]
parent_cellphone: Option<Text<String>>, parent_cellphone: Text<String>,
#[multipart(rename = "home-phone")] #[multipart(rename = "home-phone")]
homephone: Option<Text<String>>, homephone: Text<String>,
#[multipart(rename = "additional-emergency-contact")] #[multipart(rename = "additional-emergency-contact")]
contact: Option<Text<String>>, contact: Text<String>,
#[multipart(rename = "addtional-emergency-contact-phone")] #[multipart(rename = "addtional-emergency-contact-phone")]
contact_phone: Option<Text<String>>, contact_phone: Text<String>,
#[multipart(rename = "doctor-name")] #[multipart(rename = "doctor-name")]
doctorname: Option<Text<String>>, doctorname: Text<String>,
#[multipart(rename = "doctor-city")] #[multipart(rename = "doctor-city")]
doctorcity: Option<Text<String>>, doctorcity: Text<String>,
#[multipart(rename = "doctor-phone")] #[multipart(rename = "doctor-phone")]
doctorphone: Option<Text<String>>, doctorphone: Text<String>,
#[multipart(rename = "medical-coverage")] #[multipart(rename = "medical-coverage")]
medical: Option<Text<String>>, medical: Text<String>,
#[multipart(rename = "insurance-name")] #[multipart(rename = "insurance-name")]
insurance: Option<Text<String>>, insurance: Text<String>,
#[multipart(rename = "policy-number")] #[multipart(rename = "policy-number")]
policy_number: Option<Text<String>>, policy_number: Text<String>,
allergies: Option<Text<String>>, allergies: Text<String>,
#[multipart(rename = "allergies-other")] #[multipart(rename = "allergies-other")]
allergies_other: Option<Text<String>>, allergies_other: Text<String>,
#[multipart(rename = "specific-allergies")] #[multipart(rename = "specific-allergies")]
specific_allergies: Option<Text<String>>, specific_allergies: Text<String>,
#[multipart(rename = "allergic-treatment")] #[multipart(rename = "allergic-treatment")]
treatment: Option<Text<String>>, treatment: Text<String>,
conditions: Option<Text<String>>, conditions: Text<String>,
#[multipart(rename = "tetanus-shot")] #[multipart(rename = "tetanus-shot")]
tetanus: Option<Text<String>>, tetanus: Text<String>,
#[multipart(rename = "swimming-ability")] #[multipart(rename = "swimming-ability")]
swimming: Option<Text<String>>, swimming: Text<String>,
#[multipart(rename = "medication-schedule")] #[multipart(rename = "medication-schedule")]
medication: Option<Text<String>>, medication: Text<String>,
#[multipart(rename = "other-notes")] #[multipart(rename = "other-notes")]
notes: Option<Text<String>>, notes: Text<String>,
agreement: Option<Text<String>>, agreement: Text<String>,
#[multipart(rename = "image")] #[multipart(rename = "image")]
file: Option<TempFile>, file: Option<TempFile>,
registration: Option<Text<String>>, registration: Text<String>,
} }
#[post("/health-form")] impl From<&HealthForm> for HashMap<i32, String> {
pub async fn health_form(MultipartForm(form): MultipartForm<HealthForm>) -> HttpResponse { fn from(form: &HealthForm) -> Self {
let first = form let mut map = HashMap::new();
.first_name map.insert(37, format!("{} {}", form.first_name.0, form.last_name.0));
.as_ref() map.insert(
.unwrap_or(&Text(String::from(""))) 38,
.0 format!("{} {}", form.parent_first_name.0, form.parent_last_name.0),
.clone();
let last = form
.last_name
.as_ref()
.unwrap_or(&Text(String::from("")))
.0
.clone();
let full_name = format!("{} {}", first, last);
let registration = form
.registration
.as_ref()
.unwrap_or(&Text(String::from("")))
.0
.clone();
let email_subject = format!("{} {} filled out a health form!", first, last);
let filename_noext = format!("{}_{}", first, last);
let parent = format!(
"{} {}",
form.parent_first_name
.as_ref()
.unwrap_or(&Text(String::from("")))
.0
.clone(),
form.parent_last_name
.as_ref()
.unwrap_or(&Text(String::from("")))
.0
.clone()
); );
let birthdate = form map.insert(39, form.birthdate.0.clone());
.birthdate map.insert(40, form.street.0.clone());
.as_ref() map.insert(41, form.city.0.clone());
.unwrap_or(&Text(String::from(""))) map.insert(42, form.state.0.clone());
.0 map.insert(43, form.zip.0.clone());
.clone(); map.insert(44, form.parent_cellphone.0.clone());
let street = form map.insert(45, form.homephone.0.clone());
.street map.insert(46, format!("{} {}", form.contact.0, form.contact_phone.0));
.as_ref() map.insert(47, form.doctorname.0.clone());
.unwrap_or(&Text(String::from(""))) map.insert(48, form.doctorcity.0.clone());
.0 map.insert(49, form.doctorphone.0.clone());
.clone(); map.insert(50, form.medical.0.clone());
let city = form map.insert(51, form.insurance.0.clone());
.city map.insert(52, form.policy_number.0.clone());
.as_ref() map.insert(54, form.agreement.0.clone());
.unwrap_or(&Text(String::from(""))) map.insert(
.0 55,
.clone(); format!("{} \n {}", form.allergies.0, form.allergies_other.0),
let state = form );
.state map.insert(56, form.specific_allergies.0.clone());
.as_ref() map.insert(57, form.treatment.0.clone());
.unwrap_or(&Text(String::from(""))) map.insert(58, form.conditions.0.clone());
.0 map.insert(59, form.tetanus.0.clone());
.clone(); map.insert(60, form.medication.0.clone());
let zip = form map.insert(61, form.notes.0.clone());
.zip map.insert(62, form.swimming.0.clone());
.as_ref() map
.unwrap_or(&Text(String::from(""))) }
.0 }
.clone();
let parent_cellphone = form impl HealthForm {
.parent_cellphone async fn build_email(&self) -> Markup {
.as_ref() html! {
.unwrap_or(&Text(String::from("")))
.0
.clone();
let homephone = form
.homephone
.as_ref()
.unwrap_or(&Text(String::from("")))
.0
.clone();
let contact = form
.contact
.as_ref()
.unwrap_or(&Text(String::from("")))
.0
.clone();
let contact_phone = form
.contact_phone
.as_ref()
.unwrap_or(&Text(String::from("")))
.0
.clone();
let doctorname = form
.doctorname
.as_ref()
.unwrap_or(&Text(String::from("")))
.0
.clone();
let doctorcity = form
.doctorcity
.as_ref()
.unwrap_or(&Text(String::from("")))
.0
.clone();
let doctorphone = form
.doctorphone
.as_ref()
.unwrap_or(&Text(String::from("")))
.0
.clone();
let medical = form
.medical
.as_ref()
.unwrap_or(&Text(String::from("")))
.0
.clone();
let insurance = form
.insurance
.as_ref()
.unwrap_or(&Text(String::from("")))
.0
.clone();
let policy_number = form
.policy_number
.as_ref()
.unwrap_or(&Text(String::from("")))
.0
.clone();
let agreement = form
.agreement
.as_ref()
.unwrap_or(&Text(String::from("")))
.0
.clone();
let allergies = form
.allergies
.as_ref()
.unwrap_or(&Text(String::from("")))
.0
.clone();
let allergies_other = form
.allergies_other
.as_ref()
.unwrap_or(&Text(String::from("")))
.0
.clone();
let specific_allergies = form
.specific_allergies
.as_ref()
.unwrap_or(&Text(String::from("")))
.0
.clone();
let treatment = form
.treatment
.as_ref()
.unwrap_or(&Text(String::from("")))
.0
.clone();
let conditions = form
.conditions
.as_ref()
.unwrap_or(&Text(String::from("")))
.0
.clone();
let tetanus = form
.tetanus
.as_ref()
.unwrap_or(&Text(String::from("")))
.0
.clone();
let swimming = form
.swimming
.as_ref()
.unwrap_or(&Text(String::from("")))
.0
.clone();
let medication = form
.medication
.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 health form!");
let email = html! {
(DOCTYPE) (DOCTYPE)
meta charset="utf-8";
html { html {
head { head {
title { (first) " " (last) " filled out a health form!" } title { (self.first_name.0) " " (self.last_name.0) " filled out a health form!" }
style { style {
"table { border-collapse: collapse; width: 100% }" "table { border-collapse: collapse; width: 100% }"
"td, th { padding: 8px }" "td, th { padding: 8px }"
@ -272,161 +127,202 @@ pub async fn health_form(MultipartForm(form): MultipartForm<HealthForm>) -> Http
} }
} }
body { body {
h1 { "Health form for " (first) " " (last) "!" } h1 { "Health form for " (self.first_name.0) " " (self.last_name.0) "!" }
hr; hr;
table { table {
tr { tr {
th { "Name" } th { "Name" }
td { (first) " " (last) } td { (self.first_name.0) " " (self.last_name.0) }
} }
tr { tr {
th { "Parent" } th { "Parent" }
td { (parent) } td { (self.parent_first_name.0) " " (self.parent_last_name.0) }
} }
tr { tr {
th { "Birthdate" } th { "Birthdate" }
td { (birthdate) } td { (self.birthdate.0) }
} }
tr { tr {
th { "Street" } th { "Street" }
td { (street) } td { (self.street.0) }
} }
tr { tr {
th { "City" } th { "City" }
td { (city) } td { (self.city.0) }
} }
tr { tr {
th { "State" } th { "State" }
td { (state) } td { (self.state.0) }
} }
tr { tr {
th { "Zip" } th { "Zip" }
td { (zip) } td { (self.zip.0) }
} }
tr { tr {
th { "Phone" } th { "Parent Cell Phone" }
td { (parent_cellphone) } td { (self.parent_cellphone.0) }
} }
tr { tr {
th { "Home Phone" } th { "Homephone" }
td { (homephone) } td { (self.homephone.0) }
} }
tr { tr {
th { "Additional Emergency Contact" } th { "Additional Emergency Contact" }
td { (contact) } td { (self.contact.0) }
} }
tr { tr {
th { "Contact Phone" } th { "Emegency Contact Phone" }
td { (contact_phone) } td { (self.contact_phone.0) }
} }
tr { tr {
th { "Doctor" } th { "Doctor" }
td { (doctorname) } td { (self.doctorname.0) }
} }
tr { tr {
th { "Doctor City" } th { "Doctor City" }
td { (doctorcity) } td { (self.doctorcity.0) }
} }
tr { tr {
th { "Doctor Phone" } th { "Doctor Phone" }
td { (doctorphone) } td { (self.doctorphone.0) }
} }
tr { tr {
th { "Medical Coverage" } th { "Medical Coverage" }
td { (medical) } td { (self.medical.0) }
} }
tr { tr {
th { "Insurance Provider" } th { "Insurance Provider" }
td { (insurance) } td { (self.insurance.0) }
} }
tr { tr {
th { "Policy Number" } th { "Policy Number" }
td { (policy_number) } td { (self.policy_number.0) }
} }
tr { tr {
th { "Allergies" } th { "Allergies" }
td { (allergies) } td { (self.allergies.0)
"\n\n"
(self.allergies_other.0)
} }
tr {
th { "Other Allergies" }
td { (allergies_other) }
} }
tr { tr {
th { "Specific Allergies" } th { "Specific Allergies" }
td { (specific_allergies) } td { (self.specific_allergies.0) }
} }
tr { tr {
th { "Treatments" } th { "Allergic Treatments" }
td { (treatment) } td { (self.treatment.0) }
} }
tr { tr {
th { "Physical or mental conditions" } th { "Conditions" }
td { (conditions) } td { (self.conditions.0) }
} }
tr { tr {
th { "Last tetanus shot" } th { "Date of last Tetanus Shot" }
td { (tetanus) } td { (self.tetanus.0) }
} }
tr { tr {
th { "Swimming Ability" } th { "Swimming Ability" }
td { (swimming) } td { (self.swimming.0) }
} }
tr { tr {
th { "Medication Schedule" } th { "Medication Schedule" }
td { (medication) } td { (self.medication.0) }
} }
tr { tr {
th { "Other Relevant Info" } th { "Other Notes" }
td { (notes) } td { (self.notes.0) }
} }
tr { tr {
th { "Final Agreement" } th { "Final Agreement" }
td { (agreement) } td { (self.agreement.0) }
}
tr {
th { "Registration" }
td { (self.registration.0) }
}
} }
} }
} }
} }
};
let mut path: Option<String> = Some(String::from(""));
let mut file_exists = false;
let mut filename = String::from("");
info!("Does the file exist? {:?}", file_exists);
match store_health_form(&form).await {
Ok(_) => info!("Successfully posted the health form in nextcloud tables"),
Err(e) => log::error!("Error posting health form to nextcloud tables: {:?}", e),
} }
if let Some(f) = form.file { async fn store_form(&self) -> Result<()> {
if let Some(file) = f.file_name { let client = Client::new();
if let Some(ext) = file.rsplit('.').next() { let map = HashMap::from(self);
filename = format!("{}.{}", filename_noext, ext); let mut json = HashMap::new();
path = Some(format!("./tmp/{}.{}", filename_noext, ext)); json.insert("data", map);
let link = r#"https://staff.tfcconnection.org/apps/tables/#/table/4/row/757"#;
let res = client
.post("https://staff.tfcconnection.org/ocs/v2.php/apps/tables/api/2/tables/4/rows")
.basic_auth("chris", Some("2VHeGxeC^Zf9KqFK^G@Pt!zu2q^6@b"))
.header("OCS-APIRequest", "true")
.header("Content-Type", "application/json")
.json(&json)
.send()
.await?;
if res.status().is_success() {
let res = res.text().await.unwrap();
Ok(())
} else { } else {
path = Some(format!("./tmp/{}", file)); Err(eyre!(
"Problem in storing data: {:?}",
res.error_for_status()
))
} }
// let path = format!("./tmp/{}", file); }
info!("saving to {}", path.clone().unwrap());
match f.file.persist(path.clone().unwrap()) { fn get_temp_file(&mut self) -> Option<(String, String)> {
let first = self.first_name.clone();
let last = self.last_name.clone();
let filename_noext = format!("{}_{}", first, last);
let file_name = if let Some(file) = self.file.as_ref() {
file.file_name.to_owned()
} else {
return None;
};
let filename;
let path = if let Some(file_name) = file_name {
if let Some(ext) = file_name.rsplit('.').next() {
filename = format!("{}.{}", filename_noext, ext);
format!("./tmp/{}.{}", filename_noext, ext)
} else {
filename = String::default();
format!("./tmp/{}", file_name)
}
} else {
filename = String::default();
String::default()
};
let file = self.file.take();
match file.unwrap().file.persist(path.clone()) {
Ok(f) => { Ok(f) => {
info!( if f.metadata().unwrap().len() <= 0 {
"Hey! We got a file! {:?}", return None;
f.metadata().expect("Something bad happened mate")
);
if f.metadata().unwrap().len() > 0 {
file_exists = true;
} }
info!(?f, "File saved successfully");
Some((filename, path))
} }
Err(e) => info!("{:?}: Probably a missing image", e), Err(e) => {
error!("{:?}: Probably a missing image", e);
None
} }
} }
} }
let multi = if file_exists { async fn send_email(&mut self) -> Result<()> {
let filebody = fs::read(path.clone().unwrap_or_default()); 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 email = self.build_email().await;
let temp_file = self.get_temp_file();
let multi = if let Some((file, path)) = temp_file {
let filebody = fs::read(path);
let content_type = ContentType::parse("image/jpg").unwrap(); let content_type = ContentType::parse("image/jpg").unwrap();
let attachment = Attachment::new(filename).body(filebody.unwrap(), content_type); let attachment = Attachment::new(file).body(filebody.unwrap(), content_type);
// info!("The attachment is: {:?}", attachment.headers()); // info!(?attachment);
MultiPart::mixed() MultiPart::mixed()
.singlepart(SinglePart::html(email.into_string())) .singlepart(SinglePart::html(email.into_string()))
.singlepart(attachment) .singlepart(attachment)
@ -434,8 +330,6 @@ pub async fn health_form(MultipartForm(form): MultipartForm<HealthForm>) -> Http
MultiPart::alternative_plain_html(String::from("Testing"), email.into_string()) MultiPart::alternative_plain_html(String::from("Testing"), email.into_string())
}; };
// info!("{:?}", multi);
if let Ok(m) = Message::builder() if let Ok(m) = Message::builder()
.from( .from(
"TFC ADMIN <no-reply@mail.tfcconnection.org>" "TFC ADMIN <no-reply@mail.tfcconnection.org>"
@ -443,16 +337,25 @@ pub async fn health_form(MultipartForm(form): MultipartForm<HealthForm>) -> Http
.unwrap(), .unwrap(),
) )
.to("Chris Cochrun <chris@tfcconnection.org>".parse().unwrap()) .to("Chris Cochrun <chris@tfcconnection.org>".parse().unwrap())
.to("Ethan Rose <ethan@tfcconnection.org>".parse().unwrap())
.subject(email_subject) .subject(email_subject)
.multipart(multi) .multipart(multi)
{ {
let _ = send_email(m); crate::email::send_email(m).await
} else { } else {
info!("Email incorrect"); Err(eyre!("Email incorrect"))
}
}
}
#[post("/health-form")]
pub async fn health_form(MultipartForm(mut form): MultipartForm<HealthForm>) -> HttpResponse {
match form.send_email().await {
Ok(_) => info!("Successfully sent email health form"),
Err(e) => error!("There was an error sending email: {e}"),
} }
match registration.as_str() { let full_name = format!("{} {}", form.first_name.0, form.last_name.0);
match form.registration.0.as_str() {
"now" => { "now" => {
info!("Sending them to pay for registration now"); info!("Sending them to pay for registration now");
HttpResponse::Ok() HttpResponse::Ok()
@ -492,7 +395,7 @@ pub async fn health_form(MultipartForm(form): MultipartForm<HealthForm>) -> Http
_ => { _ => {
log::error!( log::error!(
"Got registration error possibly. Here is what the registration was: {}", "Got registration error possibly. Here is what the registration was: {}",
registration.as_str() form.registration.0.as_str()
); );
let html = html! { let html = html! {
div class="mt-8" { div class="mt-8" {
@ -511,241 +414,3 @@ pub async fn health_form(MultipartForm(form): MultipartForm<HealthForm>) -> Http
} }
// HttpResponse::Ok().body("hi") // HttpResponse::Ok().body("hi")
} }
async fn store_health_form(form: &HealthForm) -> Result<(), Error> {
let request = Client::new();
let mut map = HashMap::new();
map.insert(
37,
format!(
"{} {}",
form.first_name
.as_ref()
.unwrap_or(&Text(String::new()))
.0
.clone(),
form.last_name
.as_ref()
.unwrap_or(&Text(String::new()))
.0
.clone()
),
);
map.insert(
38,
format!(
"{} {}",
form.parent_first_name
.as_ref()
.unwrap_or(&Text(String::new()))
.0
.clone(),
form.parent_last_name
.as_ref()
.unwrap_or(&Text(String::new()))
.0
.clone()
),
);
map.insert(
39,
form.birthdate
.as_ref()
.unwrap_or(&Text(String::new()))
.0
.clone(),
);
map.insert(
40,
form.street
.as_ref()
.unwrap_or(&Text(String::new()))
.0
.clone(),
);
map.insert(
41,
form.city.as_ref().unwrap_or(&Text(String::new())).0.clone(),
);
map.insert(
42,
form.state
.as_ref()
.unwrap_or(&Text(String::new()))
.0
.clone(),
);
map.insert(
43,
form.zip.as_ref().unwrap_or(&Text(String::new())).0.clone(),
);
map.insert(
44,
form.parent_cellphone
.as_ref()
.unwrap_or(&Text(String::new()))
.0
.clone(),
);
map.insert(
45,
form.homephone
.as_ref()
.unwrap_or(&Text(String::new()))
.0
.clone(),
);
map.insert(
46,
format!(
"{} {}",
form.contact
.as_ref()
.unwrap_or(&Text(String::new()))
.0
.clone(),
form.contact_phone
.as_ref()
.unwrap_or(&Text(String::new()))
.0
.clone(),
),
);
map.insert(
47,
form.doctorname
.as_ref()
.unwrap_or(&Text(String::new()))
.0
.clone(),
);
map.insert(
48,
form.doctorcity
.as_ref()
.unwrap_or(&Text(String::new()))
.0
.clone(),
);
map.insert(
49,
form.doctorphone
.as_ref()
.unwrap_or(&Text(String::new()))
.0
.clone(),
);
map.insert(
50,
form.medical
.as_ref()
.unwrap_or(&Text(String::new()))
.0
.clone(),
);
map.insert(
51,
form.insurance
.as_ref()
.unwrap_or(&Text(String::new()))
.0
.clone(),
);
map.insert(
52,
form.policy_number
.as_ref()
.unwrap_or(&Text(String::new()))
.0
.clone(),
);
map.insert(
54,
form.agreement
.as_ref()
.unwrap_or(&Text(String::new()))
.0
.clone(),
);
map.insert(
55,
format!(
"{}{}",
form.allergies
.as_ref()
.unwrap_or(&Text(String::new()))
.0
.clone(),
form.allergies_other
.as_ref()
.unwrap_or(&Text(String::new()))
.0
.clone(),
),
);
map.insert(
56,
form.specific_allergies
.as_ref()
.unwrap_or(&Text(String::new()))
.0
.clone(),
);
map.insert(
57,
form.treatment
.as_ref()
.unwrap_or(&Text(String::new()))
.0
.clone(),
);
map.insert(
58,
form.conditions
.as_ref()
.unwrap_or(&Text(String::new()))
.0
.clone(),
);
map.insert(
59,
form.tetanus
.as_ref()
.unwrap_or(&Text(String::new()))
.0
.clone(),
);
map.insert(
62,
form.swimming
.as_ref()
.unwrap_or(&Text(String::new()))
.0
.clone(),
);
map.insert(
60,
form.medication
.as_ref()
.unwrap_or(&Text(String::new()))
.0
.clone(),
);
map.insert(
61,
form.notes
.as_ref()
.unwrap_or(&Text(String::new()))
.0
.clone(),
);
let mut json = HashMap::new();
json.insert("data", map);
request
.post("https://staff.tfcconnection.org/apps/tables/api/1/tables/4/rows")
.basic_auth("chris", Some("2VHeGxeC^Zf9KqFK^G@Pt!zu2q^6@b"))
.json(&json)
.send()
.await?;
Ok(())
}

View file

@ -1,19 +1,14 @@
use std::{ use std::{collections::HashMap, fs};
collections::{BTreeMap, HashMap},
fs,
};
use actix_multipart::form::{tempfile::TempFile, text::Text, MultipartForm}; use actix_multipart::form::{tempfile::TempFile, text::Text, MultipartForm};
use actix_web::{post, web, HttpResponse}; use actix_web::{post, HttpResponse};
use color_eyre::{eyre::eyre, Result}; use color_eyre::{eyre::eyre, Result};
use lettre::{ use lettre::{
message::{header::ContentType, Attachment, MultiPart, SinglePart}, message::{header::ContentType, Attachment, MultiPart, SinglePart},
Message, Message,
}; };
use maud::{html, Markup, PreEscaped, DOCTYPE}; use maud::{html, Markup, DOCTYPE};
use reqwest::Client; use reqwest::Client;
use serde_json::json;
use sqlx::SqliteConnection;
use tracing::{error, info}; use tracing::{error, info};
#[derive(Debug, MultipartForm)] #[derive(Debug, MultipartForm)]