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