Merge branch 'try-tailwind'
This commit is contained in:
@@ -20,18 +20,18 @@
|
||||
(:jwt-secret env)
|
||||
{:alg :hs512}))
|
||||
|
||||
(defn oauth [{{:strs [code]} :query-params {:strs [host]} :headers}]
|
||||
(defn oauth [{{:strs [code state]} :query-params {:strs [host]} :headers :as request}]
|
||||
(try
|
||||
(let [auth (-> "https://accounts.google.com/o/oauth2/token"
|
||||
(http/post
|
||||
{:form-params {"client_id" google-client-id
|
||||
"client_secret" google-client-secret
|
||||
"code" code
|
||||
"redirect_uri" (str (:scheme env) "://" host "/api/oauth")
|
||||
"grant_type" "authorization_code"}
|
||||
:as :json})
|
||||
(http/post
|
||||
{:form-params {"client_id" google-client-id
|
||||
"client_secret" google-client-secret
|
||||
"code" code
|
||||
"redirect_uri" (str (:scheme env) "://" host "/api/oauth")
|
||||
"grant_type" "authorization_code"}
|
||||
:as :json})
|
||||
:body)
|
||||
|
||||
|
||||
token (:access_token auth)
|
||||
profile (-> (http/get "https://www.googleapis.com/oauth2/v1/userinfo"
|
||||
{:headers {"Authorization" (str "Bearer " token)} :as :json})
|
||||
@@ -45,6 +45,7 @@
|
||||
:user/name (:name profile)})
|
||||
auth {:user (:name profile)
|
||||
:exp (time/plus (time/now) (time/days 30))
|
||||
:db/id (:db/id user)
|
||||
:user/clients (map (fn [c]
|
||||
(select-keys c [:client/code :db/id :client/locations]))
|
||||
(:user/clients user))
|
||||
@@ -53,19 +54,18 @@
|
||||
_ (mu/log ::logged-in-as
|
||||
:auth auth)]
|
||||
;; TODO - these namespaces are not being transmitted/deserialized properly
|
||||
|
||||
|
||||
(if (and token user)
|
||||
(let [jwt (jwt/sign auth
|
||||
(:jwt-secret env)
|
||||
{:alg :hs512})]
|
||||
|
||||
{:status 301
|
||||
:headers {"Location" (str "/?jwt=" jwt)}
|
||||
:headers {"Location" (str (or (not-empty state) "/") "?jwt=" jwt)}
|
||||
:session {:identity (dissoc auth :exp)}})
|
||||
{:status 401
|
||||
:body "Couldn't authenticate"}))
|
||||
(catch Exception e
|
||||
(log/warn e )
|
||||
(log/warn e)
|
||||
{:status 401
|
||||
:body (str "Couldn't authenticate " (.toString e))})))
|
||||
|
||||
|
||||
@@ -267,8 +267,9 @@
|
||||
))
|
||||
(into [["Vendor Name" "Address" "City" "State" "Zip" "Terms" "Account" "Account Code"]]))]
|
||||
{:body
|
||||
(into (list)
|
||||
data)})))
|
||||
(into []
|
||||
data)
|
||||
:headers {"content-disposition" "attachment; filename=\"vendors.csv\""}})))
|
||||
|
||||
(defn export-ledger [{:keys [identity query-params]}]
|
||||
(let [start-date (or (some-> (query-params "start-date")
|
||||
@@ -426,7 +427,7 @@
|
||||
"expected-deposit/" {#"export/?" {:get :export-expected-deposits}}
|
||||
"clients/" {#"export/?" {:get :export-clients}}
|
||||
"vendors/" {#"export/?" {:get :export-vendors}
|
||||
"/company" {#"export/?" {:get :export-company-vendors}}}
|
||||
"company/" {#"export" {:get :export-company-vendors}}}
|
||||
"ledger/" {#"export/?" {:get :export-ledger}}
|
||||
"accounts/" {#"export/?" {:get :export-accounts}}
|
||||
"transactions/" {#"export/?" {:get :export-transactions}
|
||||
|
||||
@@ -18,7 +18,8 @@
|
||||
[com.brunobonacci.mulog :as mu]
|
||||
[datomic.api :as dc]
|
||||
[hiccup2.core :as hiccup]
|
||||
[amazonica.aws.s3 :as s3]))
|
||||
[amazonica.aws.s3 :as s3]
|
||||
[auto-ap.ssr.components :as com]))
|
||||
|
||||
(defn fmt-amount [a]
|
||||
(with-precision 2
|
||||
@@ -27,19 +28,14 @@
|
||||
(.setScale 2 java.math.RoundingMode/HALF_UP)
|
||||
(double))))
|
||||
|
||||
|
||||
|
||||
|
||||
(defn rows->maps [rows]
|
||||
(let [[headers & rows] rows]
|
||||
(for [r rows]
|
||||
(into {}
|
||||
(map vector headers r)))))
|
||||
|
||||
|
||||
|
||||
|
||||
(defn map->sales-order [r clients]
|
||||
(println r)
|
||||
(let [order-number (get r "Order Number")
|
||||
event-date (get r "Event Date")
|
||||
store-name (get r "Store Name")
|
||||
@@ -135,30 +131,29 @@
|
||||
(stream->sales-orders s)))
|
||||
|
||||
(defn page* []
|
||||
[:div
|
||||
[:h1.title "EZCater XLS Import"]
|
||||
[:div.card.block {:style {:width "500px"}}
|
||||
[:div.card-content
|
||||
"Please go to "
|
||||
[:a {:href "https://www.ezcater.com/ez_manage/reports/new" :target "_blank"} "EZCater's report page"]
|
||||
" to generate a new report. Then drop it below."]]
|
||||
[:div#page-notification.notification.block {:style {:display "none"}}]
|
||||
[:div.card.block
|
||||
[:div.card-content
|
||||
[:form {:action (bidi/path-for ssr-routes/only-routes
|
||||
:admin-ezcater-xls)
|
||||
:method "POST"
|
||||
:class "dropzone"
|
||||
:id "ezcater"}]]]
|
||||
[:script
|
||||
(hiccup/raw
|
||||
"
|
||||
[:div.mt-4
|
||||
(com/card {}
|
||||
[:div.px-4.py-3.space-y-4.flex.flex-col
|
||||
[:h1.text-2xl.mb-3.font-bold "EZCater XLS Import"]
|
||||
[:p.text-sm.italic
|
||||
"Please go to "
|
||||
(com/link {:href "https://www.ezcater.com/ez_manage/reports/new" :target "_blank"} "EZCater's report page")
|
||||
" to generate a new report. Then drop it below."]
|
||||
[:div#page-notification.notification.block {:style {:display "none"}}]
|
||||
[:form.bg-blue-300 {:action (bidi/path-for ssr-routes/only-routes
|
||||
:admin-ezcater-xls)
|
||||
:method "POST"
|
||||
:class "dropzone"
|
||||
:id "ezcater"}]
|
||||
[:script
|
||||
(hiccup/raw
|
||||
"
|
||||
Dropzone.options.ezcater = {
|
||||
success: function (file, response) {
|
||||
document.getElementById(\"page-notification\").innerHTML = response;
|
||||
document.getElementById(\"page-notification\").style[\"display\"] = \"block\";
|
||||
}
|
||||
}")]])
|
||||
}")]])])
|
||||
|
||||
(defn upload-xls [{:keys [identity] :as request}]
|
||||
|
||||
@@ -194,8 +189,23 @@
|
||||
(if (= :post request-method)
|
||||
(upload-xls request)
|
||||
(base-page
|
||||
request
|
||||
(page*)
|
||||
|
||||
(admin-side-bar matched-route))))
|
||||
request
|
||||
(com/page {:nav (com/admin-aside-nav)
|
||||
:active-client (:client (:session request))
|
||||
:identity (:identity request)
|
||||
:app-params {:hx-get (bidi/path-for ssr-routes/only-routes
|
||||
:admin-ezcater-xls)
|
||||
:hx-trigger "clientSelected from:body"
|
||||
:hx-select "#app-contents"
|
||||
:hx-swap "outerHTML swap:300ms"}}
|
||||
(com/breadcrumbs {}
|
||||
[:a {:href (bidi/path-for ssr-routes/only-routes
|
||||
:admin)}
|
||||
"Admin"]
|
||||
[:a {:href (bidi/path-for ssr-routes/only-routes
|
||||
:admin-ezcater-xls)}
|
||||
"EZCater XLS Import"])
|
||||
(page*))
|
||||
|
||||
"EZCater upload")))
|
||||
|
||||
|
||||
@@ -8,30 +8,33 @@
|
||||
(defn wrap-secure [handler]
|
||||
(fn [request]
|
||||
(cond (authenticated? request)
|
||||
(handler request)
|
||||
(handler request)
|
||||
|
||||
(get (:headers request) "hx-request")
|
||||
{:status 401
|
||||
:headers {"hx-redirect" (str "/login?"
|
||||
(url/map->query {"redirect-to" (:uri request)}))}}
|
||||
|
||||
(get (:headers request) "hx-request")
|
||||
{:status 401
|
||||
:headers {"hx-redirect" "/login"}}
|
||||
|
||||
:else
|
||||
{:status 302
|
||||
:headers {"Location" "/login" }})))
|
||||
:else
|
||||
{:status 302
|
||||
:headers {"Location" (str "/login?"
|
||||
(url/map->query {"redirect-to" (:uri request)}))}})))
|
||||
|
||||
(defn wrap-admin [handler]
|
||||
(fn [request]
|
||||
(if (is-admin? (:identity request))
|
||||
(handler request)
|
||||
(do
|
||||
(do
|
||||
(alog/warn ::unauthenticated)
|
||||
{:status 302
|
||||
:headers {"Location" "/login"}}))))
|
||||
:headers {"Location" (str "/login?"
|
||||
(url/map->query {"redirect-to" (:uri request)}))}}))))
|
||||
|
||||
(defn wrap-client-redirect-unauthenticated [handler]
|
||||
(fn [request]
|
||||
(let [response (handler request)]
|
||||
(if (= 401 (get response :status))
|
||||
(-> response
|
||||
(assoc-in [:headers "hx-redirect"] "/login/"))
|
||||
(-> response
|
||||
(assoc-in [:headers "hx-redirect"] (str "/login?"
|
||||
(url/map->query {"redirect-to" (:uri request)}))))
|
||||
response))))
|
||||
|
||||
Reference in New Issue
Block a user