Compare commits

...

10 commits

Author SHA1 Message Date
Chris Cochrun f6cd1e4f18 hopefully making things more reproducable 2025-03-26 13:37:54 -05:00
Chris Cochrun 7ba9d476cc growl 2025-03-26 13:27:32 -05:00
Chris Cochrun 9633ba6c92 fixxy plz 2025-03-26 13:20:04 -05:00
Chris Cochrun 090f19481c grrrrrr 2025-03-26 12:37:17 -05:00
Chris Cochrun 4f417e4470 grrrrrrrrrrrr 2025-03-26 12:34:49 -05:00
Chris Cochrun 5c398601a9 idk 2025-03-26 12:31:24 -05:00
Chris Cochrun c850680def fixing naersk build 2025-03-26 12:18:20 -05:00
Chris Cochrun 700db824f0 using naersk to build 2025-03-26 12:14:43 -05:00
Chris Cochrun fdb6021683 making the camp form function goodly 2025-03-26 11:55:59 -05:00
Chris Cochrun b2d96c13a1 making tests work with emails 2025-03-25 15:23:40 -05:00
12 changed files with 350 additions and 372 deletions

View file

@ -32,3 +32,9 @@ tracing-actix-web = "0.7.14"
color-eyre = "0.6.3" color-eyre = "0.6.3"
pretty_assertions = "1.4.1" pretty_assertions = "1.4.1"
sqlx = { version = "0.8.2", features = ["sqlite"] } sqlx = { version = "0.8.2", features = ["sqlite"] }
[profile.dev]
opt-level = 0
[profile.release]
opt-level = 3

View file

@ -5498,10 +5498,6 @@ pre {
flex-basis: 75%; flex-basis: 75%;
} }
.md\:basis-1\/2 {
flex-basis: 50%;
}
.md\:basis-1\/4 { .md\:basis-1\/4 {
flex-basis: 25%; flex-basis: 25%;
} }

View file

