mirror of
https://github.com/penpot/penpot.git
synced 2025-05-10 16:36:38 +02:00
✨ Add :insecure-register flag.
This allows on-premise users skip the email validation.
This commit is contained in:
parent
bf2a393fd3
commit
e7003dde83
10 changed files with 79 additions and 60 deletions
|
@ -268,10 +268,17 @@
|
||||||
::telemetry-with-taiga
|
::telemetry-with-taiga
|
||||||
::tenant]))
|
::tenant]))
|
||||||
|
|
||||||
|
(def default-flags
|
||||||
|
[:enable-backend-asserts
|
||||||
|
:enable-backend-api-doc
|
||||||
|
:enable-insecure-register
|
||||||
|
:enable-secure-session-cookies])
|
||||||
|
|
||||||
(defn- parse-flags
|
(defn- parse-flags
|
||||||
[config]
|
[config]
|
||||||
(-> (:flags config)
|
(flags/parse flags/default
|
||||||
(flags/parse flags/default)))
|
default-flags
|
||||||
|
(:flags config)))
|
||||||
|
|
||||||
(defn read-env
|
(defn read-env
|
||||||
[prefix]
|
[prefix]
|
||||||
|
|
|
@ -45,7 +45,7 @@
|
||||||
(defn handler
|
(defn handler
|
||||||
[rpc]
|
[rpc]
|
||||||
(let [context (prepare-context rpc)]
|
(let [context (prepare-context rpc)]
|
||||||
(if (contains? cf/flags :api-doc)
|
(if (contains? cf/flags :backend-api-doc)
|
||||||
(fn [_]
|
(fn [_]
|
||||||
{:status 200
|
{:status 200
|
||||||
:body (-> (io/resource "api-doc.tmpl")
|
:body (-> (io/resource "api-doc.tmpl")
|
||||||
|
|
|
@ -203,6 +203,7 @@
|
||||||
(sxf request)))
|
(sxf request)))
|
||||||
(let [info (assoc info
|
(let [info (assoc info
|
||||||
:iss :prepared-register
|
:iss :prepared-register
|
||||||
|
:is-active true
|
||||||
:exp (dt/in-future {:hours 48}))
|
:exp (dt/in-future {:hours 48}))
|
||||||
token (tokens :generate info)
|
token (tokens :generate info)
|
||||||
params (d/without-nils
|
params (d/without-nils
|
||||||
|
|
|
@ -53,12 +53,13 @@
|
||||||
|
|
||||||
(defn- add-cookies
|
(defn- add-cookies
|
||||||
[response {:keys [id] :as session}]
|
[response {:keys [id] :as session}]
|
||||||
(let [cors? (contains? cfg/flags :cors)]
|
(let [cors? (contains? cfg/flags :cors)
|
||||||
|
secure? (contains? cfg/flags :secure-session-cookies)]
|
||||||
(assoc response :cookies {cookie-name {:path "/"
|
(assoc response :cookies {cookie-name {:path "/"
|
||||||
:http-only true
|
:http-only true
|
||||||
:value id
|
:value id
|
||||||
:same-site (if cors? :none :strict)
|
:same-site (if cors? :none :strict)
|
||||||
:secure true}})))
|
:secure secure?}})))
|
||||||
|
|
||||||
(defn- clear-cookies
|
(defn- clear-cookies
|
||||||
[response]
|
[response]
|
||||||
|
|
|
@ -34,7 +34,7 @@
|
||||||
params {:id id
|
params {:id id
|
||||||
:email email
|
:email email
|
||||||
:fullname fullname
|
:fullname fullname
|
||||||
:is-demo true
|
:is-active true
|
||||||
:deleted-at (dt/in-future cf/deletion-delay)
|
:deleted-at (dt/in-future cf/deletion-delay)
|
||||||
:password password
|
:password password
|
||||||
:props {:onboarding-viewed true}}]
|
:props {:onboarding-viewed true}}]
|
||||||
|
|
|
@ -124,9 +124,7 @@
|
||||||
|
|
||||||
;; --- MUTATION: Register Profile
|
;; --- MUTATION: Register Profile
|
||||||
|
|
||||||
(s/def ::accept-terms-and-privacy ::us/boolean)
|
|
||||||
(s/def ::token ::us/not-empty-string)
|
(s/def ::token ::us/not-empty-string)
|
||||||
|
|
||||||
(s/def ::register-profile
|
(s/def ::register-profile
|
||||||
(s/keys :req-un [::token ::fullname]))
|
(s/keys :req-un [::token ::fullname]))
|
||||||
|
|
||||||
|
@ -148,8 +146,12 @@
|
||||||
[{:keys [conn tokens session metrics] :as cfg} {:keys [token] :as params}]
|
[{:keys [conn tokens session metrics] :as cfg} {:keys [token] :as params}]
|
||||||
(let [claims (tokens :verify {:token token :iss :prepared-register})
|
(let [claims (tokens :verify {:token token :iss :prepared-register})
|
||||||
params (merge params claims)]
|
params (merge params claims)]
|
||||||
|
|
||||||
(check-profile-existence! conn params)
|
(check-profile-existence! conn params)
|
||||||
(let [profile (->> params
|
|
||||||
|
(let [is-active (or (:is-active params)
|
||||||
|
(contains? cf/flags :insecure-register))
|
||||||
|
profile (->> (assoc params :is-active is-active)
|
||||||
(create-profile conn)
|
(create-profile conn)
|
||||||
(create-profile-relations conn)
|
(create-profile-relations conn)
|
||||||
(decode-profile-row))]
|
(decode-profile-row))]
|
||||||
|
@ -182,6 +184,15 @@
|
||||||
::audit/props (audit/profile->props profile)
|
::audit/props (audit/profile->props profile)
|
||||||
::audit/profile-id (:id profile)})
|
::audit/profile-id (:id profile)})
|
||||||
|
|
||||||
|
;; If the `:enable-insecure-register` flag is set, we proceed
|
||||||
|
;; to sign in the user directly, without email verification.
|
||||||
|
(true? is-active)
|
||||||
|
(with-meta (profile/strip-private-attrs profile)
|
||||||
|
{:transform-response ((:create session) (:id profile))
|
||||||
|
:before-complete (annotate-profile-register metrics)
|
||||||
|
::audit/props (audit/profile->props profile)
|
||||||
|
::audit/profile-id (:id profile)})
|
||||||
|
|
||||||
;; In all other cases, send a verification email.
|
;; In all other cases, send a verification email.
|
||||||
:else
|
:else
|
||||||
(let [vtoken (tokens :generate
|
(let [vtoken (tokens :generate
|
||||||
|
@ -226,7 +237,7 @@
|
||||||
backend (:backend params "penpot")
|
backend (:backend params "penpot")
|
||||||
is-demo (:is-demo params false)
|
is-demo (:is-demo params false)
|
||||||
is-muted (:is-muted params false)
|
is-muted (:is-muted params false)
|
||||||
is-active (:is-active params (or (not= "penpot" backend) is-demo))
|
is-active (:is-active params false)
|
||||||
email (str/lower (:email params))
|
email (str/lower (:email params))
|
||||||
|
|
||||||
params {:id id
|
params {:id id
|
||||||
|
|
|
@ -10,16 +10,14 @@
|
||||||
[cuerdas.core :as str]))
|
[cuerdas.core :as str]))
|
||||||
|
|
||||||
(def default
|
(def default
|
||||||
#{:backend-asserts
|
"A common flags that affects both: backend and frontend."
|
||||||
:api-doc
|
[:enable-registration
|
||||||
:registration
|
:enable-demo-users])
|
||||||
:demo-users})
|
|
||||||
|
|
||||||
(defn parse
|
(defn parse
|
||||||
([flags] (parse flags #{}))
|
[& flags]
|
||||||
([flags default]
|
(loop [flags (apply concat flags)
|
||||||
(loop [flags (seq flags)
|
result #{}]
|
||||||
result default]
|
|
||||||
(let [item (first flags)]
|
(let [item (first flags)]
|
||||||
(if (nil? item)
|
(if (nil? item)
|
||||||
result
|
result
|
||||||
|
@ -34,6 +32,6 @@
|
||||||
(disj result (keyword (subs sname 8))))
|
(disj result (keyword (subs sname 8))))
|
||||||
|
|
||||||
:else
|
:else
|
||||||
(recur (rest flags) result))))))))
|
(recur (rest flags) result)))))))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,7 @@ services:
|
||||||
- PENPOT_SMTP_PASSWORD=
|
- PENPOT_SMTP_PASSWORD=
|
||||||
- PENPOT_SMTP_SSL=false
|
- PENPOT_SMTP_SSL=false
|
||||||
- PENPOT_SMTP_TLS=false
|
- PENPOT_SMTP_TLS=false
|
||||||
- PENPOT_FLAGS="enable-cors"
|
- PENPOT_FLAGS="enable-cors enable-insecure-register enable-terms-and-privacy-checkbox"
|
||||||
|
|
||||||
# LDAP setup
|
# LDAP setup
|
||||||
- PENPOT_LDAP_HOST=ldap
|
- PENPOT_LDAP_HOST=ldap
|
||||||
|
|
|
@ -57,8 +57,8 @@
|
||||||
(defn- parse-flags
|
(defn- parse-flags
|
||||||
[global]
|
[global]
|
||||||
(let [flags (obj/get global "penpotFlags" "")
|
(let [flags (obj/get global "penpotFlags" "")
|
||||||
flags (into #{} (map keyword) (str/words flags))]
|
flags (sequence (map keyword) (str/words flags))]
|
||||||
(flags/parse flags flags/default)))
|
(flags/parse flags/default flags)))
|
||||||
|
|
||||||
(defn- parse-version
|
(defn- parse-version
|
||||||
[global]
|
[global]
|
||||||
|
|
|
@ -169,7 +169,9 @@
|
||||||
(let [token (:invitation-token data)]
|
(let [token (:invitation-token data)]
|
||||||
(st/emit! (rt/nav :auth-verify-token {} {:token token})))
|
(st/emit! (rt/nav :auth-verify-token {} {:token token})))
|
||||||
|
|
||||||
(not= "penpot" (:auth-backend data))
|
;; The :is-active flag is true, when insecure-register is enabled
|
||||||
|
;; or the user used external auth provider.
|
||||||
|
(:is-active data)
|
||||||
(st/emit! (du/login-from-register))
|
(st/emit! (du/login-from-register))
|
||||||
|
|
||||||
:else
|
:else
|
||||||
|
@ -178,9 +180,14 @@
|
||||||
(s/def ::accept-terms-and-privacy (s/and ::us/boolean true?))
|
(s/def ::accept-terms-and-privacy (s/and ::us/boolean true?))
|
||||||
(s/def ::accept-newsletter-subscription ::us/boolean)
|
(s/def ::accept-newsletter-subscription ::us/boolean)
|
||||||
|
|
||||||
(s/def ::register-validate-form
|
(if (contains? @cf/flags :terms-and-privacy-checkbox)
|
||||||
|
(s/def ::register-validate-form
|
||||||
(s/keys :req-un [::token ::fullname ::accept-terms-and-privacy]
|
(s/keys :req-un [::token ::fullname ::accept-terms-and-privacy]
|
||||||
:opt-un [::accept-newsletter-subscription]))
|
:opt-un [::accept-newsletter-subscription]))
|
||||||
|
(s/def ::register-validate-form
|
||||||
|
(s/keys :req-un [::token ::fullname]
|
||||||
|
:opt-un [::accept-terms-and-privacy
|
||||||
|
::accept-newsletter-subscription])))
|
||||||
|
|
||||||
(mf/defc register-validate-form
|
(mf/defc register-validate-form
|
||||||
[{:keys [params] :as props}]
|
[{:keys [params] :as props}]
|
||||||
|
@ -207,6 +214,7 @@
|
||||||
:label (tr "auth.fullname")
|
:label (tr "auth.fullname")
|
||||||
:type "text"}]]
|
:type "text"}]]
|
||||||
|
|
||||||
|
(when (contains? @cf/flags :terms-and-privacy-checkbox)
|
||||||
[:div.fields-row
|
[:div.fields-row
|
||||||
[:& fm/input {:name :accept-terms-and-privacy
|
[:& fm/input {:name :accept-terms-and-privacy
|
||||||
:class "check-primary"
|
:class "check-primary"
|
||||||
|
@ -216,14 +224,7 @@
|
||||||
[:div
|
[:div
|
||||||
[:a {:href "https://penpot.app/terms.html" :target "_blank"} (tr "auth.terms-of-service")]
|
[:a {:href "https://penpot.app/terms.html" :target "_blank"} (tr "auth.terms-of-service")]
|
||||||
[:span ",\u00A0"]
|
[:span ",\u00A0"]
|
||||||
[:a {:href "https://penpot.app/privacy.html" :target "_blank"} (tr "auth.privacy-policy")]]]]]
|
[:a {:href "https://penpot.app/privacy.html" :target "_blank"} (tr "auth.privacy-policy")]]]]])
|
||||||
|
|
||||||
;; (when (contains? @cf/flags :newsletter-registration-check)
|
|
||||||
;; [:div.fields-row
|
|
||||||
;; [:& fm/input {:name :accept-newsletter-subscription
|
|
||||||
;; :class "check-primary"
|
|
||||||
;; :label (tr "auth.newsletter-subscription")
|
|
||||||
;; :type "checkbox"}]])
|
|
||||||
|
|
||||||
[:& fm/submit-button
|
[:& fm/submit-button
|
||||||
{:label (tr "auth.register-submit")
|
{:label (tr "auth.register-submit")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue