diff options
author | colin <colin@cicadas.surf> | 2023-01-21 09:49:39 -0800 |
---|---|---|
committer | colin <colin@cicadas.surf> | 2023-01-21 09:49:39 -0800 |
commit | 6b1c9d7ae508c41848828939454945bf2addb994 (patch) | |
tree | 05210e5b7bc1735031ae3df0c7f75becdbe6b6e1 /routes.lisp | |
parent | b1c6b6ecf3476beb82f7b39516b94863e12c37f8 (diff) |
Refactor+Fix: with-hero-session macro; packaging and init
Diffstat (limited to 'routes.lisp')
-rw-r--r-- | routes.lisp | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/routes.lisp b/routes.lisp index b0b81ac..f737c80 100644 --- a/routes.lisp +++ b/routes.lisp @@ -13,10 +13,20 @@ (setf (lzb:response-header :location) location (lzb:response-code) "303")) -(defmacro with-session (&body body) - `(a:if-let ((sesh (session-with-id (lzb:request-cookie +session-cookie-name+)))) - ,@body - (redirect-to "/tavern-door"))) +(defun current-session () + "Get the session associated with the current request. Will throw an +error if lazybones:*request* is not currently bound. It will return +NIL if there is no session for the current request. + +I.e. It should be called within the scope of a request handler." + (session-with-id (lzb:request-cookie +session-cookie-name+ ))) + +(defmacro with-hero-session ((hero &key session (redirect "/tavern-door")) &body body) + (let ((session (or session (gensym "SESSION")))) + `(a:if-let (,session (current-session)) + (let ((,hero (session-hero ,session))) + ,@body) + (redirect-to ,redirect)))) (defendpoint* :get "/godess-shrine" () () (godess-shrine)) @@ -39,4 +49,5 @@ (redirect-to "/tavern-door")))) (defendpoint* :get "/tavern" () () - (with-session (tavern (session-hero sesh)))) + (with-hero-session (hero) + (tavern hero))) |