diff options
author | Griffin Smith <grfn@gws.fyi> | 2020-07-24T00·53-0400 |
---|---|---|
committer | glittershark <grfn@gws.fyi> | 2020-07-24T16·41+0000 |
commit | 3e033637b449c23388ea793c05a61e1fe501767a (patch) | |
tree | a184c6d9d3c49519b48001ef71227b3a89625f4d /web/panettone/src/panettone.lisp | |
parent | 156c68698b4f0a153dce3c3027c3de7a980aeaee (diff) |
feat(web/panettone): Add a Log Out link to the footer r/1454
Generalize the rendering of the footer nav, and add a Log Out button to the right. Change-Id: I107e2370fd8f12949218ecacb611649a48abd738 Reviewed-on: https://cl.tvl.fyi/c/depot/+/1413 Tested-by: BuildkiteCI Reviewed-by: tazjin <mail@tazj.in>
Diffstat (limited to 'web/panettone/src/panettone.lisp')
-rw-r--r-- | web/panettone/src/panettone.lisp | 51 |
1 files changed, 37 insertions, 14 deletions
diff --git a/web/panettone/src/panettone.lisp b/web/panettone/src/panettone.lisp index 9cb0a8ef56d2..14010b8aa8d0 100644 --- a/web/panettone/src/panettone.lisp +++ b/web/panettone/src/panettone.lisp @@ -174,16 +174,39 @@ updated issue" (defvar *title* "Panettone") +(defvar *user* nil) + (setf (who:html-mode) :HTML5) -(defmacro render (&body body) +(defun render/footer-nav (&rest extra) + (who:with-html-output (*standard-output*) + (:footer + (:nav + (if (find (hunchentoot:request-uri*) + (list "/" "/issues/closed") + :test #'string=) + (who:htm (:span :class "placeholder")) + (who:htm (:a :href "/" "All Issues"))) + (if *user* + (who:htm + (:form :class "form-link log-out" + :method "post" + :action "/logout" + (:input :type "submit" :value "Log Out"))) + (who:htm + (:a :href "/login" "Log In"))))))) + +(defmacro render ((&key (footer t)) &body body) `(who:with-html-output-to-string (*standard-output* nil :prologue t) (:head (:title (who:esc *title*)) (:link :rel "stylesheet" :type "text/css" :href "/main.css")) (:body - (:div :class "content" - ,@body)))) + (:div + :class "content" + ,@body + (when ,footer + (render/footer-nav)))))) (defun render/alert (message) "Render an alert box for MESSAGE, if non-null" @@ -193,7 +216,7 @@ updated issue" (who:htm (:div :class "alert" (who:esc message)))))) (defun render/login (&key message (original-uri "/")) - (render + (render (:footer nil) (:div :class "login-form" (:header @@ -262,7 +285,7 @@ updated issue" (format nil "~A comment~:p" num-comments)))))))))))))) (defun render/index (&key issues) - (render + (render () (:header (:h1 "Issues") (:a @@ -275,7 +298,7 @@ updated issue" (render/issue-list :issues issues)))) (defun render/closed-issues (&key issues) - (render + (render () (:header (:h1 "Closed issues")) (:main @@ -285,7 +308,7 @@ updated issue" (render/issue-list :issues issues)))) (defun render/new-issue (&optional message) - (render + (render () (:header (:h1 "New Issue")) (:main @@ -324,7 +347,7 @@ updated issue" (check-type issue issue) (let ((issue-id (get-id issue)) (issue-status (status issue))) - (render + (render () (:header (:h1 (who:esc (subject issue))) (:div :class "issue-number" @@ -365,20 +388,16 @@ updated issue" (who:esc (displayname author)) " at " (who:esc (format-dottime (created-at comment))))))))) - (render/new-comment (get-id issue)))))) - (:footer - (:nav (:a :href "/" "All Issues")))))) + (render/new-comment (get-id issue))))))))) (defun render/not-found (entity-type) - (render + (render () (:h1 (who:esc entity-type) "Not Found"))) ;;; ;;; HTTP handlers ;;; -(defvar *user* nil) - (defun @auth (next) (if-let ((*user* (hunchentoot:session-value 'user))) (funcall next) @@ -402,6 +421,10 @@ updated issue" (hunchentoot:redirect (or original-uri "/"))) (render/login :message "Invalid credentials"))) +(defroute logout ("/logout" :method :post) () + (hunchentoot:delete-session-value 'user) + (hunchentoot:redirect "/")) + (defroute index ("/" :decorators (@auth)) () (let ((issues (open-issues *p-system*))) (render/index :issues issues))) |