users are not activated, looks like you can edit existing ones

This commit is contained in:
Bryce Covert
2018-05-21 17:48:59 -07:00
parent d020a4d254
commit 3fee89f840
12 changed files with 282 additions and 35 deletions

View File

@@ -5,17 +5,31 @@
[auto-ap.routes :as routes]
[auto-ap.effects :as effects]
[venia.core :as v]
[bidi.bidi :as bidi]))
[bidi.bidi :as bidi]
[goog.crypt.base64 :as b64]
[clojure.string :as str]))
(defn jwt->data [token]
(js->clj (.parse js/JSON (b64/decodeString (second (str/split token #"\." ))))))
(re-frame/reg-event-fx
::initialize-db
(fn [{:keys [db]} [_ token]]
(let [handler (:handler (bidi/match-route routes/routes (.. js/window -location -pathname)))]
(if (and (not= :login handler) (not token))
(cond
(and (not= :login handler) (not token))
{:redirect "/login"
:db (assoc db/default-db
:active-page :login
:user token)}
(and token (= "none" (get (jwt->data token) "role") ))
{:redirect "/needs-activation"
:db (assoc db/default-db
:active-page :needs-activation
:user token)}
:else
{:db (assoc db/default-db
:active-page handler
:user token)