(defpackage #:kitchensink (:use #:cl) (:local-nicknames (#:wknd #:weekend))) (in-package #:kitchensink) (defparameter +fname+ "([^/]+)" "Match any ole character except /") (defclass file () ((name :reader name :initarg :name :initform (wknd::slot-required 'file 'name))) (:documentation "Serves files in the weekend/examples dir.") (:metaclass wknd::endpoint) (:method . :get) (:route-parts "file" +fname+) (:extractors :name)) (defun file-in-examples-dir (name) (merge-pathnames name (asdf:system-relative-pathname 'weekend "examples/"))) (defmethod wknd::handle ((req file)) (let ((file (file-in-examples-dir (name req)))) (unless (uiop:file-exists-p file) (wknd::not-found req)) (wknd:handle-static-file file (or (wknd:mime-type file) "text/plain")))) (defvar *identified-persons* nil) (defclass identify-form () () (:documentation "Page to serve an identify form") (:metaclass wknd::endpoint) (:method . :get) (:route-parts "identify") (:content-type . "text/html")) (defmethod wknd::handle ((req identify-form)) "
") (defclass hello () () (:documentation "A Page that just says hello.") (:metaclass wknd:endpoint) (:method . :get) (:route-parts "hello") (:content-type . "text/html")) (defmethod wknd:authenticate ((req hello)) (or (plusp (length (wknd:get-cookie "name"))) (wknd:endpoint-redirect 'identify-form))) (defmethod wknd::handle ((req hello)) (with-output-to-string (*standard-output*) (princ "") (format t "

hello ~a

" (wknd:get-cookie "name")) (princ ""))) (defclass identify () ((name :reader name :initarg :name :type string)) (:metaclass wknd::endpoint) (:method . :post) (:route-parts "identify")) (defmethod wknd::handle ((req identify)) (wknd:set-cookie "name" :value (name req)) (wknd:endpoint-redirect 'hello)) (defvar *server* (make-instance 'hunchentoot:easy-acceptor :port 8888)) (hunchentoot:start *server*)