From ffa213f6f825479df7b544f23d1240dd1c86f10f Mon Sep 17 00:00:00 2001 From: Grant Shangreaux Date: Tue, 24 Jan 2023 22:02:17 -0600 Subject: Add: doorkeeper :message param to pass info to user Basic handling for when a hero name is entered but does not exist in the store. The /tavern-door endpoint will parse a NAME query param and the doorkeeper says they've never heard of them. --- dnd.asd | 3 ++- endpoints.lisp | 11 ++++++++--- pages.lisp | 4 ++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/dnd.asd b/dnd.asd index d192838..bd4c74b 100644 --- a/dnd.asd +++ b/dnd.asd @@ -17,7 +17,8 @@ #:parenscript #:derrida #:ironclad - #:jonathan) + #:jonathan + #:quri) :components ((:file "package") (:file "utilities") (:file "init") diff --git a/endpoints.lisp b/endpoints.lisp index 5c2a656..19be125 100644 --- a/endpoints.lisp +++ b/endpoints.lisp @@ -14,8 +14,9 @@ (defendpoint* :get "/" () () (redirect-to "/tavern-door")) -(defendpoint* :get "/tavern-door" () () - (doorkeeper)) +(defendpoint* :get "/tavern-door" ((name str)) () + (if name (doorkeeper :message (format nil "M'fraid I've n'er 'eard o' ~a." name)) + (doorkeeper))) (defendpoint* :post "/tavern-door" () () (with-plist ((name :name)) (lzb:request-body) @@ -24,7 +25,7 @@ (lzb:set-response-cookie +session-cookie-name+ (session-id sesh) :path "/" :domain "localhost") (redirect-to "/tavern")) - (redirect-to "/tavern-door")))) + (redirect-to (format nil "/tavern-door?name=~a" (quri:url-encode name)))))) (defendpoint* :get "/godess-shrine" () () (godess-shrine)) @@ -40,6 +41,10 @@ (with-hero-session (hero) (tavern hero))) +(defun str (string) + "A String" + string) + (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." diff --git a/pages.lisp b/pages.lisp index 9ae2de9..7f705cd 100644 --- a/pages.lisp +++ b/pages.lisp @@ -19,9 +19,9 @@ (:input :name "NAME") (:button :type "submit" "Pray To The Goddess")))) -(defun doorkeeper () +(defun doorkeeper (&key (message "Wot's yer name 'ero?")) (with-page (:title "Tavern Door") - (:h1 "Wot's yer name 'ero?") + (:h1 message) (:form :method "POST" :action "/tavern-door" (:label :for "NAME" "Thy Hero's Appelation:") (:input :name "NAME") -- cgit v1.2.3