mirror of
https://github.com/penpot/penpot.git
synced 2025-05-07 23:35:53 +02:00
✨ Auto login after email verify.
This commit is contained in:
parent
a9b7cf61a5
commit
e607e8315c
2 changed files with 25 additions and 16 deletions
|
@ -44,20 +44,29 @@
|
||||||
claims)
|
claims)
|
||||||
|
|
||||||
(defmethod process-token :verify-email
|
(defmethod process-token :verify-email
|
||||||
[{:keys [conn] :as cfg} _params {:keys [profile-id] :as claims}]
|
[{:keys [conn session] :as cfg} _params {:keys [profile-id] :as claims}]
|
||||||
(let [profile (db/get-by-id conn :profile profile-id {:for-update true})]
|
(let [profile (profile/retrieve-profile conn profile-id)
|
||||||
(when (:is-active profile)
|
claims (assoc claims :profile profile)]
|
||||||
(ex/raise :type :validation
|
|
||||||
:code :email-already-validated))
|
(when-not (:is-active profile)
|
||||||
(when (not= (:email profile)
|
(when (not= (:email profile)
|
||||||
(:email claims))
|
(:email claims))
|
||||||
(ex/raise :type :validation
|
(ex/raise :type :validation
|
||||||
:code :invalid-token))
|
:code :invalid-token))
|
||||||
|
|
||||||
|
(db/update! conn :profile
|
||||||
|
{:is-active true}
|
||||||
|
{:id (:id profile)}))
|
||||||
|
|
||||||
|
(with-meta claims
|
||||||
|
{:transform-response
|
||||||
|
(fn [request response]
|
||||||
|
(let [uagent (get-in request [:headers "user-agent"])
|
||||||
|
id (session/create! session {:profile-id profile-id
|
||||||
|
:user-agent uagent})]
|
||||||
|
(assoc response
|
||||||
|
:cookies (session/cookies session {:value id}))))})))
|
||||||
|
|
||||||
(db/update! conn :profile
|
|
||||||
{:is-active true}
|
|
||||||
{:id (:id profile)})
|
|
||||||
claims))
|
|
||||||
|
|
||||||
(defmethod process-token :auth
|
(defmethod process-token :auth
|
||||||
[{:keys [conn] :as cfg} _params {:keys [profile-id] :as claims}]
|
[{:keys [conn] :as cfg} _params {:keys [profile-id] :as claims}]
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
;; This Source Code Form is "Incompatible With Secondary Licenses", as
|
;; This Source Code Form is "Incompatible With Secondary Licenses", as
|
||||||
;; defined by the Mozilla Public License, v. 2.0.
|
;; defined by the Mozilla Public License, v. 2.0.
|
||||||
;;
|
;;
|
||||||
;; Copyright (c) 2020 UXBOX Labs SL
|
;; Copyright (c) 2020-2021 UXBOX Labs SL
|
||||||
|
|
||||||
(ns app.main.ui.auth.verify-token
|
(ns app.main.ui.auth.verify-token
|
||||||
(:require
|
(:require
|
||||||
|
@ -21,9 +21,9 @@
|
||||||
[app.main.ui.auth.register :refer [register-page]]
|
[app.main.ui.auth.register :refer [register-page]]
|
||||||
[app.main.ui.icons :as i]
|
[app.main.ui.icons :as i]
|
||||||
[app.util.forms :as fm]
|
[app.util.forms :as fm]
|
||||||
[app.util.storage :refer [cache]]
|
|
||||||
[app.util.i18n :as i18n :refer [tr t]]
|
[app.util.i18n :as i18n :refer [tr t]]
|
||||||
[app.util.router :as rt]
|
[app.util.router :as rt]
|
||||||
|
[app.util.storage :refer [cache]]
|
||||||
[app.util.timers :as ts]
|
[app.util.timers :as ts]
|
||||||
[beicon.core :as rx]
|
[beicon.core :as rx]
|
||||||
[cljs.spec.alpha :as s]
|
[cljs.spec.alpha :as s]
|
||||||
|
@ -35,7 +35,7 @@
|
||||||
[data]
|
[data]
|
||||||
(let [msg (tr "dashboard.notifications.email-verified-successfully")]
|
(let [msg (tr "dashboard.notifications.email-verified-successfully")]
|
||||||
(ts/schedule 100 #(st/emit! (dm/success msg)))
|
(ts/schedule 100 #(st/emit! (dm/success msg)))
|
||||||
(st/emit! (rt/nav :auth-login))))
|
(st/emit! (da/login-from-token data))))
|
||||||
|
|
||||||
(defmethod handle-token :change-email
|
(defmethod handle-token :change-email
|
||||||
[data]
|
[data]
|
||||||
|
|
Loading…
Add table
Reference in a new issue