- Add vendor-changed HTMX handlers for both bulk code and individual edit - Pre-populate default account at 100% when vendor is selected and no accounts exist - Fix render-accounts-section to render from step-params correctly - Change bulk code vendor-changed from hx-get to hx-post to include form data - Add routes for vendor-changed endpoints - Update e2e tests to cover vendor pre-population - Run lein cljfmt fix across codebase
104 lines
4.7 KiB
Clojure
104 lines
4.7 KiB
Clojure
(ns auto-ap.ssr.auth
|
|
(:require
|
|
[auto-ap.session-version :as session-version]
|
|
[auto-ap.ssr.components :as com]
|
|
[auto-ap.ssr.hx :as hx]
|
|
[auto-ap.ssr.svg :as svg]
|
|
[auto-ap.ssr.ui :refer [base-page]]
|
|
[buddy.sign.jwt :as jwt]
|
|
[config.core :refer [env]]
|
|
[hiccup.util :as hu]))
|
|
|
|
(defn logout [request]
|
|
{:status 301
|
|
:headers {"Location" "/login"}
|
|
:session {}})
|
|
|
|
(defn impersonate [request]
|
|
{:status 200
|
|
:session {:identity (dissoc (jwt/unsign (get-in request [:query-params "jwt"])
|
|
(:jwt-secret env)
|
|
{:alg :hs512})
|
|
:exp)
|
|
:version session-version/current-session-version}})
|
|
|
|
(defn login-url
|
|
([] (login-url nil))
|
|
([next]
|
|
|
|
(let [client-id "264081895820-0nndcfo3pbtqf30sro82vgq5r27h8736.apps.googleusercontent.com"
|
|
redirect-uri (str (:base-url env) "/api/oauth")]
|
|
(str (hu/url "https://accounts.google.com/o/oauth2/auth"
|
|
(cond-> {"access_type" "online"
|
|
"client_id" client-id
|
|
"redirect_uri" redirect-uri
|
|
"response_type" "code"
|
|
"max_auth_age" "0"
|
|
"scope" "https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile"}
|
|
next (assoc "state" (hu/url-encode next))))))))
|
|
|
|
(defn- page-contents [request]
|
|
[:div#app {"@notification.document" "notificationDetails=event.detail.value; showNotification=true"
|
|
|
|
:x-data (hx/json {:showError false
|
|
:errorDetails ""
|
|
:showNotification false
|
|
:notificationDetails ""})
|
|
"@htmx:response-error.camel" "errorDetails = $event.detail.xhr.response; showError=true;"}
|
|
[:div#app-contents.flex.overflow-hidden
|
|
[:div#main-content {:class "relative w-full h-full overflow-y-auto px-4 bg-gray-100 dark:bg-gray-900 min-h-content "}
|
|
[:div#notification-holder
|
|
[:div.fixed.top-0.right-0.left-0.z-30.mx-auto.max-w-screen-lg.w-screen-lg.my-0.pt-8.rounded-lg {:x-show "showNotification"}
|
|
[:div.relative
|
|
[:button.absolute.right-2.top-2.w-6.h-6.z-50.text-blue-400
|
|
{"@click" "showNotification=false"}
|
|
svg/filled-x]]
|
|
|
|
[:div.m-4.overflow-auto.z-30.flex.center-items.justify-center.text-blue-800.bg-blue-50.dark:bg-gray-800.dark:text-blue-400.border-blue-300.rounded-lg.border.max-h-96
|
|
{:x-show "showNotification"
|
|
"x-transition:enter" "transition duration-300 transform ease-in-out"
|
|
"x-transition:enter-start" "opacity-0 translate-y-full"
|
|
"x-transition:enter-end" "opacity-100 translate-y-0"
|
|
"x-transition:leave" "transition duration-300 transform ease-in-out"
|
|
"x-transition:leave-start" "opacity-100 translate-y-0"
|
|
"x-transition:leave-end" "opacity-0 translate-y-full"}
|
|
|
|
[:div {:class "p-4 text-lg w-full" :role "alert"}
|
|
[:div.text-sm
|
|
[:pre#notification-details.text-xs {:x-html "notificationDetails"}]]]]]]
|
|
[:div {:x-show "showError"
|
|
:x-init ""}
|
|
[:div.fixed.top-0.right-0.left-0.z-30.mx-auto.max-w-screen-lg.w-screen-lg.my-0.pt-8.rounded-lg
|
|
[:div.relative
|
|
[:button.absolute.right-2.top-2.w-6.h-6.z-50.text-red-600
|
|
{"@click" "showError=false"}
|
|
svg/filled-x]]
|
|
|
|
[:div.m-4.overflow-auto.z-30.flex.center-items.justify-center.text-red-800.bg-red-50.dark:bg-gray-800.dark:text-red-400.border-red-300.rounded-lg.border.max-h-96
|
|
{:x-show "showError"
|
|
"x-transition:enter" "transition duration-300"
|
|
"x-transition:enter-start" "opacity-0"
|
|
"x-transition:enter-end" "opacity-100"}
|
|
|
|
[:div {:class "p-4 mb-4 text-lg w-full" :role "alert"}
|
|
[:div.inline-block.w-8.h-8.mr-2 svg/alert]
|
|
[:span.font-medium "Oh, drat! An unexpected error has occurred."]
|
|
[:div.text-sm {:x-data (hx/json {"expandError" false})}
|
|
[:p "Integreat staff have been notified and are looking into it. "]
|
|
[:p "To see error details, " [:a.underline.cursor-pointer {"@click" "expandError=true"} "click here"] "."]
|
|
[:pre#error-details.text-xs {:x-show "expandError" :x-text "errorDetails"}]]]]]]
|
|
[:div.p-4.flex.flex-row.justify-center.items-center.h-screen
|
|
(com/card {:class "animate-slideUp"}
|
|
|
|
[:div.p-4
|
|
[:img {:src "/img/logo-big.png"}]
|
|
[:div
|
|
[:a.button.is-large.is-primary {:href (login-url (get (:query-params request) "redirect-to"))} "Login with Google"]]
|
|
"HELLO"])]]]])
|
|
|
|
(defn login [request]
|
|
(base-page
|
|
request
|
|
(page-contents request)
|
|
|
|
"Dashboard")) |