summaryrefslogtreecommitdiff
path: root/endpoints.lisp
diff options
context:
space:
mode:
Diffstat (limited to 'endpoints.lisp')
-rw-r--r--endpoints.lisp57
1 files 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)))