From: Gerd Flaig Date: Sat, 20 Dec 2008 21:19:40 +0000 (+0100) Subject: ensure session X-Git-Url: http://git.pond.sub.org/?p=eow;a=commitdiff_plain;h=cb4d7092bd39cb0dc6f39c15d6fda7ec2ae311b0 ensure session --- diff --git a/static/root.html b/static/root.html new file mode 100644 index 0000000..330cd79 --- /dev/null +++ b/static/root.html @@ -0,0 +1,39 @@ + + + +Empire Web Client + + + + + + + + +
+EOW alpha0 Empire/Ajax +
+
+Welcome to the Empire over the Web client (EOW). +
+
+
+
> +
+
+
+ +
+
+ Last modified: Sat Dec 20 22:16:28 CET 2008 + diff --git a/static/test.html b/static/test.html deleted file mode 100644 index 28f676c..0000000 --- a/static/test.html +++ /dev/null @@ -1,39 +0,0 @@ - - - -Empire Web Client - - - - - - - - -
-EOW alpha0 Empire/Ajax -
-
-Welcome to the Empire over the Web client (EOW). -
-
-
-
> -
-
-
- -
-
- Last modified: Sun Dec 14 23:04:50 CET 2008 - 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