diff options
author | Grant Shoshin Shangreaux <shoshin@cicadas.surf> | 2023-01-07 11:12:15 -0600 |
---|---|---|
committer | Grant Shoshin Shangreaux <shoshin@cicadas.surf> | 2023-01-07 11:12:15 -0600 |
commit | aee7f487f97c10c15b6c7b48156cc95db19d9137 (patch) | |
tree | 9ccdb9b7a3e356ed39f2ed71b2d04b7e2718df20 | |
parent | 9a040d4e78ab07eb9c482a40042f2ba92d2a8e3b (diff) |
First Draft of hero creation and login
-rw-r--r-- | DEV.org | 16 | ||||
-rw-r--r-- | api.lisp | 25 | ||||
-rw-r--r-- | dnd.lisp | 8 | ||||
-rw-r--r-- | model.lisp | 10 | ||||
-rw-r--r-- | package.lisp | 8 | ||||
-rw-r--r-- | pages.lisp | 30 | ||||
-rw-r--r-- | routes.lisp | 38 | ||||
-rw-r--r-- | serialization.lisp | 13 |
8 files changed, 105 insertions, 43 deletions
@@ -0,0 +1,16 @@ +* Four fings for wargfood +** DONE Make Heroes + - [X] route to serve the form + - [X] form to enter a name + - [X] route handler to take the post & persist object +** DONE Enter the tavern + - [X] Wot's Yer Name, Fella? (make the form) + - [X] handle post (set a cookie/header) + - [X] make a tavern page +** TODO Make Campaigns +** TODO Make Monsters (in campaigns) +** TODO Attack Monsters (assign heroes / change status) + +* More fings for wargfood +** TODO Setup Auth / User Reg +** TODO Deploy diff --git a/api.lisp b/api.lisp deleted file mode 100644 index cecacb4..0000000 --- a/api.lisp +++ /dev/null @@ -1,25 +0,0 @@ -;;;; api.lisp -- http routes for dnd - -(in-package :dnd) - -(lzb:provision-app (api) - :title "Dungeons & Deadlines" - :version "0.1.0" - :prefix "/api" - :content-type "application/json" - :auth 'default-auth) - -(defun default-auth (&rest ignore) - (declare (ignore ignore)) - t) - - - -(defendpoint* :get "/hall-of-legends" ((filter-by identity)) - (:auth t) - "Get a list of heros sorted by renown" - (json:to-json - (list :heroes - (sort (copy-seq (db:store-objects-with-class 'hero)) - #'> - :key #'renown)))) @@ -1,3 +1,11 @@ ;;;; dnd.lisp (in-package #:dnd) + +(defvar *dnd-arena* nil + "The instance of the HTTP server") + +(defun conjure-arena () + (setf *dnd-arena* (lzb:create-server)) + (lzb:install-app *dnd-arena* (lzb:app)) + (lzb:start-server *dnd-arena*)) @@ -62,6 +62,16 @@ :documentation "Salt for this hero's password hash.")) (:metaclass db:persistent-class)) +;; TODO expiration? +(defclass session (db:store-object) + ((hero :reader session-hero + :initarg :hero) + (id :reader session-id + :initform (nuid) + :index-type idx:string-unique-index + :index-reader session-with-id)) + (:metaclass db:persistent-class)) + ;; aka an issue ;; (defclass monster (can-equip has-uid) ;; ((name) diff --git a/package.lisp b/package.lisp index 2c7bff8..a844c56 100644 --- a/package.lisp +++ b/package.lisp @@ -6,10 +6,14 @@ (#:idx #:bknr.indices) (#:lzb #:lazybones) (#:re #:cl-ppcre) - (#:json #:jonathan)) + (#:json #:jonathan) + (#:a #:alexandria-2)) (:import-from #:lazybones #:defendpoint*) (:import-from #:derrida - #:with-plist)) + #:with-plist) + (:import-from #:spinneret + #:with-html + #:with-html-string)) diff --git a/pages.lisp b/pages.lisp new file mode 100644 index 0000000..7bbf48b --- /dev/null +++ b/pages.lisp @@ -0,0 +1,30 @@ +;;;; pages.lisp -- html generation functions for dnd + +(defmacro with-page ((&key title) &body body) + `(with-html-string + (:doctype) + (:html + (:head + (:title ,title)) + (:body ,@body)))) + +(defun a-hero-is-born () + (with-page (:title "A Hero Is Born!") + (:header + (:h1 "A Hero Is Materializing From the Void...")) + (:form :method "POST" :action "/a-hero-is-born" + (:label :for "NAME" "Thy Hero's Appelation") + (:input :name "NAME") + (:button :type "submit")))) + +(defun doorkeeper () + (with-page (:title "Tavern Door") + (:h1 "Wot's yer name 'ero?") + (:form :method "POST" :action "/tavern-door" + (:label :for "NAME" "Thy Hero's Appelation") + (:input :name "NAME") + (:button :type "submit")))) + +(defun tavern (hero) + (with-page (:title "A Bustling Tavern") + (:h1 "Aye! Welcome " (hero-name hero)))) diff --git a/routes.lisp b/routes.lisp index 56b6191..b1d4ff7 100644 --- a/routes.lisp +++ b/routes.lisp @@ -2,11 +2,43 @@ (in-package :dnd) -(lzb:provision-app (api) +(lzb:provision-app () :title "Dungeons & Deadlines" :version "0.1.0" - :prefix "/api" - :content-type "application/json") + :content-type "text/html") +(defparameter +session-cookie-name+ "dnd-session") +(defendpoint* :get "/a-hero-is-born" () () + (a-hero-is-born)) +(defendpoint* :post "/a-hero-is-born" () () + (with-plist ((name :name)) (lzb:request-body) + (birth-from-the-goddess-loins name) + (setf (lzb:response-header :location) "/tavern-door" + (lzb:response-code) "303"))) + +(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") + (setf (lzb:response-header :location) "/tavern" + (lzb:response-code) "303")) + (setf (lzb:response-header :location) "/tavern-door" + (lzb:response-code) "303")))) + +(defendpoint* :get "/tavern" () () + (let ((hero (session-hero (session-with-id (lzb:request-cookie +session-cookie-name+))))) + (tavern hero))) + +(defun birth-from-the-goddess-loins (name) + (db:with-transaction () + (make-instance 'hero :name name))) + +(defun new-sesh (hero) + (db:with-transaction () (make-instance 'session :hero hero))) diff --git a/serialization.lisp b/serialization.lisp deleted file mode 100644 index 6579b92..0000000 --- a/serialization.lisp +++ /dev/null @@ -1,13 +0,0 @@ -;;;; serialization.lisp - - - -(in-package :dnd) - -(defun hall-of-fame-hero-view (hero) - (json:to-json - (list :name (hero-name hero) - :uid (uid hero) - :renown (renown hero) - :title (hero-title hero) - :class (hero-class hero)))) |