Commit 6c8b2f73 authored by amirouche's avatar amirouche

web: improve signup form

parent 8b459c71
......@@ -151,6 +151,7 @@ form input[type="password"] {
border: 1px solid hsla(0, 0%, 70%, 1);
border-radius: 2px;
background: white;
padding: 5px 10px;
form .error input[type="text"],
......@@ -173,18 +173,18 @@ exec guile -L $(pwd) -e '(@ (web) main)' -s "$0" "$@"
(loop (cdr alist) out)))))
(define (signup/template errors)
(let ((signin-error (assoc-ref errors "signin"))
(let ((username-error (assoc-ref errors "username"))
(password-error (assoc-ref errors "password"))
(confirmation-error (assoc-ref errors "confirmation")))
(template "signup"
`(form (@ (method "POST"))
(h2 "Sign up")
(div (@ (class ,(make-class `(("form-item" . #t)
("error" . ,signin-error)))))
(p (label "signin")
(input (@ (name "signin")
("error" . ,username-error)))))
(p (label "username")
(input (@ (name "username")
(type "text"))))
,(maybe-error signin-error))
,(maybe-error username-error))
(div (@ (class ,(make-class `(("form-item" . #t)
("error" . ,password-error)))))
(p (label "password")
......@@ -203,19 +203,23 @@ exec guile -L $(pwd) -e '(@ (web) main)' -s "$0" "$@"
(define (signup/get request)
(sxml->response (signup/template '())))
(define (signin-valid? signin)
(and (eq? (string-length (car signin)) 0)
"Password must be at least one character"))
(define (username-valid? username)
(and (or (not username)
(eq? (string-length (car username)) 0))
"username must be at least one character"))
(define (password-valid? password)
#t) ;; TODO
(and (not password)
;; TODO: implement password strength
"password is required"))
(define %signup `(("signin" . ,signin-valid?)
(define %signup `(("username" . ,username-valid?)
("password" . ,password-valid?)))
(define (signup/post request body)
(let ((form (decode body)))
(let ((errors (pk 'errors (validate %signup form))))
(let ((errors (validate %signup form)))
;; TODO: implement deep validation
(if (null? errors)
(redirect "/")
(sxml->response (signup/template errors))))))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment