Making the tfc-api in lisp use ningle rather than raw hunchentoot
This commit is contained in:
parent
038b813a0b
commit
228626b65d
15
flake.nix
15
flake.nix
|
@ -28,6 +28,9 @@
|
||||||
cl_plus_ssl
|
cl_plus_ssl
|
||||||
fiveam
|
fiveam
|
||||||
slite
|
slite
|
||||||
|
clack
|
||||||
|
woo
|
||||||
|
ningle
|
||||||
pkgs.openssl
|
pkgs.openssl
|
||||||
pkgs.openssl.out
|
pkgs.openssl.out
|
||||||
pkgs.openssl.dev
|
pkgs.openssl.dev
|
||||||
|
@ -68,7 +71,17 @@
|
||||||
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
devShell = import ./shell.nix { inherit pkgs; };
|
devShell = pkgs.mkShell {
|
||||||
|
name = "tfc-api";
|
||||||
|
version = "0.0.1";
|
||||||
|
src = src;
|
||||||
|
nativeBuildInputs = nbi;
|
||||||
|
buildInputs = bi;
|
||||||
|
nativeLibs = nativeLibs;
|
||||||
|
shellHook = ''
|
||||||
|
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${pkgs.lib.makeLibraryPath nativeLibs}"
|
||||||
|
'';
|
||||||
|
};
|
||||||
packages.default = pkgs.rustPlatform.buildRustPackage {
|
packages.default = pkgs.rustPlatform.buildRustPackage {
|
||||||
pname = "api";
|
pname = "api";
|
||||||
version = "0.0.1";
|
version = "0.0.1";
|
||||||
|
|
|
@ -78,7 +78,7 @@
|
||||||
// Can now start using this in production IF,
|
// Can now start using this in production IF,
|
||||||
// I get the server running on the server
|
// I get the server running on the server
|
||||||
/* let base = "https://api.tfcconnection.org/health-form"; */
|
/* let base = "https://api.tfcconnection.org/health-form"; */
|
||||||
let base = "http://localhost:4242/health-form";
|
let base = "http://localhost:5000/health-form";
|
||||||
fetch(base, {
|
fetch(base, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: data
|
body: data
|
||||||
|
@ -217,7 +217,7 @@
|
||||||
|
|
||||||
<div id="health-form" class="form text-lg w-full">
|
<div id="health-form" class="form text-lg w-full">
|
||||||
<form id='form'
|
<form id='form'
|
||||||
hx-post="https://tfcconnection.org/api/health-form"
|
hx-post="http://localhost:5000/health-form"
|
||||||
hx-encoding="multipart/form-data"
|
hx-encoding="multipart/form-data"
|
||||||
autocomplete="on"
|
autocomplete="on"
|
||||||
method="post"
|
method="post"
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
(asdf:load-system 'cl-smtp)
|
(asdf:load-system 'cl-smtp)
|
||||||
(asdf:load-system 'log4cl)
|
(asdf:load-system 'log4cl)
|
||||||
(asdf:load-system 'fiveam)
|
(asdf:load-system 'fiveam)
|
||||||
|
(asdf:load-system 'clack)
|
||||||
|
(asdf:load-system 'ningle)
|
||||||
|
|
||||||
(defpackage tfcserver
|
(defpackage tfcserver
|
||||||
(:use :cl :com.inuoe.jzon :spinneret :serapeum))
|
(:use :cl :com.inuoe.jzon :spinneret :serapeum))
|
||||||
|
@ -16,12 +18,7 @@
|
||||||
|
|
||||||
(log:config :daily "/tmp/tfc-%Y%m%d.log")
|
(log:config :daily "/tmp/tfc-%Y%m%d.log")
|
||||||
|
|
||||||
(defvar *server*)
|
(defvar *app* (make-instance 'ningle:app))
|
||||||
(defun start-server (port)
|
|
||||||
(setq *server*
|
|
||||||
(hunchentoot:start
|
|
||||||
(make-instance 'hunchentoot:easy-acceptor
|
|
||||||
:port port))))
|
|
||||||
|
|
||||||
(defparameter *mail-css*
|
(defparameter *mail-css*
|
||||||
'((table :border-collapse "collapse" :width "100%")
|
'((table :border-collapse "collapse" :width "100%")
|
||||||
|
@ -406,7 +403,7 @@ with the image attached"
|
||||||
(not (cl-smtp:send-email
|
(not (cl-smtp:send-email
|
||||||
"mail.tfcconnection.org"
|
"mail.tfcconnection.org"
|
||||||
"no-reply@mail.tfcconnection.org"
|
"no-reply@mail.tfcconnection.org"
|
||||||
'("chris@tfcconnection.org" "ethan@tfcconnection.org")
|
'("chris@tfcconnection.org")
|
||||||
(format nil "~a ~a filled out a Health Form!" first-name last-name)
|
(format nil "~a ~a filled out a Health Form!" first-name last-name)
|
||||||
(format nil "Health Form for ~a ~a" first-name last-name)
|
(format nil "Health Form for ~a ~a" first-name last-name)
|
||||||
:display-name "TFC ADMIN"
|
:display-name "TFC ADMIN"
|
||||||
|
@ -430,48 +427,42 @@ with the image attached"
|
||||||
"-" (car row) " ")))
|
"-" (car row) " ")))
|
||||||
(:td (cdr row))))))))))))
|
(:td (cdr row))))))))))))
|
||||||
|
|
||||||
(tbnl:define-easy-handler (health-form :uri "/health-form") ()
|
(setf (ningle:route *app* "/health-form" :method :post)
|
||||||
(setf (tbnl:header-out :access-control-expose-headers) "*")
|
#'(lambda (params)
|
||||||
(let* ((data (tbnl:post-parameters* tbnl:*request*))
|
(log:info params)
|
||||||
(registration (cdr (assoc "registration" data :test 'string=)))
|
(let* ((image-element (assoc "image" params :test 'string=))
|
||||||
(image (cdr (assoc "image" data :test 'string=)))
|
(registration (cdr (assoc "registration" params :test 'string=)))
|
||||||
(first-name (cdr (assoc "first-name" data :test 'string=)))
|
(first-name (cdr (assoc "first-name" params :test 'string=)))
|
||||||
(last-name (cdr (assoc "last-name" data :test 'string=)))
|
(last-name (cdr (assoc "last-name" params :test 'string=)))
|
||||||
(image (cdr (assoc "image" data :test 'string=)))
|
(image (nth 1 image-element))
|
||||||
(attachment nil))
|
(filename (nth 2 image-element)))
|
||||||
(loop :for d :in data
|
(serapeum:write-stream-into-file
|
||||||
:do (progn
|
image (pathname "frodo.jpg")
|
||||||
(if (string= "first-name" (car d))
|
:if-exists :supersede
|
||||||
(progn
|
:if-does-not-exist :create)
|
||||||
(setf first-name (cdr d))))
|
(log:info filename)
|
||||||
(if (string= "last-name" (car d))
|
(bt:make-thread
|
||||||
(progn
|
(lambda ()
|
||||||
(setf last-name (cdr d))))
|
(mail-health-form params (pathname filename))
|
||||||
(if (string= "image" (car d))
|
(log:info "Sent email"))
|
||||||
(let ((path (path-join
|
:name "health-form")
|
||||||
hunchentoot:*tmp-directory*
|
(setf (lack.response:response-headers ningle:*response*)
|
||||||
(format nil "~a_~a.~a" first-name last-name
|
(append (lack.response:response-headers ningle:*response*)
|
||||||
(cadr (uiop:split-string
|
(list :access-control-expose-headers "*")))
|
||||||
(car (last d 2)) :separator "."))))))
|
(log:info registration)
|
||||||
(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)
|
|
||||||
(log:info attachment)))))
|
|
||||||
(log:info data)
|
|
||||||
(when data
|
|
||||||
(mail-health-form data attachment)
|
|
||||||
(cond ((string= registration "now")
|
(cond ((string= registration "now")
|
||||||
(log:info "Sending them to pay now")
|
(log:info "Sending them to pay now")
|
||||||
(setf (hunchentoot:header-out :HX-Redirect) "https://secure.myvanco.com/L-Z772/campaign/C-13JPJ"))
|
(setf (lack.response:response-headers ningle:*response*)
|
||||||
|
(append (lack.response:response-headers ningle:*response*)
|
||||||
|
(list :hx-redirect
|
||||||
|
"https://secure.myvanco.com/L-Z772/campaign/C-13JPJ"))))
|
||||||
((string= registration "full")
|
((string= registration "full")
|
||||||
(log:info "Sending them to pay full amount")
|
(log:info "Sending them to pay full amount")
|
||||||
(setf (tbnl:header-out :HX-Redirect) "https://secure.myvanco.com/L-Z772/campaign/C-13JQE"))
|
(setf (lack.response:response-headers ningle:*response*)
|
||||||
((string= registration "later")
|
(append (lack.response:response-headers ningle:*response*)
|
||||||
|
(list :hx-redirect
|
||||||
|
"https://secure.myvanco.com/L-Z772/campaign/C-13JQE"))))
|
||||||
|
(t
|
||||||
(log:info "Sending the health form thank you snippet")
|
(log:info "Sending the health form thank you snippet")
|
||||||
(with-html-string
|
(with-html-string
|
||||||
(:div
|
(:div
|
||||||
|
|
Loading…
Reference in a new issue