X-Git-Url: http://git.pond.sub.org/?p=eow;a=blobdiff_plain;f=web.lisp;h=96aca61708bc8f95acd11d79255cc801ed9a980f;hp=e648f319f150cd1804c91ffddac05b5431c6a17e;hb=f17995f251724c7edce2660fc1f8a10b1e368a11;hpb=1bd48ef37e2267d788ab2721044d9d12129e9087 diff --git a/web.lisp b/web.lisp index e648f31..96aca61 100644 --- a/web.lisp +++ b/web.lisp @@ -11,12 +11,13 @@ :directory (pathname-directory *this-file*))) (defparameter +templates-root+ (namestring *this-dir*)) -(defparameter +root-url+ "/eow/static/test.html") +(defparameter +root-url+ "/eow/") (defparameter +web-root-base+ "/eow") (defparameter +web-root+ (concatenate 'string +web-root-base+ "/")) (defparameter +static-web-root+ (concatenate 'string +web-root+ "static/")) (defparameter +static-files-root+ (concatenate 'string +templates-root+ "static/")) (defparameter +login-page+ (concatenate 'string +static-web-root+ "login.html")) +(defparameter +root-page-file+ "root.html") (defun string-starts-with (string prefix) ;; (from Hunchentoot) @@ -52,10 +53,12 @@ (defgeneric prompt (session minutes btus)) (defgeneric data (session message)) +(defvar *session*) + (defun update () "Send stream of updates to client" - (let ((s (session-value `session))) - (locked-queue:dequeue (update-queue s)))) + (with-session + (locked-queue:dequeue (update-queue *session*)))) (defmethod send ((s session) string) "Push a javascript update fragment to the client." @@ -67,11 +70,11 @@ (defmethod data ((s session) message) (send s (parenscript:ps* `(msg ,message)))) -(defun login () - (let ((s (session-value 'session))) - (if s - (redirect +root-url+) - (redirect +login-page+)))) +(defmacro with-session (&body body) + `(let ((*session* (session-value 'session))) + (if *session* + (progn ,@body) + (redirect +login-page+)))) ;; destination of login-form (defun login-action () @@ -84,8 +87,12 @@ (format nil "Connection error: ~a~%" e)))) (defun command-action () - (let ((s (session-value 'session))) - (empire:send-message (connection s) (get-parameter "q")))) + (with-session + (empire:send-message (connection *session*) (get-parameter "q")))) + +(defun root-page () + (with-session + (handle-static-file (concatenate 'string +static-files-root+ +root-page-file+)))) (defun dispatch (request) (let ((script-name (script-name request))) @@ -95,7 +102,7 @@ ((string= script-name "/eow/login") 'login-action) ((string= script-name "/eow/command") 'command-action) ((or (string-equal script-name +web-root-base+) - (string-equal script-name +web-root+)) 'login) ; go to the start page + (string-equal script-name +web-root+)) 'root-page) ; go to the start page ((string-starts-with script-name +static-web-root+) 'serve-static)))) ; serve static file