]> git.pond.sub.org Git - eow/blobdiff - web.lisp
Initial working command line
[eow] / web.lisp
index 093769224ec938c3d91b3669e6250be4ec0959fc..0f6a0c8966fed615898f2b3baa4a289d7233f063 100644 (file)
--- 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)
   "Push a javascript update fragment to the client."
   (locked-queue:enqueue *update-queue* string))
 
+(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