summaryrefslogtreecommitdiff
path: root/routes.lisp
blob: b0b81acb1231b4352f75939e82c9fea6dbfb7efc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
;;;; routes.lisp -- http routes for dnd

(in-package :dnd)

(lzb:provision-app ()
  :title "Dungeons & Deadlines"
  :version "0.1.0"
  :content-type "text/html")

(defparameter +session-cookie-name+ "dnd-session")

(defun redirect-to (location)
  (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")))

(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-session (tavern (session-hero sesh))))