mirror of
https://github.com/penpot/penpot.git
synced 2025-05-13 01:26:37 +02:00
✨ Improve error handling on ldap frontend code
This commit is contained in:
parent
ce790d83fd
commit
90022041e6
4 changed files with 57 additions and 35 deletions
|
@ -12,7 +12,6 @@
|
||||||
[app.db :as db]
|
[app.db :as db]
|
||||||
[app.http.session :as session]
|
[app.http.session :as session]
|
||||||
[app.loggers.audit :as-alias audit]
|
[app.loggers.audit :as-alias audit]
|
||||||
[app.main :as-alias main]
|
|
||||||
[app.rpc :as-alias rpc]
|
[app.rpc :as-alias rpc]
|
||||||
[app.rpc.commands.auth :as auth]
|
[app.rpc.commands.auth :as auth]
|
||||||
[app.rpc.commands.profile :as profile]
|
[app.rpc.commands.profile :as profile]
|
||||||
|
@ -73,7 +72,7 @@
|
||||||
(rph/with-meta {::audit/props (:props profile)
|
(rph/with-meta {::audit/props (:props profile)
|
||||||
::audit/profile-id (:id profile)})))
|
::audit/profile-id (:id profile)})))
|
||||||
|
|
||||||
(-> profile
|
(-> (profile/strip-private-attrs profile)
|
||||||
(rph/with-transform (session/create-fn cfg (:id profile)))
|
(rph/with-transform (session/create-fn cfg (:id profile)))
|
||||||
(rph/with-meta {::audit/props (:props profile)
|
(rph/with-meta {::audit/props (:props profile)
|
||||||
::audit/profile-id (:id profile)}))))))
|
::audit/profile-id (:id profile)}))))))
|
||||||
|
|
|
@ -231,8 +231,35 @@
|
||||||
(rx/observe-on :async)))))
|
(rx/observe-on :async)))))
|
||||||
(rx/catch on-error))))))
|
(rx/catch on-error))))))
|
||||||
|
|
||||||
|
(def ^:private schema:login-with-ldap
|
||||||
|
(sm/define
|
||||||
|
[:map
|
||||||
|
[:email ::sm/email]
|
||||||
|
[:password :string]]))
|
||||||
|
|
||||||
|
(defn login-with-ldap
|
||||||
|
[params]
|
||||||
|
|
||||||
|
(dm/assert!
|
||||||
|
"expected valid params"
|
||||||
|
(sm/check! schema:login-with-ldap params))
|
||||||
|
|
||||||
|
(ptk/reify ::login-with-ldap
|
||||||
|
ptk/WatchEvent
|
||||||
|
(watch [_ _ _]
|
||||||
|
(let [{:keys [on-error on-success]
|
||||||
|
:or {on-error rx/throw
|
||||||
|
on-success identity}} (meta params)]
|
||||||
|
(->> (rp/cmd! :login-with-ldap params)
|
||||||
|
(rx/tap on-success)
|
||||||
|
(rx/map (fn [profile]
|
||||||
|
(-> profile
|
||||||
|
(with-meta {::ev/source "login-with-ldap"})
|
||||||
|
(logged-in))))
|
||||||
|
(rx/catch on-error))))))
|
||||||
|
|
||||||
(defn login-from-token
|
(defn login-from-token
|
||||||
|
"Used mainly as flow continuation after token validation."
|
||||||
[{:keys [profile] :as tdata}]
|
[{:keys [profile] :as tdata}]
|
||||||
(ptk/reify ::login-from-token
|
(ptk/reify ::login-from-token
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
|
|
|
@ -42,6 +42,10 @@
|
||||||
{:type :warning
|
{:type :warning
|
||||||
:content (tr "auth.demo-warning")}])
|
:content (tr "auth.demo-warning")}])
|
||||||
|
|
||||||
|
(defn create-demo-profile
|
||||||
|
[]
|
||||||
|
(st/emit! (du/create-demo-profile)))
|
||||||
|
|
||||||
(defn- login-with-oidc
|
(defn- login-with-oidc
|
||||||
[event provider params]
|
[event provider params]
|
||||||
(dom/prevent-default event)
|
(dom/prevent-default event)
|
||||||
|
@ -60,28 +64,6 @@
|
||||||
:else
|
:else
|
||||||
(st/emit! (msg/error (tr "errors.generic"))))))))
|
(st/emit! (msg/error (tr "errors.generic"))))))))
|
||||||
|
|
||||||
(defn- login-with-ldap
|
|
||||||
[event params]
|
|
||||||
(dom/prevent-default event)
|
|
||||||
(dom/stop-propagation event)
|
|
||||||
(let [{:keys [on-error]} (meta params)]
|
|
||||||
(->> (rp/cmd! :login-with-ldap params)
|
|
||||||
(rx/subs! (fn [profile]
|
|
||||||
(if-let [token (:invitation-token profile)]
|
|
||||||
(st/emit! (rt/nav :auth-verify-token {} {:token token}))
|
|
||||||
(st/emit! (du/login-from-token {:profile profile}))))
|
|
||||||
(fn [{:keys [type code] :as error}]
|
|
||||||
(cond
|
|
||||||
(and (= type :restriction)
|
|
||||||
(= code :ldap-not-initialized))
|
|
||||||
(st/emit! (msg/error (tr "errors.ldap-disabled")))
|
|
||||||
|
|
||||||
(fn? on-error)
|
|
||||||
(on-error error)
|
|
||||||
|
|
||||||
:else
|
|
||||||
(st/emit! (msg/error (tr "errors.generic")))))))))
|
|
||||||
|
|
||||||
(s/def ::email ::us/email)
|
(s/def ::email ::us/email)
|
||||||
(s/def ::password ::us/not-empty-string)
|
(s/def ::password ::us/not-empty-string)
|
||||||
(s/def ::invitation-token ::us/not-empty-string)
|
(s/def ::invitation-token ::us/not-empty-string)
|
||||||
|
@ -114,6 +96,11 @@
|
||||||
(= :profile-blocked (:code cause)))
|
(= :profile-blocked (:code cause)))
|
||||||
(reset! error (tr "errors.profile-blocked"))
|
(reset! error (tr "errors.profile-blocked"))
|
||||||
|
|
||||||
|
(and (= :restriction (:type cause))
|
||||||
|
(= :ldap-not-initialized (:code cause)))
|
||||||
|
(st/emit! (msg/error (tr "errors.ldap-disabled")))
|
||||||
|
|
||||||
|
|
||||||
(and (= :restriction (:type cause))
|
(and (= :restriction (:type cause))
|
||||||
(= :admin-only-profile (:code cause)))
|
(= :admin-only-profile (:code cause)))
|
||||||
(reset! error (tr "errors.profile-blocked"))
|
(reset! error (tr "errors.profile-blocked"))
|
||||||
|
@ -130,9 +117,10 @@
|
||||||
(reset! error (tr "errors.generic")))))
|
(reset! error (tr "errors.generic")))))
|
||||||
|
|
||||||
on-success-default
|
on-success-default
|
||||||
|
(mf/use-fn
|
||||||
(fn [data]
|
(fn [data]
|
||||||
(when-let [token (:invitation-token data)]
|
(when-let [token (:invitation-token data)]
|
||||||
(st/emit! (rt/nav :auth-verify-token {} {:token token}))))
|
(st/emit! (rt/nav :auth-verify-token {} {:token token})))))
|
||||||
|
|
||||||
on-success
|
on-success
|
||||||
(fn [data]
|
(fn [data]
|
||||||
|
@ -153,11 +141,15 @@
|
||||||
(mf/use-callback
|
(mf/use-callback
|
||||||
(mf/deps form)
|
(mf/deps form)
|
||||||
(fn [event]
|
(fn [event]
|
||||||
|
(dom/prevent-default event)
|
||||||
|
(dom/stop-propagation event)
|
||||||
|
|
||||||
(reset! error nil)
|
(reset! error nil)
|
||||||
(let [params (:clean-data @form)]
|
(let [params (:clean-data @form)
|
||||||
(login-with-ldap event (with-meta params
|
params (with-meta params
|
||||||
{:on-error on-error
|
{:on-error on-error
|
||||||
:on-success on-success})))))
|
:on-success on-success})]
|
||||||
|
(st/emit! (du/login-with-ldap params)))))
|
||||||
|
|
||||||
on-recovery-request
|
on-recovery-request
|
||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
|
@ -308,5 +300,11 @@
|
||||||
[:& lk/link {:action go-register
|
[:& lk/link {:action go-register
|
||||||
:class (stl/css :register-link)
|
:class (stl/css :register-link)
|
||||||
:data-test "register-submit"}
|
:data-test "register-submit"}
|
||||||
(tr "auth.register-submit")]])]]))
|
(tr "auth.register-submit")]])]
|
||||||
|
|
||||||
|
(when (contains? cf/flags :demo-users)
|
||||||
|
[:div {:class (stl/css :link-entry :demo-account)}
|
||||||
|
[:span (tr "auth.create-demo-profile") " "]
|
||||||
|
[:& lk/link {:action create-demo-profile
|
||||||
|
:data-test "demo-account-link"}
|
||||||
|
(tr "auth.create-demo-account")]])]))
|
||||||
|
|
|
@ -154,7 +154,7 @@
|
||||||
[:*
|
[:*
|
||||||
[:hr {:class (stl/css :separator)}]
|
[:hr {:class (stl/css :separator)}]
|
||||||
[:div {:class (stl/css :demo-account)}
|
[:div {:class (stl/css :demo-account)}
|
||||||
[:& lk/link {:action #(st/emit! (du/create-demo-profile))
|
[:& lk/link {:action login/create-demo-profile
|
||||||
:class (stl/css :demo-account-link)}
|
:class (stl/css :demo-account-link)}
|
||||||
(tr "auth.create-demo-account")]]])]])
|
(tr "auth.create-demo-account")]]])]])
|
||||||
|
|
||||||
|
@ -265,5 +265,3 @@
|
||||||
[:div {:class (stl/css :notification-text)} (tr "auth.verification-email-sent")]
|
[:div {:class (stl/css :notification-text)} (tr "auth.verification-email-sent")]
|
||||||
[:div {:class (stl/css :notification-text-email)} (:email params "")]
|
[:div {:class (stl/css :notification-text-email)} (:email params "")]
|
||||||
[:div {:class (stl/css :notification-text)} (tr "auth.check-your-email")]])
|
[:div {:class (stl/css :notification-text)} (tr "auth.check-your-email")]])
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue