X-Git-Url: http://git.pond.sub.org/?p=eow;a=blobdiff_plain;f=web.lisp;h=0f6a0c8966fed615898f2b3baa4a289d7233f063;hp=20e27510d2a67c37764967dd29b271b141479ee6;hb=f08c83a6016dddd28fd4acc9bb12c4350a40c004;hpb=ae10588ada2b32b3c715056b32c042fd221a534d diff --git a/web.lisp b/web.lisp index 20e2751..0f6a0c8 100644 --- a/web.lisp +++ b/web.lisp @@ -16,6 +16,7 @@ (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")) (defun string-starts-with (string prefix) ;; (from Hunchentoot) @@ -43,13 +44,35 @@ (defun prompt (minutes btus) (send (format nil "prompt(~a,~a);~%" minutes btus))) +(defun data (message) + (send (parenscript:ps* `(msg ,message)))) + +(defun login () + (let ((connection (session-value 'connection))) + (if connection + (redirect +root-url+) + (redirect +login-page+)))) + +;; destination of login-form +(defun login-action () + (let ((connection (empire:connect :user (post-parameter "username") + :password (post-parameter "password")))) + (setf (session-value 'connection) connection) + (redirect +root-url+))) + +(defun command-action () + (let ((connection (session-value 'connection))) + (empire:send-message connection (get-parameter "q")))) + (defun dispatch (request) (let ((script-name (script-name request))) (cond ((not (string-starts-with script-name +web-root+)) nil) ; do not handle this request ((string= script-name "/eow/update") 'update) + ((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+)) (redirect +root-url+)) ; go to the start page + (string-equal script-name +web-root+)) 'login) ; go to the start page ((string-starts-with script-name +static-web-root+) 'serve-static)))) ; serve static file