diff options
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))) |