@ -50,7 +50,37 @@
"type": "github" "type": "github"
} }
}, },
"naersk": {
"inputs": {
"nixpkgs": "nixpkgs"
},
"locked": {
"lastModified": 1742901344,
"narHash": "sha256-o9dXcpfXpBm6+/SRqcQW0GzRkJymwyEAu5UD5LMDd3s=",
"owner": "nix-community",
"repo": "naersk",
"rev": "a75c0584b0d69de943babc899530e9c70c642b42",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "naersk",
"type": "github"
}
},
"nixpkgs": { "nixpkgs": {
"locked": {
"lastModified": 0,
"narHash": "sha256-Q6pMP4a9ed636qilcYX8XUguvKl/0/LGXhHcRI91p0U=",
"path": "/nix/store/xq5rfjj1z2r8yx338arajg5vwsxh1fri-source",
"type": "path"
},
"original": {
"id": "nixpkgs",
"type": "indirect"
}
},
"nixpkgs_2": {
"locked": { "locked": {
"lastModified": 1720031269, "lastModified": 1720031269,
"narHash": "sha256-rwz8NJZV+387rnWpTYcXaRNvzUSnnF9aHONoJIYmiUQ=", "narHash": "sha256-rwz8NJZV+387rnWpTYcXaRNvzUSnnF9aHONoJIYmiUQ=",
@ -66,7 +96,7 @@
"type": "github" "type": "github"
} }
}, },
"nixpkgs_2": { "nixpkgs_3": {
"locked": { "locked": {
"lastModified": 1718428119, "lastModified": 1718428119,
"narHash": "sha256-WdWDpNaq6u1IPtxtYHHWpl5BmabtpmLnMAx0RdJ/vo8=", "narHash": "sha256-WdWDpNaq6u1IPtxtYHHWpl5BmabtpmLnMAx0RdJ/vo8=",
@ -87,13 +117,14 @@
"blowfish": "blowfish", "blowfish": "blowfish",
"cl-nix-lite": "cl-nix-lite", "cl-nix-lite": "cl-nix-lite",
"flake-utils": "flake-utils", "flake-utils": "flake-utils",
"nixpkgs": "nixpkgs", "naersk": "naersk",
"nixpkgs": "nixpkgs_2",
"rust-overlay": "rust-overlay" "rust-overlay": "rust-overlay"
} }
}, },
"rust-overlay": { "rust-overlay": {
"inputs": { "inputs": {
"nixpkgs": "nixpkgs_2" "nixpkgs": "nixpkgs_3"
}, },
"locked": { "locked": {
"lastModified": 1720145907, "lastModified": 1720145907,

View file

@ -6,6 +6,7 @@
flake-utils.url = "github:numtide/flake-utils"; flake-utils.url = "github:numtide/flake-utils";
cl-nix-lite.url = "github:hraban/cl-nix-lite"; cl-nix-lite.url = "github:hraban/cl-nix-lite";
rust-overlay.url = "github:oxalica/rust-overlay"; rust-overlay.url = "github:oxalica/rust-overlay";
naersk.url = "github:nix-community/naersk";
blowfish = { blowfish = {
url = "github:nunocoracao/blowfish?rev=b6744efbf2d76023084498552a916b49d5a764d8"; url = "github:nunocoracao/blowfish?rev=b6744efbf2d76023084498552a916b49d5a764d8";
flake = false; flake = false;
@ -19,33 +20,35 @@
pkgs = nixpkgs.legacyPackages.${system}; pkgs = nixpkgs.legacyPackages.${system};
src = ./.; src = ./.;
sbcl' = pkgs.sbcl.withPackages (ps: with ps; [ naersk' = pkgs.callPackage naersk {};
hunchentoot
dexador # sbcl' = pkgs.sbcl.withPackages (ps: with ps; [
jzon # hunchentoot
serapeum # dexador
deploy # jzon
spinneret # serapeum
lass # deploy
cl-smtp # spinneret
log4cl # lass
cl_plus_ssl # cl-smtp
fiveam # log4cl
slite # cl_plus_ssl
clack # fiveam
jingle # slite
lack-middleware-static # clack
lack-middleware-session # jingle
lack-middleware-mount # lack-middleware-static
lack # lack-middleware-session
lack-util # lack-middleware-mount
lack-component # lack
woo # lack-util
ningle # lack-component
pkgs.openssl # woo
pkgs.openssl.out # ningle
pkgs.openssl.dev # pkgs.openssl
]); # pkgs.openssl.out
# pkgs.openssl.dev
# ]);
nbi = with pkgs; [ nbi = with pkgs; [
gcc gcc
stdenv stdenv
@ -63,12 +66,7 @@
hugo hugo
go go
nodejs nodejs
sbcl' # sbcl'
guile
guile-fibers
guile-quickcheck
guile-sjson
guile-config
clippy clippy
rustc rustc
cargo cargo
@ -104,8 +102,9 @@
${pkgs.hugo}/bin/hugo --minify ${pkgs.hugo}/bin/hugo --minify
''; '';
installPhase = '' installPhase = ''
mkdir -p $out/public ls -l
cp -r public $out/public cp -r public $out/
ls -l $out
''; '';
buildInputs = bi; buildInputs = bi;
nativeBuildInputs = nbi; nativeBuildInputs = nbi;
@ -121,22 +120,24 @@
buildInputs = bi; buildInputs = bi;
nativeLibs = nativeLibs; nativeLibs = nativeLibs;
}; };
packages.default = pkgs.rustPlatform.buildRustPackage rec { packages.default = naersk'.buildPackage {
pname = "tfcapi"; pname = "tfcapi";
version = "0.0.1"; version = "0.0.1";
src = ./.; src = ./.;
cargoBuildFlags = ""; cargoBuildFlags = "";
doCheck = false; doCheck = false;
cargoLock = { # cargoLock = {
lockFile = ./Cargo.lock; # lockFile = ./Cargo.lock;
}; # };
nativeBuildInputs = nbi; nativeBuildInputs = nbi;
buildInputs = bi; buildInputs = bi;
fixupPhase = '' fixupPhase = ''
ls -l ls -l
mkdir -p $out/public
ls -l $out
cp -r ${site}/* $out/public/
ls -l $out ls -l $out
cp -r ${site}/public $out/public
''; '';
}; };
packages.site = site; packages.site = site;

View file

@ -2,7 +2,7 @@ default:
just --list just --list
build: build:
rm -rf public && NODE_ENV=production ./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 && hugo --gc --minify rm -rf public && NODE_ENV=production ./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 && hugo --gc --minify
run: run: build
cargo run cargo run
server: server:
hugo server --noHTTPCache --disableFastRender hugo server --noHTTPCache --disableFastRender

View file

@ -224,7 +224,7 @@
target="_parent" target="_parent"
class="w-full items-center flex flex-wrap"> class="w-full items-center flex flex-wrap">
<h3 class="basis-full">2024-2025 Health Form</h3> <h3 class="basis-full">2025-2026 Health Form</h3>
<div class="basis-full flex flex-wrap my-4"> <div class="basis-full flex flex-wrap my-4">
<label for="first-name" class="basis-full">What is your first and last name? <span class='inline-block text-[#f39] text-sm'>* required</span></label> <label for="first-name" class="basis-full">What is your first and last name? <span class='inline-block text-[#f39] text-sm'>* required</span></label>
<br/> <br/>

View file

@ -2,163 +2,76 @@ use std::collections::HashMap;
use actix_multipart::form::{text::Text, MultipartForm}; use actix_multipart::form::{text::Text, MultipartForm};
use actix_web::{http::StatusCode, post, HttpResponse, HttpResponseBuilder}; use actix_web::{http::StatusCode, post, HttpResponse, HttpResponseBuilder};
use lettre::{message::MultiPart, Message}; use color_eyre::eyre::{Context, Result};
use maud::{html, DOCTYPE}; use futures::FutureExt;
use reqwest::{Client, Error}; use lettre::{message::SinglePart, Message};
use tracing::info; use maud::{html, Markup, DOCTYPE};
use reqwest::Client;
use tracing::{error, info};
use crate::email::send_email; #[derive(Debug, MultipartForm)]
#[derive(Debug, MultipartForm, Default)]
struct CampForm { struct CampForm {
#[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>,
gender: Option<Text<String>>, gender: 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<i32>>, zip: Text<i32>,
#[multipart(rename = "parent-phone")] #[multipart(rename = "parent-phone")]
parent_phone: Option<Text<String>>, parent_phone: Text<String>,
#[multipart(rename = "parent-email")] #[multipart(rename = "parent-email")]
parent_email: Option<Text<String>>, parent_email: Text<String>,
grade: Option<Text<String>>, grade: Text<String>,
shirt: Option<Text<String>>, shirt: Text<String>,
allergies: Option<Text<String>>, allergies: Text<String>,
week: Option<Text<String>>, week: Text<String>,
registration: Option<Text<String>>, registration: Text<String>,
#[multipart(rename = "health-form")] #[multipart(rename = "health-form")]
health_form: Option<Text<String>>, health_form: Text<String>,
} }
#[post("/camp-form")] impl From<&CampForm> for HashMap<i32, String> {
pub async fn camp_form(MultipartForm(form): MultipartForm<CampForm>) -> HttpResponse { fn from(form: &CampForm) -> Self {
info!("a new form"); let mut map = HashMap::new();
let first = form map.insert(63, format!("{} {}", form.first_name.0, form.last_name.0));
.first_name map.insert(
.as_ref() 64,
.unwrap_or(&Text(String::from(""))) format!("{} {}", form.parent_first_name.0, form.parent_last_name.0),
.0
.clone();
let last = form
.last_name
.as_ref()
.unwrap_or(&Text(String::from("")))
.0
.clone();
let full_name = format!("{} {}", first, last);
let email_subject = format!("{} {} signed up for camp!", 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(65, form.parent_phone.0.clone());
.birthdate map.insert(66, form.parent_email.0.clone().clone());
.as_ref() map.insert(67, form.birthdate.0.clone());
.unwrap_or(&Text(String::from(""))) map.insert(69, form.gender.0.clone());
.0 map.insert(70, form.street.0.clone());
.clone(); map.insert(71, form.city.0.clone());
let gender = form map.insert(72, form.state.0.clone());
.gender map.insert(73, form.zip.0.clone().to_string());
.as_ref() map.insert(74, form.grade.0.clone());
.unwrap_or(&Text(String::from(""))) map.insert(75, form.week.0.clone());
.0 map.insert(76, form.shirt.0.clone());
.clone(); map.insert(77, form.registration.0.clone());
let street = form map.insert(115, form.health_form.0.clone());
.street map
.as_ref() }
.unwrap_or(&Text(String::from(""))) }
.0
.clone();
let city = form
.city
.as_ref()
.unwrap_or(&Text(String::from("")))
.0
.clone();
let state = form
.state
.as_ref()
.unwrap_or(&Text(String::from("")))
.0
.clone();
let zip = form.zip.as_ref().unwrap_or(&Text(0)).0;
let parent_phone = form
.parent_phone
.as_ref()
.unwrap_or(&Text(String::from("")))
.0
.clone();
let parent_email = form
.parent_email
.as_ref()
.unwrap_or(&Text(String::from("")))
.0
.clone();
let grade = form
.grade
.as_ref()
.unwrap_or(&Text(String::from("")))
.0
.clone();
let shirt = form
.shirt
.as_ref()
.unwrap_or(&Text(String::from("")))
.0
.clone();
let allergies = form
.allergies
.as_ref()
.unwrap_or(&Text(String::from("")))
.0
.clone();
let week = form
.week
.as_ref()
.unwrap_or(&Text(String::from("")))
.0
.clone();
let registration = form
.registration
.as_ref()
.unwrap_or(&Text(String::from("")))
.0
.clone();
let health = form
.health_form
.as_ref()
.unwrap_or(&Text(String::from("")))
.0
.clone();
let reg = registration.clone();
info!("Sending post to database"); impl CampForm {
fn build_email(&self) -> Markup {
info!("{first} {last} signed up for camp!"); html! {
let email = html! {
(DOCTYPE) (DOCTYPE)
meta charset="utf-8"; meta charset="utf-8";
html { html {
head { head {
title { (first) " " (last) " signed up for camp!" } title { (self.first_name.0) " " (self.last_name.0) " signed up for camp!" }
style { style {
"table { border-collapse: collapse; width: 100% }" "table { border-collapse: collapse; width: 100% }"
"td, th { padding: 8px }" "td, th { padding: 8px }"
@ -169,83 +82,102 @@ pub async fn camp_form(MultipartForm(form): MultipartForm<CampForm>) -> HttpResp
} }
} }
body { body {
h1 { "Camp form for " (first) " " (last) } h1 { "Camp 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 { "Gender" } th { "Gender" }
td { (gender) } td { (self.gender.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 { "Parent Phone" } th { "Parent Phone" }
td { (parent_phone) } td { (self.parent_phone.0) }
} }
tr { tr {
th { "Parent Email" } th { "Parent Email" }
td { (parent_email) } td { (self.parent_email.0) }
} }
tr { tr {
th { "Grade" } th { "Grade" }
td { (grade) } td { (self.grade.0) }
} }
tr { tr {
th { "Camper Allergies" } th { "Camper Allergies" }
td { (allergies) } td { (self.allergies.0) }
} }
tr { tr {
th { "T-Shirt Size" } th { "T-Shirt Size" }
td { (shirt) } td { (self.shirt.0) }
} }
tr { tr {
th { "Week Choice" } th { "Week Choice" }
td { (week) } td { (self.week.0) }
} }
tr { tr {
th { "Health Form" } th { "Health Form" }
td { (health) } td { (self.health_form.0) }
} }
tr { tr {
th { "Registration" } th { "Registration" }
td { (registration) } td { (self.registration.0) }
}
}
} }
} }
} }
} }
};
let multi = MultiPart::alternative_plain_html(
String::from("A camp form was filled out!"),
email.into_string(),
);
if let Ok(m) = Message::builder() fn prepare_email(&self) -> Result<Message> {
let first = self.first_name.clone();
let last = self.last_name.clone();
let email_subject = format!("{} {} signed up for camp!", first, last);
info!("{first} {last} signed up for camp!");
let email = self.build_email();
// let temp_file = self.get_temp_file();
// let multi = if let Some((file, path, content_type)) = temp_file {
// let filebody = fs::read(path);
// let content_type =
// ContentType::parse(&content_type.unwrap_or(String::from("image/jpg"))).unwrap();
// let attachment = Attachment::new(file).body(filebody.unwrap(), content_type);
// // info!(?attachment);
// MultiPart::mixed()
// .singlepart(SinglePart::html(email.into_string()))
// .singlepart(attachment)
// } else {
// MultiPart::alternative_plain_html(String::from("Testing"), email.into_string())
// };
let singlepart = SinglePart::html(email.into_string());
Message::builder()
.from( .from(
"TFC ADMIN <no-reply@mail.tfcconnection.org>" "TFC ADMIN <no-reply@mail.tfcconnection.org>"
.parse() .parse()
@ -254,19 +186,35 @@ pub async fn camp_form(MultipartForm(form): MultipartForm<CampForm>) -> HttpResp
.to("Chris Cochrun <chris@tfcconnection.org>".parse().unwrap()) .to("Chris Cochrun <chris@tfcconnection.org>".parse().unwrap())
.to("Ethan Rose <ethan@tfcconnection.org>".parse().unwrap()) .to("Ethan Rose <ethan@tfcconnection.org>".parse().unwrap())
.subject(email_subject) .subject(email_subject)
.multipart(multi) .singlepart(singlepart)
{ // .multipart(multi)
let _ = send_email(m); .wrap_err("problemss")
} else {
info!("Email incorrect");
} }
}
match store_camp_form(form).await { #[post("/api/camp-form")]
pub async fn camp_form(MultipartForm(form): MultipartForm<CampForm>) -> HttpResponse {
let full_name = format!("{} {}", form.first_name.0, form.last_name.0);
let map = (&form).into();
let future = store_camp_form(map);
actix_rt::spawn(future.map(|s| match s {
Ok(_) => info!("Successfully posted to nextcloud tables"), Ok(_) => info!("Successfully posted to nextcloud tables"),
Err(e) => log::error!("Error in posting camp data: {:?}", e), Err(e) => log::error!("Error in posting camp data: {:?}", e),
} }));
match health.as_str() { let email = form.prepare_email();
match email {
Ok(m) => {
let sent = crate::email::send_email(m);
actix_rt::spawn(sent.map(|s| match s {
Ok(_) => info!("Successfully sent form to email!"),
Err(e) => error!("There was an erroring sending form to email: {e}"),
}));
}
Err(e) => error!("error sending email {e}"),
};
match form.health_form.0.as_str() {
"now" => { "now" => {
info!("Sending them to fill out the health form"); info!("Sending them to fill out the health form");
HttpResponse::Ok() HttpResponse::Ok()
@ -274,13 +222,13 @@ pub async fn camp_form(MultipartForm(form): MultipartForm<CampForm>) -> HttpResp
.insert_header(( .insert_header((
"HX-Redirect", "HX-Redirect",
format!( format!(
"https://tfcconnection.org/camp-health-form/?registration={}", "/camp-health-form/?registration={}",
reg.as_str() form.registration.0.as_str()
), ),
)) ))
.finish() .finish()
} }
"later" => match reg.as_str() { "later" => 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()
@ -343,46 +291,70 @@ pub async fn camp_form(MultipartForm(form): MultipartForm<CampForm>) -> HttpResp
} }
} }
async fn store_camp_form(form: CampForm) -> Result<(), Error> { async fn store_camp_form(map: HashMap<i32, String>) -> Result<()> {
let request = Client::new(); let request = Client::new();
let mut map = HashMap::new();
map.insert(
63,
format!(
"{} {}",
&form.first_name.unwrap_or(Text(String::new())).0,
&form.last_name.unwrap_or(Text(String::new())).0
),
);
map.insert(
64,
format!(
"{} {}",
form.parent_first_name.unwrap_or(Text(String::new())).0,
form.parent_last_name.unwrap_or(Text(String::new())).0
),
);
map.insert(65, form.parent_phone.unwrap_or(Text(String::new())).0);
map.insert(66, form.parent_email.unwrap_or(Text(String::new())).0);
map.insert(67, form.birthdate.unwrap_or(Text(String::new())).0);
map.insert(69, form.gender.unwrap_or(Text(String::new())).0);
map.insert(70, form.street.unwrap_or(Text(String::new())).0);
map.insert(71, form.city.unwrap_or(Text(String::new())).0);
map.insert(72, form.state.unwrap_or(Text(String::new())).0);
map.insert(73, form.zip.unwrap_or(Text(0)).0.to_string());
map.insert(74, form.grade.unwrap_or(Text(String::new())).0);
map.insert(75, form.week.unwrap_or(Text(String::new())).0);
map.insert(76, form.shirt.unwrap_or(Text(String::new())).0);
map.insert(77, form.registration.unwrap_or(Text(String::new())).0);
map.insert(115, form.health_form.unwrap_or(Text(String::new())).0);
let mut json = HashMap::new(); let mut json = HashMap::new();
json.insert("data", map); json.insert("data", map);
request request
.post("https://staff.tfcconnection.org/apps/tables/api/1/tables/5/rows") .post("https://staff.tfcconnection.org/apps/tables/api/1/tables/5/rows")
// .header("xc-token", "Ohah24HNGXVvvixv8tvVJW5uNNdWjDJHG1d4t3o9")
.basic_auth("chris", Some("2VHeGxeC^Zf9KqFK^G@Pt!zu2q^6@b")) .basic_auth("chris", Some("2VHeGxeC^Zf9KqFK^G@Pt!zu2q^6@b"))
.header("OCS-APIRequest", "true")
.header("Content-Type", "application/json")
.json(&json) .json(&json)
.send() .send()
.await?; .await?;
Ok(()) Ok(())
} }
#[cfg(test)]
mod test {
use super::*;
use actix_web::test;
fn form() -> CampForm {
CampForm {
first_name: Text("Frodo".into()),
last_name: Text("Braggins".into()),
parent_first_name: Text("Bilbo".into()),
parent_last_name: Text("Braggins".into()),
birthdate: Text(String::from("1845-09-12")),
gender: Text(String::from("male")),
street: Text(String::from("1234 Bag End")),
city: Text(String::from("The Shire")),
state: Text(String::from("Hobbiton")),
zip: Text(88888),
parent_phone: Text(String::from("1234567898")),
parent_email: Text(String::from("bilbo@hobbits.com")),
grade: Text(String::from("junior")),
shirt: Text(String::from("medium")),
allergies: Text(String::from("Cool beans")),
week: Text(String::from("1")),
registration: Text(String::from("later")),
health_form: Text(String::from("I guess")),
}
}
#[test]
async fn test_nc_post() {
let form = form();
assert!(!form.first_name.is_empty());
let map = HashMap::from(&form);
let res = store_camp_form(map).await;
match res {
Ok(_) => assert!(true),
Err(e) => assert!(false, "Failed storing test: {e}"),
}
}
#[test]
async fn test_email() {
let form = form();
assert!(!form.first_name.is_empty());
match form.prepare_email() {
Ok(m) => {
assert!(crate::email::send_email(m).await.is_ok())
}
Err(e) => assert!(false, "Failed emailing test: {e}"),
}
}
}

View file

@ -70,7 +70,6 @@ impl ContactForm {
let mut json = HashMap::new(); let mut json = HashMap::new();
json.insert("data", map); json.insert("data", map);
let link = r#"https://staff.tfcconnection.org/apps/tables/#/table/140/row/757"#;
let res = client let res = client
.post("https://staff.tfcconnection.org/ocs/v2.php/apps/tables/api/2/tables/140/rows") .post("https://staff.tfcconnection.org/ocs/v2.php/apps/tables/api/2/tables/140/rows")
.basic_auth("chris", Some("2VHeGxeC^Zf9KqFK^G@Pt!zu2q^6@b")) .basic_auth("chris", Some("2VHeGxeC^Zf9KqFK^G@Pt!zu2q^6@b"))

View file

@ -380,7 +380,7 @@ pub async fn health_form(MultipartForm(mut form): MultipartForm<HealthForm>) ->
.insert_header(("Access-Control-Expose-Headers", "*")) .insert_header(("Access-Control-Expose-Headers", "*"))
.insert_header(( .insert_header((
"HX-Redirect", "HX-Redirect",
"https://secure.myvanco.com/L-Z772/campaign/C-13DM3", "https://secure.myvanco.com/L-Z772/campaign/C-13JPJ",
)) ))
.finish() .finish()
} }

View file

@ -1,4 +1,4 @@
use std::{collections::HashMap, fs, io::Write}; 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};
@ -269,32 +269,6 @@ impl MtForm {
} }
} }
async fn store_form(&self) -> Result<()> {
let client = Client::new();
let map = HashMap::from(self);
let mut json = HashMap::new();
json.insert("data", map);
let link = r#"https://staff.tfcconnection.org/apps/tables/#/table/9/row/757"#;
let res = client
.post("https://staff.tfcconnection.org/ocs/v2.php/apps/tables/api/2/tables/9/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 {
Err(eyre!(
"Problem in storing data: {:?}",
res.error_for_status()
))
}
}
fn get_temp_file(&self) -> Option<(String, String, Option<String>)> { fn get_temp_file(&self) -> Option<(String, String, Option<String>)> {
let first = self.first_name.clone(); let first = self.first_name.clone();
let last = self.last_name.clone(); let last = self.last_name.clone();
@ -339,7 +313,7 @@ impl MtForm {
} }
} }
fn send_email(&self) -> Result<Message> { fn prepare_email(&self) -> Result<Message> {
let first = self.first_name.clone(); let first = self.first_name.clone();
let last = self.last_name.clone(); let last = self.last_name.clone();
let email_subject = format!("{} {} signed up for mission trip!", first, last); let email_subject = format!("{} {} signed up for mission trip!", first, last);
@ -382,7 +356,7 @@ pub async fn mt_form(MultipartForm(form): MultipartForm<MtForm>) -> HttpResponse
Ok(_) => info!("Successfully sent form to nextcloud!"), Ok(_) => info!("Successfully sent form to nextcloud!"),
Err(e) => error!("There was an erroring sending form to nextcloud: {e}"), Err(e) => error!("There was an erroring sending form to nextcloud: {e}"),
})); }));
let email = form.send_email(); let email = form.prepare_email();
match email { match email {
Ok(m) => { Ok(m) => {
let sent = crate::email::send_email(m); let sent = crate::email::send_email(m);
@ -453,7 +427,6 @@ async fn store_form(map: HashMap<i32, String>) -> Result<()> {
let mut json = HashMap::new(); let mut json = HashMap::new();
json.insert("data", map); json.insert("data", map);
let link = r#"https://staff.tfcconnection.org/apps/tables/#/table/9/row/757"#;
let res = client let res = client
.post("https://staff.tfcconnection.org/ocs/v2.php/apps/tables/api/2/tables/9/rows") .post("https://staff.tfcconnection.org/ocs/v2.php/apps/tables/api/2/tables/9/rows")
.basic_auth("chris", Some("2VHeGxeC^Zf9KqFK^G@Pt!zu2q^6@b")) .basic_auth("chris", Some("2VHeGxeC^Zf9KqFK^G@Pt!zu2q^6@b"))
@ -463,7 +436,7 @@ async fn store_form(map: HashMap<i32, String>) -> Result<()> {
.send() .send()
.await?; .await?;
if res.status().is_success() { if res.status().is_success() {
let res = res.text().await.unwrap(); // let res = res.text().await.unwrap();
Ok(()) Ok(())
} else { } else {
Err(eyre!( Err(eyre!(
@ -476,9 +449,6 @@ async fn store_form(map: HashMap<i32, String>) -> Result<()> {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use actix_web::test; use actix_web::test;
use pretty_assertions::assert_eq;
use sqlx::Connection;
use tracing::debug;
use super::*; use super::*;
@ -527,7 +497,8 @@ mod test {
async fn test_nc_post() { async fn test_nc_post() {
let form = form(); let form = form();
assert!(!form.first_name.is_empty()); assert!(!form.first_name.is_empty());
let res = form.store_form().await; let map = HashMap::from(&form);
let res = store_form(map).await;
match res { match res {
Ok(_) => assert!(true, "passed storing test"), Ok(_) => assert!(true, "passed storing test"),
Err(e) => assert!(false, "Failed storing test: {e}"), Err(e) => assert!(false, "Failed storing test: {e}"),
@ -536,10 +507,12 @@ mod test {
#[test] #[test]
async fn test_email() { async fn test_email() {
let mut form = form(); let form = form();
assert!(!form.first_name.is_empty()); assert!(!form.first_name.is_empty());
match form.send_email() { match form.prepare_email() {
Ok(_) => assert!(true, "passed emailing test"), Ok(m) => {
assert!(crate::email::send_email(m).await.is_ok())
}
Err(e) => assert!(false, "Failed emailing test: {e}"), Err(e) => assert!(false, "Failed emailing test: {e}"),
} }
} }

View file

@ -153,7 +153,7 @@ impl MtParentForm {
} }
} }
async fn send_email(&mut self) -> Result<()> { async fn send_email(&self) -> Result<()> {
let first = self.student_first_name.clone(); let first = self.student_first_name.clone();
let last = self.student_last_name.clone(); let last = self.student_last_name.clone();
let email_subject = format!("Parent reference form for {} {}!", first, last); let email_subject = format!("Parent reference form for {} {}!", first, last);
@ -180,7 +180,7 @@ impl MtParentForm {
} }
#[post("/api/mt-parent-form")] #[post("/api/mt-parent-form")]
pub async fn mt_parent_form(MultipartForm(mut form): MultipartForm<MtParentForm>) -> HttpResponse { pub async fn mt_parent_form(MultipartForm(form): MultipartForm<MtParentForm>) -> HttpResponse {
match form.store_form().await { match form.store_form().await {
Ok(_) => info!("Successfully sent form to nextcloud!"), Ok(_) => info!("Successfully sent form to nextcloud!"),
Err(e) => error!("There was an erroring sending form to nextcloud: {e}"), Err(e) => error!("There was an erroring sending form to nextcloud: {e}"),

View file

@ -49,7 +49,7 @@ async fn main() -> std::io::Result<()> {
.rotation(Rotation::DAILY) .rotation(Rotation::DAILY)
.filename_prefix("api") .filename_prefix("api")
.filename_suffix("log") .filename_suffix("log")
.build("./tmp") .build("/storage/logs/tfcsite")
.expect("Shouldn't"); .expect("Shouldn't");
let filter = EnvFilter::builder() let filter = EnvFilter::builder()
@ -75,7 +75,7 @@ async fn main() -> std::io::Result<()> {
.with(logfile_layer.with_filter(filter).and_then(stdout_layer)); .with(logfile_layer.with_filter(filter).and_then(stdout_layer));
let _ = tracing::subscriber::set_global_default(subscriber).wrap_err("Tracing broked"); let _ = tracing::subscriber::set_global_default(subscriber).wrap_err("Tracing broked");
std::fs::create_dir_all("./tmp")?; std::fs::create_dir_all("/storage/logs/tfcsite")?;
info!("starting HTTP server at http://localhost:4242"); info!("starting HTTP server at http://localhost:4242");
@ -88,7 +88,7 @@ async fn main() -> std::io::Result<()> {
App::new() App::new()
.app_data(data.clone()) .app_data(data.clone())
.wrap(TracingLogger::<DomainRootSpanBuilder>::new()) .wrap(TracingLogger::<DomainRootSpanBuilder>::new())
.app_data(TempFileConfig::default().directory("./tmp")) .app_data(TempFileConfig::default().directory("/storage/logs/tfcsite"))
.service(mt_form) .service(mt_form)
.service(health_form) .service(health_form)
.service(mt_parent_form) .service(mt_parent_form)