Should fix most of the authentication issues

This commit is contained in:
2023-09-05 23:08:22 -07:00
parent a6e4080746
commit a56d3b0b84
22 changed files with 506 additions and 179 deletions

View File

@@ -4,7 +4,7 @@
[auto-ap.routes :as routes]
[auto-ap.utils :refer [by]]
[auto-ap.views.pages.data-page :as data-page]
[auto-ap.views.utils :refer [parse-jwt with-user]]
[auto-ap.views.utils :refer [parse-jwt with-user gunzip]]
[bidi.bidi :as bidi]
[clojure.string :as str]
[clojure.edn :as edn]
@@ -12,10 +12,18 @@
[re-frame.core :as re-frame]
[auto-ap.ssr-routes :as ssr-routes]
[cemerick.url :as url]
[auto-ap.subs :as subs]))
[auto-ap.subs :as subs]
[pako]))
(defn jwt->data [token]
(js->clj (.parse js/JSON (b64/decodeString (second (str/split token #"\." ))))))
(let [raw (js->clj (.parse js/JSON (b64/decodeString (second (str/split token #"\." )))))
gz-clients (or (:gz-clients raw)
(get raw "gz-clients"))]
(cond-> raw
gz-clients (assoc "user/clients" (gunzip gz-clients)))))
(defn client-query []

View File

@@ -56,6 +56,11 @@
(when (= "admin" (:user/role @user))
[:a {:class "navbar-item" :href (bidi/path-for routes/routes :admin)} "Administration"])
[:hr {:class "navbar-divider"}]
[:a.navbar-item {:on-click (fn []
(.removeItem js/localStorage "last-client-id" nil)
(.setItem js/localStorage "last-selected-clients" ":all")
(.reload (.-location js/document ) true))}
"Full Refresh"]
[:a.navbar-item {:on-click (fn [e] (.preventDefault e) (re-frame/dispatch [::events/logout]))} "Logout"]]]
[:a.navbar-item {:href (login-url)} "Login"])))

View File

@@ -39,6 +39,7 @@
[:name
:profile_image_url
:email
:impersonate_jwt
:id
:role
[:clients [:id :name]]]]]}

View File

@@ -32,7 +32,7 @@
[grid/header-cell {} "Email"]
[grid/header-cell {} "Role"]
[grid/header-cell {} "Clients"]
[grid/header-cell {:style {:width (action-cell-width 1)}}]]]
[grid/header-cell {:style {:width (action-cell-width 5)}}]]]
[grid/body
(for [{:keys [id name role clients] :as c} (:data page)]
^{:key (str name "-" id)}
@@ -50,6 +50,14 @@
[grid/cell {} role]
[grid/cell {} (str/join ", " (map :name clients))]
[grid/cell {}
[:a.button {:on-click (fn []
(.setItem js/localStorage "jwt" (:impersonate-jwt c))
(.removeItem js/localStorage "last-client-id" nil)
(.removeItem js/localStorage "last-selected-clients" nil)
(.reload (.-location js/document ) true))}
"Impersonate"]
[buttons/fa-icon {:event [::form/editing c]
:icon "fa-pencil"}]]])]]
]))

View File

@@ -8,10 +8,14 @@
[:div.column.is-8.is-offset-2.has-text-centered
[:div.box.slideInFromBelow
[:img {:src "http://www.integreatconsult.com/wp-content/uploads/2016/11/logo.png"}]
[:img {:src "/img/logo.png"}]
[:div.notification.is-danger.is-light "An unexpected error has occured. "
[:a {:on-click #(.reload (.-location js/document )) } "Click here"]
" to try again."]]
[:div [:a {:on-click (fn []
(.removeItem js/localStorage "last-client-id" nil)
(.removeItem js/localStorage "last-selected-clients" nil)
(.reload (.-location js/document ) true)) } "Click here"]
" to try again."]
[:div "If the error continues, please try " [:a {:href "/login"} "logging in"] " again."]]]
[:p.has-text-gray
"Copyright Integreat 2020"]]]]]]
)

View File

@@ -11,7 +11,8 @@
[react-transition-group :as react-transition-group]
#_{:clj-kondo/ignore [:unused-namespace]}
[react :as react]
[reagent.core :as r])
[reagent.core :as r]
[pako])
(:import
(goog.i18n NumberFormat)
(goog.i18n.NumberFormat Format)))
@@ -297,13 +298,25 @@
:else
x))
(defn gunzip [b64]
(let [raw-byte-array (->> b64
js/atob
(map (fn [z] (.charCodeAt z 0)))
clj->js
(js/Uint8Array.))]
(or (edn/read-string (pako/inflate raw-byte-array #js {"to" "string"}))
nil)))
(defn parse-jwt [jwt]
(when-let [json (some-> jwt
(str/split #"\.")
second
base64/decodeString)]
(js->clj (.parse js/JSON json) :keywordize-keys true)))
(let [raw (js->clj (.parse js/JSON json) :keywordize-keys true)
gz-clients (or (:gz-clients raw)
(get raw "gz-clients"))]
(cond-> raw
gz-clients (assoc :user/clients (gunzip gz-clients))))))
(defn coerce-float [f]
(cond (str/blank? f)