about summary refs log tree commit diff
path: root/web/panettone/src/panettone.lisp
diff options
context:
space:
mode:
authorGriffin Smith <grfn@gws.fyi>2020-07-23T22·42-0400
committerglittershark <grfn@gws.fyi>2020-07-23T22·53+0000
commit6bdd191cbf440506abc0440bba732dc41ee4996f (patch)
tree03b013d85b4d653358d29aec7c414bf9e22c8181 /web/panettone/src/panettone.lisp
parentd8a0bd9e75876d04642aba450a724dc426f3f4b8 (diff)
fix(web/panettone): Fix failure on invalid username r/1446
Handle if the username submitted to the login form is one of a
nonexistent user, rather than returning a 500

Fixes: #1
Change-Id: Iebc68dea3c91dc928e4386cb172d3c1515fb1556
Reviewed-on: https://cl.tvl.fyi/c/depot/+/1402
Tested-by: BuildkiteCI
Reviewed-by: kanepyork <rikingcoding@gmail.com>
Diffstat (limited to 'web/panettone/src/panettone.lisp')
-rw-r--r--web/panettone/src/panettone.lisp22
1 files changed, 11 insertions, 11 deletions
diff --git a/web/panettone/src/panettone.lisp b/web/panettone/src/panettone.lisp
index b654dc1d6a87..b8e5d350795e 100644
--- a/web/panettone/src/panettone.lisp
+++ b/web/panettone/src/panettone.lisp
@@ -81,17 +81,17 @@
   "Checks the given USER-OR-USERNAME has the given PASSWORD, by making a bind
 request against the ldap server at *ldap*. Returns the user if authentication is
 successful, `nil' otherwise"
-  (let* ((user (if (typep user-or-username 'user) user-or-username
-                   (find-user user-or-username)))
-         (dn (dn user)))
-    (multiple-value-bind (_r code-sym _msg)
-        (ldap:bind
-         (ldap:new-ldap :host (ldap:host *ldap*)
-                        :port (ldap:port *ldap*)
-                        :user dn
-                        :pass password))
-      (when (equalp code-sym 'trivial-ldap:success)
-        user))))
+  (when-let ((user (if (typep user-or-username 'user) user-or-username
+                       (find-user user-or-username))))
+    (let ((dn (dn user)))
+      (multiple-value-bind (_r code-sym _msg)
+          (ldap:bind
+           (ldap:new-ldap :host (ldap:host *ldap*)
+                          :port (ldap:port *ldap*)
+                          :user dn
+                          :pass password))
+        (when (equalp code-sym 'trivial-ldap:success)
+          user)))))
 
 (defun author (object)
   (find-user-by-dn (author-dn object)))