about summary refs log tree commit diff
path: root/web/panettone
diff options
context:
space:
mode:
authorGriffin Smith <grfn@gws.fyi>2020-07-23T23·59-0400
committerglittershark <grfn@gws.fyi>2020-07-24T15·50+0000
commited8fed5baab5f06beb5bc85b414dff58a119b7b3 (patch)
treec21c95db50e4604d0c251c7f85817f51b64eeef4 /web/panettone
parent3ce4a6cc18b233da69b5e2e193ba88677baed34f (diff)
feat(web/panettone): Redirect to original URI after login r/1452
Once the user authenticates, redirect them to the original URI they were
trying to get to

Fixes: #7
Change-Id: Id7c8cbe3547923f6c4c5faed180ea8ea6528fddd
Reviewed-on: https://cl.tvl.fyi/c/depot/+/1411
Tested-by: BuildkiteCI
Reviewed-by: kanepyork <rikingcoding@gmail.com>
Diffstat (limited to 'web/panettone')
-rw-r--r--web/panettone/default.nix1
-rw-r--r--web/panettone/src/panettone.lisp25
2 files changed, 17 insertions, 9 deletions
diff --git a/web/panettone/default.nix b/web/panettone/default.nix
index b954bcec67ac..2de000b7e852 100644
--- a/web/panettone/default.nix
+++ b/web/panettone/default.nix
@@ -6,6 +6,7 @@ depot.nix.buildLisp.program {
   deps = with depot.third_party.lisp; [
     cl-prevalence
     cl-who
+    drakma
     defclass-std
     easy-routes
     hunchentoot
diff --git a/web/panettone/src/panettone.lisp b/web/panettone/src/panettone.lisp
index 026d47825f37..c49dc63c6c35 100644
--- a/web/panettone/src/panettone.lisp
+++ b/web/panettone/src/panettone.lisp
@@ -192,7 +192,7 @@ updated issue"
     (when message
       (who:htm (:div :class "alert" (who:esc message))))))
 
-(defun render/login (&optional message)
+(defun render/login (&key message (original-uri "/"))
   (render
     (:div
      :class "login-form"
@@ -203,6 +203,8 @@ updated issue"
       (render/alert message)
       (:form
        :method :post :action "/login"
+       (:input :type "hidden" :name "original-uri"
+               :value original-uri)
        (:div
         (:label :for "username"
                 "Username")
@@ -378,20 +380,25 @@ updated issue"
 (defun @auth (next)
   (if-let ((*user* (hunchentoot:session-value 'user)))
     (funcall next)
-    (hunchentoot:redirect "/login")))
-
-(defroute login-form ("/login" :method :get) ()
+    (hunchentoot:redirect
+     (format nil "/login?original-uri=~A"
+             (drakma:url-encode
+              (hunchentoot:request-uri*)
+              :utf-8)))))
+
+(defroute login-form ("/login" :method :get)
+    (original-uri)
   (if (hunchentoot:session-value 'user)
-      (hunchentoot:redirect "/")
-      (render/login)))
+      (hunchentoot:redirect (or original-uri "/"))
+      (render/login :original-uri original-uri)))
 
 (defroute submit-login ("/login" :method :post)
-    (&post username password)
+    (&post original-uri username password)
   (if-let ((user (authenticate-user username password)))
     (progn
       (setf (hunchentoot:session-value 'user) user)
-      (hunchentoot:redirect "/"))
-    (render/login "Invalid credentials")))
+      (hunchentoot:redirect (or original-uri "/")))
+    (render/login :message "Invalid credentials")))
 
 (defroute index ("/" :decorators (@auth)) ()
   (let ((issues (open-issues *p-system*)))