From 25c1854c8306d4550c0ced886cbd36cb43099129 Mon Sep 17 00:00:00 2001 From: Grant Shoshin Shangreaux Date: Sat, 21 Jan 2023 09:08:08 -0600 Subject: Add: initial draft of doorkeeper session management --- routes.lisp | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) (limited to 'routes.lisp') diff --git a/routes.lisp b/routes.lisp index b1d4ff7..b0b81ac 100644 --- a/routes.lisp +++ b/routes.lisp @@ -9,14 +9,22 @@ (defparameter +session-cookie-name+ "dnd-session") -(defendpoint* :get "/a-hero-is-born" () () - (a-hero-is-born)) +(defun redirect-to (location) + (setf (lzb:response-header :location) location + (lzb:response-code) "303")) -(defendpoint* :post "/a-hero-is-born" () () +(defmacro with-session (&body body) + `(a:if-let ((sesh (session-with-id (lzb:request-cookie +session-cookie-name+)))) + ,@body + (redirect-to "/tavern-door"))) + +(defendpoint* :get "/godess-shrine" () () + (godess-shrine)) + +(defendpoint* :post "/godess-shrine" () () (with-plist ((name :name)) (lzb:request-body) (birth-from-the-goddess-loins name) - (setf (lzb:response-header :location) "/tavern-door" - (lzb:response-code) "303"))) + (redirect-to "/tavern-door"))) (defendpoint* :get "/tavern-door" () () (doorkeeper)) @@ -27,18 +35,8 @@ (a:when-let ((sesh (new-sesh hero))) (lzb:set-response-cookie +session-cookie-name+ (session-id sesh) :path "/" :domain "localhost") - (setf (lzb:response-header :location) "/tavern" - (lzb:response-code) "303")) - (setf (lzb:response-header :location) "/tavern-door" - (lzb:response-code) "303")))) + (redirect-to "/tavern")) + (redirect-to "/tavern-door")))) (defendpoint* :get "/tavern" () () - (let ((hero (session-hero (session-with-id (lzb:request-cookie +session-cookie-name+))))) - (tavern hero))) - -(defun birth-from-the-goddess-loins (name) - (db:with-transaction () - (make-instance 'hero :name name))) - -(defun new-sesh (hero) - (db:with-transaction () (make-instance 'session :hero hero))) + (with-session (tavern (session-hero sesh)))) -- cgit v1.2.3