From 01c9197114270d153308226a1588de78ed05ee29 Mon Sep 17 00:00:00 2001 From: Grant Shangreaux Date: Tue, 24 Jan 2023 21:34:57 -0600 Subject: Clean: reorganize and document some of endpoints.lisp --- endpoints.lisp | 57 +++++++++++++++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 24 deletions(-) diff --git a/endpoints.lisp b/endpoints.lisp index 4d8b85c..5c2a656 100644 --- a/endpoints.lisp +++ b/endpoints.lisp @@ -9,7 +9,40 @@ (defparameter +session-cookie-name+ "dnd-session") +;;; Endpoints that do not require a session: + +(defendpoint* :get "/" () () + (redirect-to "/tavern-door")) + +(defendpoint* :get "/tavern-door" () () + (doorkeeper)) + +(defendpoint* :post "/tavern-door" () () + (with-plist ((name :name)) (lzb:request-body) + (a:if-let ((hero (hero-known-as name))) + (a:when-let ((sesh (new-sesh hero))) + (lzb:set-response-cookie +session-cookie-name+ (session-id sesh) + :path "/" :domain "localhost") + (redirect-to "/tavern")) + (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) + (redirect-to "/tavern-door"))) + +;;; Endpoints that do require a session: + +(defendpoint* :get "/tavern" () () + (with-hero-session (hero) + (tavern hero))) + (defun redirect-to (location) + "Set the lazybones response header and response code for redirecting to LOCATION. +This procedure will error if lazybones:*request* is not currently bound." (setf (lzb:response-header :location) location (lzb:response-code) "303")) @@ -27,27 +60,3 @@ I.e. It should be called within the scope of a request handler." (let ((,hero (session-hero ,session))) ,@body) (redirect-to ,redirect)))) - -(defendpoint* :get "/godess-shrine" () () - (godess-shrine)) - -(defendpoint* :post "/godess-shrine" () () - (with-plist ((name :name)) (lzb:request-body) - (birth-from-the-goddess-loins name) - (redirect-to "/tavern-door"))) - -(defendpoint* :get "/tavern-door" () () - (doorkeeper)) - -(defendpoint* :post "/tavern-door" () () - (with-plist ((name :name)) (lzb:request-body) - (a:if-let ((hero (hero-known-as name))) - (a:when-let ((sesh (new-sesh hero))) - (lzb:set-response-cookie +session-cookie-name+ (session-id sesh) - :path "/" :domain "localhost") - (redirect-to "/tavern")) - (redirect-to "/tavern-door")))) - -(defendpoint* :get "/tavern" () () - (with-hero-session (hero) - (tavern hero))) -- cgit v1.2.3