Skip to content

Commit

Permalink
Preserve input values on register validation [#427]
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy Chambers committed Jan 5, 2016
1 parent d7f9330 commit 363f57a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
5 changes: 4 additions & 1 deletion src/clojars/friend/registration.clj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
:pgp-key pgp-key}
(new-user-validations db confirm))]
(->
(response (register-form (apply concat (vals errors)) email username))
(response (register-form {:errors (apply concat (vals errors))
:email email
:username username
:pgp-key pgp-key}))
(content-type "text/html"))
(do (add-user db email username password pgp-key)
(workflow/make-auth {:identity username :username username}))))
Expand Down
4 changes: 2 additions & 2 deletions src/clojars/routes/user.clj
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
(auth/with-account
(view/update-profile db account params)))

(GET "/register" _
(view/register-form))
(GET "/register" {:keys [params]}
(view/register-form params))

(GET "/forgot-password" _
(view/forgot-password-form))
Expand Down
5 changes: 3 additions & 2 deletions src/clojars/web/user.clj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
[valip.core :refer [validate]]
[valip.predicates :as pred]))

(defn register-form [ & [errors email username pgp-key]]
(defn register-form [{:keys [errors email username pgp-key]}]
(html-doc nil "Register"
[:div.small-section
[:h1 "Register"]
Expand All @@ -29,7 +29,8 @@
:placeholder "[email protected]"}
:email)
(label :username "Username")
(text-field {:required true
(text-field {:value username
:required true
:placeholder "bob"}
:username)
(label :password "Password")
Expand Down
2 changes: 2 additions & 0 deletions test/clojars/test/integration/users.clj
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
(fill-in "Username" "dantheman")
(press "Register")
(has (status? 200))
(has (value? [:input#username] "dantheman"))
(has (value? [:input#email] "[email protected]"))
(within [:div.error :ul :li]
(has (text? "Password and confirm password must match")))

Expand Down

0 comments on commit 363f57a

Please sign in to comment.