mirror of
https://github.com/penpot/penpot.git
synced 2025-05-10 23:16:38 +02:00
✨ Add support for optional human challenge
This commit is contained in:
parent
edeb16bc26
commit
d88f28f5c2
5 changed files with 61 additions and 2 deletions
18
frontend/resources/templates/challenge.mustache
Normal file
18
frontend/resources/templates/challenge.mustache
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<title>Penpot - Challenge</title>
|
||||||
|
<link rel="icon" href="images/favicon.png" />
|
||||||
|
|
||||||
|
<script>
|
||||||
|
var params = new URL(document.location.toString()).searchParams;
|
||||||
|
var redirectPath = params.get("redirect");
|
||||||
|
setTimeout(() => {
|
||||||
|
location.href = "/#" + redirectPath;
|
||||||
|
}, 100);
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -415,6 +415,13 @@ async function generateTemplates() {
|
||||||
|
|
||||||
await fs.writeFile("./resources/public/index.html", content);
|
await fs.writeFile("./resources/public/index.html", content);
|
||||||
|
|
||||||
|
content = await renderTemplate(
|
||||||
|
"resources/templates/challenge.mustache",
|
||||||
|
{},
|
||||||
|
partials,
|
||||||
|
);
|
||||||
|
await fs.writeFile("./resources/public/challenge.html", content);
|
||||||
|
|
||||||
content = await renderTemplate(
|
content = await renderTemplate(
|
||||||
"resources/templates/preview-body.mustache",
|
"resources/templates/preview-body.mustache",
|
||||||
{
|
{
|
||||||
|
|
|
@ -137,13 +137,24 @@
|
||||||
(when (not= previous-email email)
|
(when (not= previous-email email)
|
||||||
(set-current-team! nil)))))))
|
(set-current-team! nil)))))))
|
||||||
|
|
||||||
|
(defn- on-fetch-profile-exception
|
||||||
|
[cause]
|
||||||
|
(let [data (ex-data cause)]
|
||||||
|
(if (and (= :authorization (:type data))
|
||||||
|
(= :challenge-required (:code data)))
|
||||||
|
(let [path (rt/get-current-path)
|
||||||
|
href (str "/challenge.html?redirect=" path)]
|
||||||
|
(rx/of (rt/nav-raw href)))
|
||||||
|
(rx/throw cause))))
|
||||||
|
|
||||||
(defn fetch-profile
|
(defn fetch-profile
|
||||||
[]
|
[]
|
||||||
(ptk/reify ::fetch-profile
|
(ptk/reify ::fetch-profile
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ _ _]
|
(watch [_ _ _]
|
||||||
(->> (rp/cmd! :get-profile)
|
(->> (rp/cmd! :get-profile)
|
||||||
(rx/map profile-fetched)))))
|
(rx/map profile-fetched)
|
||||||
|
(rx/catch on-fetch-profile-exception)))))
|
||||||
|
|
||||||
;; --- EVENT: login
|
;; --- EVENT: login
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
[cuerdas.core :as str]))
|
[cuerdas.core :as str]))
|
||||||
|
|
||||||
(defn handle-response
|
(defn handle-response
|
||||||
[{:keys [status body] :as response}]
|
[{:keys [status body headers] :as response}]
|
||||||
(cond
|
(cond
|
||||||
(= 204 status)
|
(= 204 status)
|
||||||
;; We need to send "something" so the streams listening downstream can act
|
;; We need to send "something" so the streams listening downstream can act
|
||||||
|
@ -40,6 +40,13 @@
|
||||||
{:type :validation
|
{:type :validation
|
||||||
:code :request-body-too-large}))
|
:code :request-body-too-large}))
|
||||||
|
|
||||||
|
(and (= status 403)
|
||||||
|
(or (= "cloudflare" (get headers "server"))
|
||||||
|
(= "challenge" (get headers "cf-mitigated"))))
|
||||||
|
(rx/throw (ex-info "http error"
|
||||||
|
{:type :authorization
|
||||||
|
:code :challenge-required}))
|
||||||
|
|
||||||
(and (>= status 400) (map? body))
|
(and (>= status 400) (map? body))
|
||||||
(rx/throw (ex-info "http error" body))
|
(rx/throw (ex-info "http error" body))
|
||||||
|
|
||||||
|
@ -48,6 +55,7 @@
|
||||||
(ex-info "http error"
|
(ex-info "http error"
|
||||||
{:type :unexpected-error
|
{:type :unexpected-error
|
||||||
:status status
|
:status status
|
||||||
|
:headers headers
|
||||||
:data body}))))
|
:data body}))))
|
||||||
|
|
||||||
(def default-options
|
(def default-options
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
[app.util.globals :as globals]
|
[app.util.globals :as globals]
|
||||||
[app.util.timers :as ts]
|
[app.util.timers :as ts]
|
||||||
[beicon.v2.core :as rx]
|
[beicon.v2.core :as rx]
|
||||||
|
[cuerdas.core :as str]
|
||||||
[goog.events :as e]
|
[goog.events :as e]
|
||||||
[potok.v2.core :as ptk]
|
[potok.v2.core :as ptk]
|
||||||
[reitit.core :as r]))
|
[reitit.core :as r]))
|
||||||
|
@ -149,6 +150,20 @@
|
||||||
[]
|
[]
|
||||||
(set! (.-href globals/location) "/"))
|
(set! (.-href globals/location) "/"))
|
||||||
|
|
||||||
|
(defn nav-raw
|
||||||
|
[href]
|
||||||
|
(ptk/reify ::nav-raw
|
||||||
|
ptk/EffectEvent
|
||||||
|
(effect [_ _ _]
|
||||||
|
(set! (.-href globals/location) href))))
|
||||||
|
|
||||||
|
(defn get-current-path
|
||||||
|
[]
|
||||||
|
(let [hash (.-hash globals/location)]
|
||||||
|
(if (str/starts-with? hash "#")
|
||||||
|
(subs hash 1)
|
||||||
|
hash)))
|
||||||
|
|
||||||
;; --- History API
|
;; --- History API
|
||||||
|
|
||||||
(defn initialize-history
|
(defn initialize-history
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue