0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-11 01:10:28 -05:00

Improve errors management on password change

This commit is contained in:
Jesús Espino 2016-04-10 20:27:25 +02:00 committed by Andrey Antukh
parent cb3a099fef
commit cc320215ac
No known key found for this signature in database
GPG key ID: 4DFEBCB8316A8B95
2 changed files with 16 additions and 7 deletions

View file

@ -40,5 +40,9 @@
"history.alert-message" "You are seeng version %s" "history.alert-message" "You are seeng version %s"
"errors.auth" "Username or passwords seems to be wrong." "errors.auth" "Username or passwords seems to be wrong."
"errors.update-password" "Error updating password, probably your old password is wrong."
"old-password-needed" "Old password needed."
"new-password-needed" "New password needed."
"password-too-short" "The new password is too short."
"password-doesnt-match" "The passwords doesn't match."
}) })

View file

@ -9,9 +9,11 @@
(:require [sablono.core :as html :refer-macros [html]] (:require [sablono.core :as html :refer-macros [html]]
[rum.core :as rum] [rum.core :as rum]
[cuerdas.core :as str] [cuerdas.core :as str]
[uxbox.locales :as t :refer (tr)]
[uxbox.router :as r] [uxbox.router :as r]
[uxbox.rstore :as rs] [uxbox.rstore :as rs]
[uxbox.ui.icons :as i] [uxbox.ui.icons :as i]
[uxbox.ui.messages :as uum]
[uxbox.ui.mixins :as mx] [uxbox.ui.mixins :as mx]
[uxbox.util.dom :as dom] [uxbox.util.dom :as dom]
[uxbox.data.users :as udu] [uxbox.data.users :as udu]
@ -22,12 +24,13 @@
(defn password-form-render (defn password-form-render
[own] [own]
(let [local (:rum/local own) (let [local (:rum/local own)
valid? (and (not (str/empty? (:password-1 @local))) invalid-reason (cond
(not (str/empty? (:password-2 @local))) (= 0 (count (:old-password @local))) "old-password-needed"
(= 6 (count (:password-1 @local ""))) (= 0 (count (:password-1 @local))) "new-password-needed"
(= (:password-1 @local) (> 6 (count (:password-1 @local ""))) "password-too-short"
(:password-2 @local)))] (not= (:password-1 @local) (:password-2 @local)) "password-doesnt-match"
(println "valid?" valid?) :else nil)
valid? (nil? invalid-reason)]
(letfn [(on-field-change [field event] (letfn [(on-field-change [field event]
(let [value (dom/event->value event)] (let [value (dom/event->value event)]
(swap! local assoc field value))) (swap! local assoc field value)))
@ -38,6 +41,7 @@
(html (html
[:form.password-form [:form.password-form
(uum/messages)
[:span.user-settings-label "Change password"] [:span.user-settings-label "Change password"]
[:input.input-text [:input.input-text
{:type "password" {:type "password"
@ -54,6 +58,7 @@
:value (:password-2 @local "") :value (:password-2 @local "")
:on-change (partial on-field-change :password-2) :on-change (partial on-field-change :password-2)
:placeholder "Confirm password"}] :placeholder "Confirm password"}]
(when-not valid? [:span (tr invalid-reason)])
[:input.btn-primary [:input.btn-primary
{:type "button" {:type "button"
:class (when-not valid? "btn-disabled") :class (when-not valid? "btn-disabled")