Compare commits

..

No commits in common. "f6cd1e4f18ad3ce25b4d454da548729300762fa3" and "33b8c0d7c355c80c92273a14805684b2b4ea6cc7" have entirely different histories.

12 changed files with 372 additions and 350 deletions

View file

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

View file

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

View file

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

View file

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

View file

@ -2,7 +2,7 @@ default:
just --list
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
run: build
run:
cargo run
server:
hugo server --noHTTPCache --disableFastRender

View file

@ -224,7 +224,7 @@
target="_parent"
class="w-full items-center flex flex-wrap">
<h3 class="basis-full">2025-2026 Health Form</h3>
<h3 class="basis-full">2024-2025 Health Form</h3>
<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>
<br/>

View file

@ -2,219 +2,271 @@ use std::collections::HashMap;
use actix_multipart::form::{text::Text, MultipartForm};
use actix_web::{http::StatusCode, post, HttpResponse, HttpResponseBuilder};
use color_eyre::eyre::{Context, Result};
use futures::FutureExt;
use lettre::{message::SinglePart, Message};
use maud::{html, Markup, DOCTYPE};
use reqwest::Client;
use tracing::{error, info};
use lettre::{message::MultiPart, Message};
use maud::{html, DOCTYPE};
use reqwest::{Client, Error};
use tracing::info;
#[derive(Debug, MultipartForm)]
use crate::email::send_email;
#[derive(Debug, MultipartForm, Default)]
struct CampForm {
#[multipart(rename = "first-name")]
first_name: Text<String>,
first_name: Option<Text<String>>,
#[multipart(rename = "last-name")]
last_name: Text<String>,
last_name: Option<Text<String>>,
#[multipart(rename = "parent-first-name")]
parent_first_name: Text<String>,
parent_first_name: Option<Text<String>>,
#[multipart(rename = "parent-last-name")]
parent_last_name: Text<String>,
parent_last_name: Option<Text<String>>,
#[multipart(rename = "birth-date")]
birthdate: Text<String>,
gender: Text<String>,
street: Text<String>,
city: Text<String>,
state: Text<String>,
zip: Text<i32>,
birthdate: Option<Text<String>>,
gender: Option<Text<String>>,
street: Option<Text<String>>,
city: Option<Text<String>>,
state: Option<Text<String>>,
zip: Option<Text<i32>>,
#[multipart(rename = "parent-phone")]
parent_phone: Text<String>,
parent_phone: Option<Text<String>>,
#[multipart(rename = "parent-email")]
parent_email: Text<String>,
grade: Text<String>,
shirt: Text<String>,
allergies: Text<String>,
week: Text<String>,
registration: Text<String>,
parent_email: Option<Text<String>>,
grade: Option<Text<String>>,
shirt: Option<Text<String>>,
allergies: Option<Text<String>>,
week: Option<Text<String>>,
registration: Option<Text<String>>,
#[multipart(rename = "health-form")]
health_form: Text<String>,
health_form: Option<Text<String>>,
}
impl From<&CampForm> for HashMap<i32, String> {
fn from(form: &CampForm) -> Self {
let mut map = HashMap::new();
map.insert(63, format!("{} {}", form.first_name.0, form.last_name.0));
map.insert(
64,
format!("{} {}", form.parent_first_name.0, form.parent_last_name.0),
);
map.insert(65, form.parent_phone.0.clone());
map.insert(66, form.parent_email.0.clone().clone());
map.insert(67, form.birthdate.0.clone());
map.insert(69, form.gender.0.clone());
map.insert(70, form.street.0.clone());
map.insert(71, form.city.0.clone());
map.insert(72, form.state.0.clone());
map.insert(73, form.zip.0.clone().to_string());
map.insert(74, form.grade.0.clone());
map.insert(75, form.week.0.clone());
map.insert(76, form.shirt.0.clone());
map.insert(77, form.registration.0.clone());
map.insert(115, form.health_form.0.clone());
map
}
}
#[post("/camp-form")]
pub async fn camp_form(MultipartForm(form): MultipartForm<CampForm>) -> HttpResponse {
info!("a new form");
let first = form
.first_name
.as_ref()
.unwrap_or(&Text(String::from("")))
.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
.birthdate
.as_ref()
.unwrap_or(&Text(String::from("")))
.0
.clone();
let gender = form
.gender
.as_ref()
.unwrap_or(&Text(String::from("")))
.0
.clone();
let street = form
.street
.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();
impl CampForm {
fn build_email(&self) -> Markup {
html! {
(DOCTYPE)
meta charset="utf-8";
html {
head {
title { (self.first_name.0) " " (self.last_name.0) " signed up for camp!" }
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 }"
}
info!("Sending post to database");
info!("{first} {last} signed up for camp!");
let email = html! {
(DOCTYPE)
meta charset="utf-8";
html {
head {
title { (first) " " (last) " signed up for camp!" }
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 { "Camp form for " (self.first_name.0) " " (self.last_name.0) "!" }
hr;
table {
tr {
th { "Name" }
td { (self.first_name.0) " " (self.last_name.0) }
}
tr {
th { "Parent" }
td { (self.parent_first_name.0) " " (self.parent_last_name.0) }
}
tr {
th { "Birthdate" }
td { (self.birthdate.0) }
}
tr {
th { "Gender" }
td { (self.gender.0) }
}
tr {
th { "Street" }
td { (self.street.0) }
}
tr {
th { "City" }
td { (self.city.0) }
}
tr {
th { "State" }
td { (self.state.0) }
}
tr {
th { "Zip" }
td { (self.zip.0) }
}
tr {
th { "Parent Phone" }
td { (self.parent_phone.0) }
}
tr {
th { "Parent Email" }
td { (self.parent_email.0) }
}
tr {
th { "Grade" }
td { (self.grade.0) }
}
tr {
th { "Camper Allergies" }
td { (self.allergies.0) }
}
tr {
th { "T-Shirt Size" }
td { (self.shirt.0) }
}
tr {
th { "Week Choice" }
td { (self.week.0) }
}
tr {
th { "Health Form" }
td { (self.health_form.0) }
}
tr {
th { "Registration" }
td { (self.registration.0) }
}
}
body {
h1 { "Camp form for " (first) " " (last) }
hr;
table {
tr {
th { "Name" }
td { (first) " " (last) }
}
tr {
th { "Parent" }
td { (parent) }
}
tr {
th { "Birthdate" }
td { (birthdate) }
}
tr {
th { "Gender" }
td { (gender) }
}
tr {
th { "Street" }
td { (street) }
}
tr {
th { "City" }
td { (city) }
}
tr {
th { "State" }
td { (state) }
}
tr {
th { "Zip" }
td { (zip) }
}
tr {
th { "Parent Phone" }
td { (parent_phone) }
}
tr {
th { "Parent Email" }
td { (parent_email) }
}
tr {
th { "Grade" }
td { (grade) }
}
tr {
th { "Camper Allergies" }
td { (allergies) }
}
tr {
th { "T-Shirt Size" }
td { (shirt) }
}
tr {
th { "Week Choice" }
td { (week) }
}
tr {
th { "Health Form" }
td { (health) }
}
tr {
th { "Registration" }
td { (registration) }
}
}
}
}
}
};
let multi = MultiPart::alternative_plain_html(
String::from("A camp form was filled out!"),
email.into_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");
}
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(
"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)
.singlepart(singlepart)
// .multipart(multi)
.wrap_err("problemss")
}
}
#[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 {
match store_camp_form(form).await {
Ok(_) => info!("Successfully posted to nextcloud tables"),
Err(e) => log::error!("Error in posting camp data: {:?}", e),
}));
}
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() {
match health.as_str() {
"now" => {
info!("Sending them to fill out the health form");
HttpResponse::Ok()
@ -222,13 +274,13 @@ pub async fn camp_form(MultipartForm(form): MultipartForm<CampForm>) -> HttpResp
.insert_header((
"HX-Redirect",
format!(
"/camp-health-form/?registration={}",
form.registration.0.as_str()
"https://tfcconnection.org/camp-health-form/?registration={}",
reg.as_str()
),
))
.finish()
}
"later" => match form.registration.0.as_str() {
"later" => match reg.as_str() {
"now" => {
info!("Sending them to pay for registration now");
HttpResponse::Ok()
@ -291,70 +343,46 @@ pub async fn camp_form(MultipartForm(form): MultipartForm<CampForm>) -> HttpResp
}
}
async fn store_camp_form(map: HashMap<i32, String>) -> Result<()> {
async fn store_camp_form(form: CampForm) -> Result<(), Error> {
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();
json.insert("data", map);
request
.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"))
.header("OCS-APIRequest", "true")
.header("Content-Type", "application/json")
.json(&json)
.send()
.await?;
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,6 +70,7 @@ impl ContactForm {
let mut json = HashMap::new();
json.insert("data", map);
let link = r#"https://staff.tfcconnection.org/apps/tables/#/table/140/row/757"#;
let res = client
.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"))

View file

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

View file

@ -1,4 +1,4 @@
use std::{collections::HashMap, fs};
use std::{collections::HashMap, fs, io::Write};
use actix_multipart::form::{tempfile::TempFile, text::Text, MultipartForm};
use actix_web::{post, HttpResponse};
@ -269,6 +269,32 @@ 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>)> {
let first = self.first_name.clone();
let last = self.last_name.clone();
@ -313,7 +339,7 @@ impl MtForm {
}
}
fn prepare_email(&self) -> Result<Message> {
fn send_email(&self) -> Result<Message> {
let first = self.first_name.clone();
let last = self.last_name.clone();
let email_subject = format!("{} {} signed up for mission trip!", first, last);
@ -356,7 +382,7 @@ pub async fn mt_form(MultipartForm(form): MultipartForm<MtForm>) -> HttpResponse
Ok(_) => info!("Successfully sent form to nextcloud!"),
Err(e) => error!("There was an erroring sending form to nextcloud: {e}"),
}));
let email = form.prepare_email();
let email = form.send_email();
match email {
Ok(m) => {
let sent = crate::email::send_email(m);
@ -427,6 +453,7 @@ async fn store_form(map: HashMap<i32, String>) -> Result<()> {
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"))
@ -436,7 +463,7 @@ async fn store_form(map: HashMap<i32, String>) -> Result<()> {
.send()
.await?;
if res.status().is_success() {
// let res = res.text().await.unwrap();
let res = res.text().await.unwrap();
Ok(())
} else {
Err(eyre!(
@ -449,6 +476,9 @@ async fn store_form(map: HashMap<i32, String>) -> Result<()> {
#[cfg(test)]
mod test {
use actix_web::test;
use pretty_assertions::assert_eq;
use sqlx::Connection;
use tracing::debug;
use super::*;
@ -497,8 +527,7 @@ mod test {
async fn test_nc_post() {
let form = form();
assert!(!form.first_name.is_empty());
let map = HashMap::from(&form);
let res = store_form(map).await;
let res = form.store_form().await;
match res {
Ok(_) => assert!(true, "passed storing test"),
Err(e) => assert!(false, "Failed storing test: {e}"),
@ -507,12 +536,10 @@ mod test {
#[test]
async fn test_email() {
let form = form();
let mut form = form();
assert!(!form.first_name.is_empty());
match form.prepare_email() {
Ok(m) => {
assert!(crate::email::send_email(m).await.is_ok())
}
match form.send_email() {
Ok(_) => assert!(true, "passed emailing test"),
Err(e) => assert!(false, "Failed emailing test: {e}"),
}
}

View file

@ -153,7 +153,7 @@ impl MtParentForm {
}
}
async fn send_email(&self) -> Result<()> {
async fn send_email(&mut self) -> Result<()> {
let first = self.student_first_name.clone();
let last = self.student_last_name.clone();
let email_subject = format!("Parent reference form for {} {}!", first, last);
@ -180,7 +180,7 @@ impl MtParentForm {
}
#[post("/api/mt-parent-form")]
pub async fn mt_parent_form(MultipartForm(form): MultipartForm<MtParentForm>) -> HttpResponse {
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}"),

View file

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