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:
parent
cb3a099fef
commit
cc320215ac
2 changed files with 16 additions and 7 deletions
|
@ -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."
|
||||
})
|
||||
|
|
|
@ -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")
|
||||
|
|
Loading…
Reference in a new issue