0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-20 13:55:34 -05:00

Don't send emails on recovery password on not verified profile.

And show proper message to the user saying that the profile
need to be verfied before proceed.
This commit is contained in:
Andrey Antukh 2021-02-03 23:47:19 +01:00 committed by Hirunatan
parent 992a8e9aef
commit 687f7ddf64
4 changed files with 55 additions and 29 deletions

View file

@ -403,11 +403,14 @@
:name (:fullname profile)}))] :name (:fullname profile)}))]
(db/with-atomic [conn pool] (db/with-atomic [conn pool]
(some->> email (when-let [profile (profile/retrieve-profile-data-by-email conn email)]
(profile/retrieve-profile-data-by-email conn) (when-not (:is-active profile)
(ex/raise :type :validation
:code :profile-not-verified
:hint "the user need to validate profile before recover password"))
(->> profile
(create-recovery-token) (create-recovery-token)
(send-email-notification conn)) (send-email-notification conn))))))
nil)))
;; --- Mutation: Recover Profile ;; --- Mutation: Recover Profile

View file

@ -173,6 +173,12 @@
"es" : "Introduce la nueva contraseña" "es" : "Introduce la nueva contraseña"
} }
}, },
"auth.notifications.profile-not-verified": {
"translations": {
"en": "Profile is not verified, please verify profile before continue.",
"es": "El perfil aun no ha sido validado, porfavor valide el perfil antes de continuar."
}
},
"auth.notifications.invalid-token-error" : { "auth.notifications.invalid-token-error" : {
"used-in" : [ "src/app/main/ui/auth/recovery.cljs:47" ], "used-in" : [ "src/app/main/ui/auth/recovery.cljs:47" ],
"translations" : { "translations" : {

View file

@ -184,10 +184,7 @@
(->> (rp/mutation :request-profile-recovery data) (->> (rp/mutation :request-profile-recovery data)
(rx/tap on-success) (rx/tap on-success)
(rx/catch (fn [err] (rx/catch on-error))))))
(on-error err)
(rx/empty))))))))
;; --- Recovery (Password) ;; --- Recovery (Password)

View file

@ -20,49 +20,69 @@
[app.util.router :as rt] [app.util.router :as rt]
[cljs.spec.alpha :as s] [cljs.spec.alpha :as s]
[cuerdas.core :as str] [cuerdas.core :as str]
[beicon.core :as rx]
[rumext.alpha :as mf])) [rumext.alpha :as mf]))
(s/def ::email ::us/email) (s/def ::email ::us/email)
(s/def ::recovery-request-form (s/keys :req-un [::email])) (s/def ::recovery-request-form (s/keys :req-un [::email]))
(defn- on-success
[]
(st/emit! (dm/info (tr "auth.notifications.recovery-token-sent"))
(rt/nav :auth-login)))
(defn- on-submit
[form event]
(let [params (with-meta (:clean-data @form)
{:on-success on-success})]
(st/emit! (uda/request-profile-recovery params))))
(mf/defc recovery-form (mf/defc recovery-form
[{:keys [locale] :as props}] []
(let [form (fm/use-form :spec ::recovery-request-form (let [form (fm/use-form :spec ::recovery-request-form
:initial {})] :initial {})
submitted (mf/use-state false)
on-error
(mf/use-callback
(fn [{:keys [code] :as error}]
(reset! submitted false)
(if (= code :profile-not-verified)
(rx/of (dm/error (tr "auth.notifications.profile-not-verified")
{:timeout nil}))
(rx/throw error))))
on-success
(mf/use-callback
(fn []
(reset! submitted false)
(st/emit! (dm/info (tr "auth.notifications.recovery-token-sent"))
(rt/nav :auth-login))))
on-submit
(mf/use-callback
(fn []
(reset! submitted true)
(->> (with-meta (:clean-data @form)
{:on-success on-success
:on-error on-error})
(uda/request-profile-recovery)
(st/emit!))))]
[:& fm/form {:on-submit on-submit [:& fm/form {:on-submit on-submit
:form form} :form form}
[:div.fields-row [:div.fields-row
[:& fm/input {:name :email [:& fm/input {:name :email
:label (t locale "auth.email") :label (tr "auth.email")
:help-icon i/at :help-icon i/at
:type "text"}]] :type "text"}]]
[:& fm/submit-button [:& fm/submit-button
{:label (t locale "auth.recovery-request-submit")}]])) {:label (tr "auth.recovery-request-submit")}]]))
;; --- Recovery Request Page ;; --- Recovery Request Page
(mf/defc recovery-request-page (mf/defc recovery-request-page
[{:keys [locale] :as props}] []
[:section.generic-form [:section.generic-form
[:div.form-container [:div.form-container
[:h1 (t locale "auth.recovery-request-title")] [:h1 (tr "auth.recovery-request-title")]
[:div.subtitle (t locale "auth.recovery-request-subtitle")] [:div.subtitle (tr "auth.recovery-request-subtitle")]
[:& recovery-form {:locale locale}] [:& recovery-form]
[:div.links [:div.links
[:div.link-entry [:div.link-entry
[:a {:on-click #(st/emit! (rt/nav :auth-login))} [:a {:on-click #(st/emit! (rt/nav :auth-login))}
(t locale "auth.go-back-to-login")]]]]]) (tr "auth.go-back-to-login")]]]]])