From ae37869c9f1dd9499c3e3f0185f853180a262714 Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Tue, 26 Mar 2024 14:30:37 -0500 Subject: [PATCH] trying to switch to using lisp but need to build it first --- default.nix | 138 ++++++++++++++++------------ flake.nix | 2 +- layouts/shortcodes/camp-form.html | 84 ++++++++++++++++- layouts/shortcodes/health-form.html | 4 +- shell.nix | 1 + src/api/camp_form.rs | 2 +- src/main.lisp | 118 ++++++++++++++++-------- tfcserver.asd | 1 + 8 files changed, 248 insertions(+), 102 deletions(-) diff --git a/default.nix b/default.nix index b68f410..8821972 100644 --- a/default.nix +++ b/default.nix @@ -1,37 +1,42 @@ { stdenv, lib, - hugo, - go, - cargo, - rustc, - clippy, - rust-analyzer, - rustfmt, + # hugo, + # go, + # cargo, + # rustc, + # clippy, + # rust-analyzer, + # rustfmt, pkg-config, - # sbcl, - # sbclPackages, + gcc, + gnumake, + sbcl, + sbclPackages, makeWrapper, openssl, - rustPlatform + build-asdf-system, + pkgs, + ... }: -# let -# sbcl' = sbcl.withPackages (ps: with ps; [ -# hunchentoot -# dexador -# jzon -# serapeum -# deploy -# spinneret -# lass -# cl-smtp -# # pkgs.openssl -# # pkgs.openssl.out -# # pkgs.openssl.dev -# ]); -# in -rustPlatform.buildRustPackage rec { +let + sbcl' = sbcl.withPackages (ps: with ps; [ + hunchentoot + dexador + jzon + serapeum + deploy + spinneret + lass + cl-smtp + log4cl + pkgs.openssl + pkgs.openssl.out + pkgs.openssl.dev + ]); +in +build-asdf-system { name = "tfcconnection"; pname = "tfcconnection"; version = "0.0.1"; @@ -39,52 +44,67 @@ rustPlatform.buildRustPackage rec { src = ./.; # cargoHash = "sha256-jtBw4ahSl88L0iuCXxQgZVm1EcboWRJMNtjxLVTtzts="; - cargoLock = { - lockFile = ./Cargo.lock; - }; + # cargoLock = { + # lockFile = ./Cargo.lock; + # }; nativeBuildInputs = [ - makeWrapper + gcc + stdenv + gnumake pkg-config - rustc - cargo - ]; - - buildInputs = [ - # rustPlatform - # clippy - # rustfmt - openssl + makeWrapper + # openssl # openssl.out # openssl.dev ]; - # nativeLibs = [ - # openssl - # openssl.out - # openssl.dev + # buildInputs = [ + # # rustPlatform + # # clippy + # # rustfmt + # # openssl + # # openssl.out + # # openssl.dev + # sbcl' # ]; - # lispLibs = with sbclPackages; [ - # hunchentoot - # dexador - # jzon - # serapeum - # deploy - # spinneret - # lass - # cl-smtp - # ]; + nativeLibs = [ + openssl + openssl.out + openssl.dev + ]; - buildPhase = '' - export HOME=$(pwd) - ${cargo}/bin/cargo build - ''; + lispLibs = with sbclPackages; [ + hunchentoot + dexador + jzon + serapeum + deploy + spinneret + lass + cl-smtp + log4cl + ]; + # ${cargo}/bin/cargo build + # buildPhase = '' + # export HOME=$(pwd) + # ${sbcl'}/bin/sbcl --load build.lisp + # ''; + + systems = "tfcserver"; + + buildScript = ./build.lisp; + + # cp target/debug/tfcapi $out/bin installPhase = '' + mkdir -pv $out + cp -r * $out + rm -fv $out/tfcserver mkdir -p $out/bin - cp target/debug/tfcapi $out/bin - wrapProgram $out/bin/tfcapi \ + cp -v tfcserver $out/bin + wrapProgram $out/bin/tfcserver \ --prefix LD_LIBRARY_PATH : $LD_LIBRARY_PATH \ ''; diff --git a/flake.nix b/flake.nix index 7888105..ae133d9 100644 --- a/flake.nix +++ b/flake.nix @@ -15,7 +15,7 @@ in { devShell = import ./shell.nix { inherit pkgs; }; - defaultPackage = pkgs.callPackage ./default.nix { }; + defaultPackage = import ./default.nix { }; } ); } diff --git a/layouts/shortcodes/camp-form.html b/layouts/shortcodes/camp-form.html index 93ad9ff..bb9ba1a 100644 --- a/layouts/shortcodes/camp-form.html +++ b/layouts/shortcodes/camp-form.html @@ -22,9 +22,59 @@ document.getElementById('warning-email').style.height = '0'; document.getElementById('warning-email').style.margin = '0'; } + if (data.get("firstname") == "") { + document.getElementById('warning-name').style.visibility = 'visible'; + document.getElementById('warning-name').style.height = ''; + document.getElementById('warning-name').style.margin = ''; + return false; + } else { + document.getElementById('warning-name').style.visibility = 'hidden'; + document.getElementById('warning-name').style.height = '0'; + document.getElementById('warning-name').style.margin = '0'; + } + if (data.get("lastname") == "") { + document.getElementById('warning-name').style.visibility = 'visible'; + document.getElementById('warning-name').style.height = ''; + document.getElementById('warning-name').style.margin = ''; + return false; + } else { + document.getElementById('warning-name').style.visibility = 'hidden'; + document.getElementById('warning-name').style.height = '0'; + document.getElementById('warning-name').style.margin = '0'; + } + if (data.get("parentfirstname") == "") { + document.getElementById('warning-name').style.visibility = 'visible'; + document.getElementById('warning-name').style.height = ''; + document.getElementById('warning-name').style.margin = ''; + return false; + } else { + document.getElementById('warning-name').style.visibility = 'hidden'; + document.getElementById('warning-name').style.height = '0'; + document.getElementById('warning-name').style.margin = '0'; + } + if (data.get("parentlastname") == "") { + document.getElementById('warning-name').style.visibility = 'visible'; + document.getElementById('warning-name').style.height = ''; + document.getElementById('warning-name').style.margin = ''; + return false; + } else { + document.getElementById('warning-name').style.visibility = 'hidden'; + document.getElementById('warning-name').style.height = '0'; + document.getElementById('warning-name').style.margin = '0'; + } + if (data.get("final-agreement") == "") { + document.getElementById('warning-agreement').style.visibility = 'visible'; + document.getElementById('warning-agreement').style.height = ''; + document.getElementById('warning-agreement').style.margin = ''; + return false; + } else { + document.getElementById('warning-agreement').style.visibility = 'hidden'; + document.getElementById('warning-agreement').style.height = '0'; + document.getElementById('warning-agreement').style.margin = '0'; + } - /* let base = "http://localhost:4242/camp-form"; */ - let base = "https://api.tfcconnection.org/camp-form"; + let base = "http://localhost:4242/camp-form"; + /* let base = "https://api.tfcconnection.org/camp-form"; */ fetch(base, { method: "POST", @@ -61,6 +111,15 @@ document.getElementById('warning-email').style.visibility = 'hidden'; document.getElementById('warning-email').style.height = '0'; document.getElementById('warning-email').style.margin = '0'; + document.getElementById('warning-name').style.visibility = 'hidden'; + document.getElementById('warning-name').style.height = '0'; + document.getElementById('warning-name').style.margin = '0'; + document.getElementById('warning-agreement').style.visibility = 'hidden'; + document.getElementById('warning-agreement').style.height = '0'; + document.getElementById('warning-agreement').style.margin = '0'; + document.getElementById('warning-other').style.visibility = 'hidden'; + document.getElementById('warning-other').style.height = '0'; + document.getElementById('warning-other').style.margin = '0'; } document.addEventListener('DOMContentLoaded', process); @@ -243,5 +302,26 @@ +
+ + {{ partial "icon.html" (.Get 0 | default "triangle-exclamation") }} + Make sure that all names are filled out + +
+ +
+ + {{ partial "icon.html" (.Get 0 | default "triangle-exclamation") }} + You have to agree to the registration information. + +
+ +
+ + {{ partial "icon.html" (.Get 0 | default "triangle-exclamation") }} + Have you checked to make sure all required fields are filled out? + +
+ diff --git a/layouts/shortcodes/health-form.html b/layouts/shortcodes/health-form.html index 4cf3125..63595b6 100644 --- a/layouts/shortcodes/health-form.html +++ b/layouts/shortcodes/health-form.html @@ -77,8 +77,8 @@ // For use in dev // Can now start using this in production IF, // I get the server running on the server - let base = "https://api.tfcconnection.org/health-form"; - /* let base = "http://localhost:4242/health-form"; */ + /* let base = "https://api.tfcconnection.org/health-form"; */ + let base = "http://localhost:4242/health-form"; fetch(base, { method: "POST", body: data diff --git a/shell.nix b/shell.nix index 6cc0bd7..16401a2 100644 --- a/shell.nix +++ b/shell.nix @@ -10,6 +10,7 @@ let spinneret lass cl-smtp + log4cl pkgs.openssl pkgs.openssl.out pkgs.openssl.dev diff --git a/src/api/camp_form.rs b/src/api/camp_form.rs index 86328ba..7d3eaad 100644 --- a/src/api/camp_form.rs +++ b/src/api/camp_form.rs @@ -261,7 +261,7 @@ pub async fn camp_form(MultipartForm(form): MultipartForm) -> HttpResp .unwrap(), ) .to("Chris Cochrun ".parse().unwrap()) - .to("Ethan Rose ".parse().unwrap()) + // .to("Ethan Rose ".parse().unwrap()) .subject(email_subject) .multipart(multi) { diff --git a/src/main.lisp b/src/main.lisp index 0b76021..d693abc 100644 --- a/src/main.lisp +++ b/src/main.lisp @@ -7,6 +7,7 @@ (require "spinneret") (require "lass") (require "cl-smtp") +(require "log4cl") (defpackage tfcserver (:use :cl :com.inuoe.jzon :spinneret :serapeum)) @@ -297,6 +298,48 @@ with the image attached to us" (:td (trim-whitespace (cdr row))))))))))))) +(defun mail-camp-form (form attachment) + "Takes the form as an alist and sends a table formatted email +with the image attached" + (let* ((first-name (trim-whitespace + (cdr (assoc "firstname" form + :test 'string=)))) + (last-name (trim-whitespace + (cdr (assoc "lastname" form + :test 'string=)))) + (parent-name (concatenate 'string + (trim-whitespace + (cdr (assoc "parentfirstname" form + :test 'string=))) + " " + (trim-whitespace + (cdr (assoc "parentlastname" form + :test 'string=)))))) + (not (cl-smtp:send-email + "mail.tfcconnection.org" + "no-reply@mail.tfcconnection.org" + '("chris@tfcconnection.org" "chris@cochrun.xyz") + (format nil "~a ~a filled out a Camp Form!" first-name last-name) + (format nil "Camp Form for ~a ~a" first-name last-name) + :display-name "TFC ADMIN" + :ssl :tls + :authentication '(:login "no-reply@mail.tfcconnection.org" "r9f36mNZFtiW4f") + :attachments attachment + :html-message + (with-html-string + (:doctype) + (:html + (:head (:title "TFC Health Form") + (:style (apply #'lass:compile-and-write *mail-css*))) + (:body + (:h1 (format nil "Camp Form for ~a ~a" first-name last-name)) + (:hr) + (:table + (loop for row in form + do (:tr + (:th (car row)) + (:td (cdr row)))))))))))) + (defun mail-health-form (form attachment) "Takes the form as an alist and sends a table formatted email with the image attached" @@ -342,46 +385,47 @@ with the image attached" (defun define-post-form-handler (uri mail-function) "Take a uri and a mailer function and define a handler in hunchentoot for forms to POST to." -(hunchentoot:define-easy-handler (respond :uri uri) () - (setf (hunchentoot:content-type*) "plain/text") - (let* ((request-type (hunchentoot:request-method hunchentoot:*request*)) - (post-data (hunchentoot:post-parameters* hunchentoot:*request*)) - (attachment nil) - (first-name nil) - (last-name nil)) - (cond ((eq request-type :get) nil) - ((eq request-type :post) - (loop :for d :in post-data - :do (progn - (uiop:println d) - (if (string= "firstname" (car d)) - (progn - (uiop:println (cdr d)) - (setf first-name (cdr d)))) - (if (string= "lastname" (car d)) - (progn - (uiop:println (cdr d)) - (setf last-name (cdr d)))) - (if (string= "image" (car d)) - (let ((path (path-join - hunchentoot:*tmp-directory* - (format nil "~a_~a.~a" first-name last-name - (cadr (uiop:split-string - (car (last d 2)) :separator ".")))))) - (uiop:copy-file - (cadr d) - (path-join - hunchentoot:*tmp-directory* - (format nil "~a_~a.~a" first-name last-name - (cadr (uiop:split-string - (car (last d 2)) :separator "."))))) - (setf attachment path) - (uiop:println attachment))))) - (if (funcall mail-function post-data attachment) - (format nil "thankyou"))))))) + (hunchentoot:define-easy-handler (respond :uri uri) () + (setf (hunchentoot:content-type*) "plain/text") + (let* ((request-type (hunchentoot:request-method hunchentoot:*request*)) + (post-data (hunchentoot:post-parameters* hunchentoot:*request*)) + (attachment nil) + (first-name nil) + (last-name nil)) + (cond ((eq request-type :get) nil) + ((eq request-type :post) + (loop :for d :in post-data + :do (progn + (uiop:println d) + (if (string= "firstname" (car d)) + (progn + (uiop:println (cdr d)) + (setf first-name (cdr d)))) + (if (string= "lastname" (car d)) + (progn + (uiop:println (cdr d)) + (setf last-name (cdr d)))) + (if (string= "image" (car d)) + (let ((path (path-join + hunchentoot:*tmp-directory* + (format nil "~a_~a.~a" first-name last-name + (cadr (uiop:split-string + (car (last d 2)) :separator ".")))))) + (uiop:copy-file + (cadr d) + (path-join + hunchentoot:*tmp-directory* + (format nil "~a_~a.~a" first-name last-name + (cadr (uiop:split-string + (car (last d 2)) :separator "."))))) + (setf attachment path) + (uiop:println attachment))))) + (if (funcall mail-function post-data attachment) + (format nil "thankyou"))))))) (define-post-form-handler "/mt-form" 'mail-mt-form) (define-post-form-handler "/health-form" 'mail-health-form) +(define-post-form-handler "/camp-form" 'mail-camp-form) (defun main () (start-server 4242) diff --git a/tfcserver.asd b/tfcserver.asd index 4921738..a22491b 100644 --- a/tfcserver.asd +++ b/tfcserver.asd @@ -12,6 +12,7 @@ "bordeaux-threads" "spinneret" "lass" + "log4cl" "cl-smtp") ;; <== list of Quicklisp dependencies :components ((:module "src" :components