From 202f3e1cabb5b8e7e8812d418d53dbeac32c4d1a Mon Sep 17 00:00:00 2001 From: Colin Okay Date: Mon, 31 Oct 2022 07:02:21 -0500 Subject: Better name validation --- new-account.lisp | 52 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/new-account.lisp b/new-account.lisp index ea265a7..653818a 100644 --- a/new-account.lisp +++ b/new-account.lisp @@ -2,24 +2,31 @@ (in-package :vampire) +(defparameter +username-regex+ + (ppcre:create-scanner "^[a-zA-Z0-9\_\\-!@#$^&*]{3,25}$")) + + + (defun new-accout-page (body) (include-style body) (with-clog-create body - (div () - (section (:h2 :content "Create a new account")) - (form () - (form-element (:text :bind invite)) - (span (:bind invite-status)) - (br ()) - (form-element (:text :bind name)) - (span (:bind name-status)) - (br ()) - (form-element (:password :bind pw)) - (br ()) - (form-element (:password :bind pw-confirm)) - (span (:bind pw-confirm-status)) - (br ()) - (button (:content "Make Account" :bind submit)))) + (div (:class "row") + (div () (section (:h2 :content "Create a new account")) + (form (:bind new-user-form) + (form-element (:text :bind invite)) + (span (:bind invite-status)) + (br ()) + (form-element (:text :bind name)) + (span (:bind name-status)) + (br ()) + (form-element (:password :bind pw)) + (br ()) + (form-element (:password :bind pw-confirm)) + (span (:bind pw-confirm-status)) + (br ()) + (button (:content "Make Account" :bind submit)))) + (div (:bind name-help :hidden t) + (p (:content "3-25 characters, no spaces, numbers, letters, or !@#$^&*()_-")))) (setf (place-holder invite) "Invite Code" (place-holder name) "Name" @@ -36,10 +43,18 @@ (set-on-blur name (thunk* + (let ((name (value name))) (setf (text name-status) - (if (user-with-name name) - "Name Already Taken" - "✔")))) + (cond + ((not (ppcre:all-matches +username-regex+ name)) + (setf (visiblep name-help) t) + "Invalid Name.") + ((user-with-name name) + (setf (visiblep name-help) nil) + "Name Already Taken") + (t + (setf (visiblep name-help) nil) + "✔")))))) (set-on-key-press pw-confirm @@ -49,7 +64,6 @@ "✔" "Passwords Do Not Match")))) - (set-on-click submit (thunk* -- cgit v1.2.3