mirror of
https://github.com/penpot/penpot.git
synced 2025-06-23 22:06:59 +02:00
🐛 Fix regression on singup flow
Move all params handling to prepare-register, just for consistency
This commit is contained in:
parent
10ae4dd3f7
commit
8b0ead6832
3 changed files with 47 additions and 49 deletions
|
@ -231,13 +231,14 @@
|
||||||
:hint "email has complaint reports")))
|
:hint "email has complaint reports")))
|
||||||
|
|
||||||
(defn prepare-register
|
(defn prepare-register
|
||||||
[{:keys [::db/pool] :as cfg} {:keys [email accept-newsletter-updates] :as params}]
|
[{:keys [::db/pool] :as cfg} {:keys [fullname email accept-newsletter-updates] :as params}]
|
||||||
|
|
||||||
(validate-register-attempt! cfg params)
|
(validate-register-attempt! cfg params)
|
||||||
|
|
||||||
(let [email (profile/clean-email email)
|
(let [email (profile/clean-email email)
|
||||||
profile (profile/get-profile-by-email pool email)
|
profile (profile/get-profile-by-email pool email)
|
||||||
params {:email email
|
params {:email email
|
||||||
|
:fullname fullname
|
||||||
:password (:password params)
|
:password (:password params)
|
||||||
:invitation-token (:invitation-token params)
|
:invitation-token (:invitation-token params)
|
||||||
:backend "penpot"
|
:backend "penpot"
|
||||||
|
@ -254,8 +255,10 @@
|
||||||
|
|
||||||
(def schema:prepare-register-profile
|
(def schema:prepare-register-profile
|
||||||
[:map {:title "prepare-register-profile"}
|
[:map {:title "prepare-register-profile"}
|
||||||
|
[:fullname ::sm/text]
|
||||||
[:email ::sm/email]
|
[:email ::sm/email]
|
||||||
[:password schema:password]
|
[:password schema:password]
|
||||||
|
[:create-welcome-file {:optional true} :boolean]
|
||||||
[:invitation-token {:optional true} schema:token]])
|
[:invitation-token {:optional true} schema:token]])
|
||||||
|
|
||||||
(sv/defmethod ::prepare-register-profile
|
(sv/defmethod ::prepare-register-profile
|
||||||
|
@ -359,13 +362,9 @@
|
||||||
:extra-data ptoken})))
|
:extra-data ptoken})))
|
||||||
|
|
||||||
(defn register-profile
|
(defn register-profile
|
||||||
[{:keys [::db/conn ::wrk/executor] :as cfg} {:keys [token fullname theme] :as params}]
|
[{:keys [::db/conn ::wrk/executor] :as cfg} {:keys [token] :as params}]
|
||||||
(let [theme (when (= theme "light") theme)
|
(let [claims (tokens/verify (::setup/props cfg) {:token token :iss :prepared-register})
|
||||||
claims (tokens/verify (::setup/props cfg) {:token token :iss :prepared-register})
|
params (into claims params)
|
||||||
params (-> claims
|
|
||||||
(into params)
|
|
||||||
(assoc :fullname fullname)
|
|
||||||
(assoc :theme theme))
|
|
||||||
|
|
||||||
profile (if-let [profile-id (:profile-id claims)]
|
profile (if-let [profile-id (:profile-id claims)]
|
||||||
(profile/get-profile conn profile-id)
|
(profile/get-profile conn profile-id)
|
||||||
|
@ -479,10 +478,7 @@
|
||||||
|
|
||||||
(def schema:register-profile
|
(def schema:register-profile
|
||||||
[:map {:title "register-profile"}
|
[:map {:title "register-profile"}
|
||||||
[:token schema:token]
|
[:token schema:token]])
|
||||||
[:fullname [::sm/word-string {:max 100}]]
|
|
||||||
[:theme {:optional true} [:string {:max 10}]]
|
|
||||||
[:create-welcome-file {:optional true} :boolean]])
|
|
||||||
|
|
||||||
(sv/defmethod ::register-profile
|
(sv/defmethod ::register-profile
|
||||||
{::rpc/auth false
|
{::rpc/auth false
|
||||||
|
|
|
@ -379,15 +379,14 @@
|
||||||
(t/deftest prepare-register-and-register-profile-1
|
(t/deftest prepare-register-and-register-profile-1
|
||||||
(let [data {::th/type :prepare-register-profile
|
(let [data {::th/type :prepare-register-profile
|
||||||
:email "user@example.com"
|
:email "user@example.com"
|
||||||
|
:fullname "foobar"
|
||||||
:password "foobar"}
|
:password "foobar"}
|
||||||
out (th/command! data)
|
out (th/command! data)
|
||||||
token (get-in out [:result :token])]
|
token (get-in out [:result :token])]
|
||||||
(t/is (string? token))
|
(t/is (string? token))
|
||||||
|
|
||||||
;; try register without token
|
;; try register without token
|
||||||
(let [data {::th/type :register-profile
|
(let [data {::th/type :register-profile}
|
||||||
:fullname "foobar"
|
|
||||||
:accept-terms-and-privacy true}
|
|
||||||
out (th/command! data)]
|
out (th/command! data)]
|
||||||
;; (th/print-result! out)
|
;; (th/print-result! out)
|
||||||
(let [error (:error out)]
|
(let [error (:error out)]
|
||||||
|
@ -398,11 +397,8 @@
|
||||||
;; try correct register
|
;; try correct register
|
||||||
(let [data {::th/type :register-profile
|
(let [data {::th/type :register-profile
|
||||||
:token token
|
:token token
|
||||||
:fullname "foobar"
|
|
||||||
:utm_campaign "utma"
|
:utm_campaign "utma"
|
||||||
:mtm_campaign "mtma"
|
:mtm_campaign "mtma"}]
|
||||||
:accept-terms-and-privacy true
|
|
||||||
:accept-newsletter-subscription true}]
|
|
||||||
(let [{:keys [result error]} (th/command! data)]
|
(let [{:keys [result error]} (th/command! data)]
|
||||||
(t/is (nil? error))))
|
(t/is (nil? error))))
|
||||||
|
|
||||||
|
@ -424,6 +420,7 @@
|
||||||
;; PREPARE REGISTER
|
;; PREPARE REGISTER
|
||||||
(let [data {::th/type :prepare-register-profile
|
(let [data {::th/type :prepare-register-profile
|
||||||
:email "hello@example.com"
|
:email "hello@example.com"
|
||||||
|
:fullname "foobar"
|
||||||
:password "foobar"}
|
:password "foobar"}
|
||||||
out (th/command! data)
|
out (th/command! data)
|
||||||
token (get-in out [:result :token])]
|
token (get-in out [:result :token])]
|
||||||
|
@ -432,10 +429,7 @@
|
||||||
|
|
||||||
;; DO REGISTRATION
|
;; DO REGISTRATION
|
||||||
(let [data {::th/type :register-profile
|
(let [data {::th/type :register-profile
|
||||||
:token @current-token
|
:token @current-token}
|
||||||
:fullname "foobar"
|
|
||||||
:accept-terms-and-privacy true
|
|
||||||
:accept-newsletter-subscription true}
|
|
||||||
out (th/command! data)]
|
out (th/command! data)]
|
||||||
(t/is (nil? (:error out)))
|
(t/is (nil? (:error out)))
|
||||||
(t/is (= 1 (:call-count @mock))))
|
(t/is (= 1 (:call-count @mock))))
|
||||||
|
@ -445,6 +439,7 @@
|
||||||
;; PREPARE REGISTER: second attempt
|
;; PREPARE REGISTER: second attempt
|
||||||
(let [data {::th/type :prepare-register-profile
|
(let [data {::th/type :prepare-register-profile
|
||||||
:email "hello@example.com"
|
:email "hello@example.com"
|
||||||
|
:fullname "foobar"
|
||||||
:password "foobar"}
|
:password "foobar"}
|
||||||
out (th/command! data)
|
out (th/command! data)
|
||||||
token (get-in out [:result :token])]
|
token (get-in out [:result :token])]
|
||||||
|
@ -479,6 +474,7 @@
|
||||||
;; PREPARE REGISTER
|
;; PREPARE REGISTER
|
||||||
(let [data {::th/type :prepare-register-profile
|
(let [data {::th/type :prepare-register-profile
|
||||||
:email "hello@example.com"
|
:email "hello@example.com"
|
||||||
|
:fullname "foobar"
|
||||||
:password "foobar"}
|
:password "foobar"}
|
||||||
out (th/command! data)
|
out (th/command! data)
|
||||||
token (get-in out [:result :token])]
|
token (get-in out [:result :token])]
|
||||||
|
@ -487,10 +483,7 @@
|
||||||
|
|
||||||
;; DO REGISTRATION
|
;; DO REGISTRATION
|
||||||
(let [data {::th/type :register-profile
|
(let [data {::th/type :register-profile
|
||||||
:token @current-token
|
:token @current-token}
|
||||||
:fullname "foobar"
|
|
||||||
:accept-terms-and-privacy true
|
|
||||||
:accept-newsletter-subscription true}
|
|
||||||
out (th/command! data)]
|
out (th/command! data)]
|
||||||
(t/is (nil? (:error out)))
|
(t/is (nil? (:error out)))
|
||||||
(t/is (= 1 (:call-count @mock))))
|
(t/is (= 1 (:call-count @mock))))
|
||||||
|
@ -504,6 +497,7 @@
|
||||||
;; PREPARE REGISTER: second attempt
|
;; PREPARE REGISTER: second attempt
|
||||||
(let [data {::th/type :prepare-register-profile
|
(let [data {::th/type :prepare-register-profile
|
||||||
:email "hello@example.com"
|
:email "hello@example.com"
|
||||||
|
:fullname "foobar"
|
||||||
:password "foobar"}
|
:password "foobar"}
|
||||||
out (th/command! data)
|
out (th/command! data)
|
||||||
token (get-in out [:result :token])]
|
token (get-in out [:result :token])]
|
||||||
|
@ -514,10 +508,7 @@
|
||||||
:return true}]
|
:return true}]
|
||||||
;; DO REGISTRATION: second attempt
|
;; DO REGISTRATION: second attempt
|
||||||
(let [data {::th/type :register-profile
|
(let [data {::th/type :register-profile
|
||||||
:token @current-token
|
:token @current-token}
|
||||||
:fullname "foobar"
|
|
||||||
:accept-terms-and-privacy true
|
|
||||||
:accept-newsletter-subscription true}
|
|
||||||
out (th/command! data)]
|
out (th/command! data)]
|
||||||
(t/is (nil? (:error out)))
|
(t/is (nil? (:error out)))
|
||||||
(t/is (= 0 (:call-count @mock))))))))
|
(t/is (= 0 (:call-count @mock))))))))
|
||||||
|
@ -532,6 +523,7 @@
|
||||||
:member-email "user@example.com"})
|
:member-email "user@example.com"})
|
||||||
data {::th/type :prepare-register-profile
|
data {::th/type :prepare-register-profile
|
||||||
:invitation-token itoken
|
:invitation-token itoken
|
||||||
|
:fullname "foobar"
|
||||||
:email "user@example.com"
|
:email "user@example.com"
|
||||||
:password "foobar"}
|
:password "foobar"}
|
||||||
|
|
||||||
|
@ -542,8 +534,7 @@
|
||||||
|
|
||||||
(let [rtoken (:token result)
|
(let [rtoken (:token result)
|
||||||
data {::th/type :register-profile
|
data {::th/type :register-profile
|
||||||
:token rtoken
|
:token rtoken}
|
||||||
:fullname "foobar"}
|
|
||||||
|
|
||||||
{:keys [result error] :as out} (th/command! data)]
|
{:keys [result error] :as out} (th/command! data)]
|
||||||
;; (th/print-result! out)
|
;; (th/print-result! out)
|
||||||
|
@ -563,6 +554,7 @@
|
||||||
data {::th/type :prepare-register-profile
|
data {::th/type :prepare-register-profile
|
||||||
:invitation-token itoken
|
:invitation-token itoken
|
||||||
:email "user@example.com"
|
:email "user@example.com"
|
||||||
|
:fullname "foobar"
|
||||||
:password "foobar"}
|
:password "foobar"}
|
||||||
out (th/command! data)]
|
out (th/command! data)]
|
||||||
|
|
||||||
|
@ -582,6 +574,7 @@
|
||||||
:member-email "user@example.com"})
|
:member-email "user@example.com"})
|
||||||
data {::th/type :prepare-register-profile
|
data {::th/type :prepare-register-profile
|
||||||
:invitation-token itoken
|
:invitation-token itoken
|
||||||
|
:fullname "foobar"
|
||||||
:email "user@example.com"
|
:email "user@example.com"
|
||||||
:password "foobar"}
|
:password "foobar"}
|
||||||
out (th/command! data)]
|
out (th/command! data)]
|
||||||
|
@ -604,6 +597,7 @@
|
||||||
data {::th/type :prepare-register-profile
|
data {::th/type :prepare-register-profile
|
||||||
:invitation-token itoken
|
:invitation-token itoken
|
||||||
:email "user@example.com"
|
:email "user@example.com"
|
||||||
|
:fullname "foobar"
|
||||||
:password "foobar"}
|
:password "foobar"}
|
||||||
out (th/command! data)]
|
out (th/command! data)]
|
||||||
|
|
||||||
|
@ -624,6 +618,7 @@
|
||||||
|
|
||||||
data {::th/type :prepare-register-profile
|
data {::th/type :prepare-register-profile
|
||||||
:invitation-token itoken
|
:invitation-token itoken
|
||||||
|
:fullname "foobar"
|
||||||
:email "user@example.com"
|
:email "user@example.com"
|
||||||
:password "foobar"}
|
:password "foobar"}
|
||||||
out (th/command! data)]
|
out (th/command! data)]
|
||||||
|
@ -636,6 +631,7 @@
|
||||||
(t/deftest prepare-register-with-registration-disabled
|
(t/deftest prepare-register-with-registration-disabled
|
||||||
(with-redefs [app.config/flags #{}]
|
(with-redefs [app.config/flags #{}]
|
||||||
(let [data {::th/type :prepare-register-profile
|
(let [data {::th/type :prepare-register-profile
|
||||||
|
:fullname "foobar"
|
||||||
:email "user@example.com"
|
:email "user@example.com"
|
||||||
:password "foobar"}
|
:password "foobar"}
|
||||||
out (th/command! data)]
|
out (th/command! data)]
|
||||||
|
@ -648,6 +644,7 @@
|
||||||
(t/deftest prepare-register-with-existing-user
|
(t/deftest prepare-register-with-existing-user
|
||||||
(let [profile (th/create-profile* 1)
|
(let [profile (th/create-profile* 1)
|
||||||
data {::th/type :prepare-register-profile
|
data {::th/type :prepare-register-profile
|
||||||
|
:fullname "foobar"
|
||||||
:email (:email profile)
|
:email (:email profile)
|
||||||
:password "foobar"}
|
:password "foobar"}
|
||||||
out (th/command! data)]
|
out (th/command! data)]
|
||||||
|
@ -660,6 +657,7 @@
|
||||||
|
|
||||||
(let [pool (:app.db/pool th/*system*)
|
(let [pool (:app.db/pool th/*system*)
|
||||||
data {::th/type :prepare-register-profile
|
data {::th/type :prepare-register-profile
|
||||||
|
:fullname "foobar"
|
||||||
:email "user@example.com"
|
:email "user@example.com"
|
||||||
:password "foobar"}]
|
:password "foobar"}]
|
||||||
|
|
||||||
|
@ -674,6 +672,7 @@
|
||||||
(t/deftest register-profile-with-complained-email
|
(t/deftest register-profile-with-complained-email
|
||||||
(let [pool (:app.db/pool th/*system*)
|
(let [pool (:app.db/pool th/*system*)
|
||||||
data {::th/type :prepare-register-profile
|
data {::th/type :prepare-register-profile
|
||||||
|
:fullname "foobar"
|
||||||
:email "user@example.com"
|
:email "user@example.com"
|
||||||
:password "foobar"}]
|
:password "foobar"}]
|
||||||
|
|
||||||
|
@ -688,6 +687,7 @@
|
||||||
|
|
||||||
(t/deftest register-profile-with-email-as-password
|
(t/deftest register-profile-with-email-as-password
|
||||||
(let [data {::th/type :prepare-register-profile
|
(let [data {::th/type :prepare-register-profile
|
||||||
|
:fullname "foobar"
|
||||||
:email "user@example.com"
|
:email "user@example.com"
|
||||||
:password "USER@example.com"}
|
:password "USER@example.com"}
|
||||||
out (th/command! data)]
|
out (th/command! data)]
|
||||||
|
|
|
@ -82,7 +82,7 @@
|
||||||
|
|
||||||
on-error
|
on-error
|
||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
(fn [form cause]
|
(fn [cause]
|
||||||
(let [{:keys [type code] :as edata} (ex-data cause)]
|
(let [{:keys [type code] :as edata} (ex-data cause)]
|
||||||
(condp = [type code]
|
(condp = [type code]
|
||||||
[:restriction :registration-disabled]
|
[:restriction :registration-disabled]
|
||||||
|
@ -101,7 +101,10 @@
|
||||||
(swap! form assoc-in [:errors :password]
|
(swap! form assoc-in [:errors :password]
|
||||||
{:message (tr "errors.email-as-password")})
|
{:message (tr "errors.email-as-password")})
|
||||||
|
|
||||||
(st/emit! (ntf/error (tr "errors.generic")))))))
|
(do
|
||||||
|
(when-let [explain (get edata :explain)]
|
||||||
|
(println explain))
|
||||||
|
(st/emit! (ntf/error (tr "errors.generic"))))))))
|
||||||
|
|
||||||
on-success
|
on-success
|
||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
|
@ -109,10 +112,9 @@
|
||||||
(fn [params]
|
(fn [params]
|
||||||
(if (fn? on-success-callback)
|
(if (fn? on-success-callback)
|
||||||
(on-success-callback (:email params))
|
(on-success-callback (:email params))
|
||||||
|
|
||||||
(cond
|
(cond
|
||||||
(some? (:token params))
|
(some? (:invitation-token params))
|
||||||
(let [token (:token params)]
|
(let [token (:invitation-token params)]
|
||||||
(st/emit! (rt/nav :auth-verify-token {:token token})))
|
(st/emit! (rt/nav :auth-verify-token {:token token})))
|
||||||
|
|
||||||
(:is-active params)
|
(:is-active params)
|
||||||
|
@ -126,25 +128,25 @@
|
||||||
on-register-profile
|
on-register-profile
|
||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
(mf/deps on-success on-error)
|
(mf/deps on-success on-error)
|
||||||
(fn [form]
|
(fn [params]
|
||||||
(reset! submitted? true)
|
(reset! submitted? true)
|
||||||
(let [create-welcome-file?
|
|
||||||
(cf/external-feature-flag "onboarding-03" "test")
|
|
||||||
|
|
||||||
params
|
|
||||||
(cond-> form
|
|
||||||
create-welcome-file? (assoc :create-welcome-file true))]
|
|
||||||
(->> (rp/cmd! :register-profile params)
|
(->> (rp/cmd! :register-profile params)
|
||||||
(rx/subs! on-success on-error #(reset! submitted? false))))))
|
(rx/subs! on-success on-error #(reset! submitted? false)))))
|
||||||
|
|
||||||
on-submit
|
on-submit
|
||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
(mf/deps on-success-callback)
|
(mf/deps on-success-callback)
|
||||||
(fn [form _event]
|
(fn [form _event]
|
||||||
(reset! submitted? true)
|
(reset! submitted? true)
|
||||||
(let [cdata (:clean-data @form)]
|
(let [create-welcome-file?
|
||||||
|
(cf/external-feature-flag "onboarding-03" "test")
|
||||||
|
|
||||||
|
cdata
|
||||||
|
(cond-> (:clean-data @form)
|
||||||
|
create-welcome-file?
|
||||||
|
(assoc :create-welcome-file true))]
|
||||||
|
|
||||||
(->> (rp/cmd! :prepare-register-profile cdata)
|
(->> (rp/cmd! :prepare-register-profile cdata)
|
||||||
(rx/map #(merge % cdata))
|
|
||||||
(rx/finalize #(reset! submitted? false))
|
(rx/finalize #(reset! submitted? false))
|
||||||
(rx/subs! on-register-profile)))))]
|
(rx/subs! on-register-profile)))))]
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue