0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-12 18:18:24 -05:00

Merge remote-tracking branch 'origin/main' into staging

This commit is contained in:
Alejandro Alonso 2024-09-06 13:50:09 +02:00
commit 5b0331611d
5 changed files with 62 additions and 3 deletions

View 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>

View file

@ -415,6 +415,13 @@ async function generateTemplates() {
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(
"resources/templates/preview-body.mustache",
{

View file

@ -139,13 +139,24 @@
(when (not= previous-email email)
(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
[]
(ptk/reify ::fetch-profile
ptk/WatchEvent
(watch [_ _ _]
(->> (rp/cmd! :get-profile)
(rx/map profile-fetched)))))
(rx/map profile-fetched)
(rx/catch on-fetch-profile-exception)))))
;; --- EVENT: login

View file

@ -17,7 +17,7 @@
[cuerdas.core :as str]))
(defn handle-response
[{:keys [status body] :as response}]
[{:keys [status body headers] :as response}]
(cond
(= 204 status)
;; We need to send "something" so the streams listening downstream can act
@ -40,6 +40,13 @@
{:type :validation
: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))
(rx/throw (ex-info "http error" body))
@ -48,6 +55,7 @@
(ex-info "http error"
{:type :unexpected-error
:status status
:headers headers
:data body}))))
(def default-options

View file

@ -13,9 +13,10 @@
[app.main.data.events :as ev]
[app.util.browser-history :as bhistory]
[app.util.dom :as dom]
[app.util.globals :as globals]
[app.util.globals :as globals]
[app.util.timers :as ts]
[beicon.v2.core :as rx]
[cuerdas.core :as str]
[goog.events :as e]
[potok.v2.core :as ptk]
[reitit.core :as r]))
@ -149,6 +150,20 @@
[]
(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
(defn initialize-history