working on reauth.
This commit is contained in:
@@ -1,4 +1,99 @@
|
||||
(ns auto-ap.views.pages.admin.yodlee2.form)
|
||||
(ns auto-ap.views.pages.admin.yodlee2.form
|
||||
(:require [auto-ap.views.components.modal :as modal]
|
||||
[auto-ap.status :as status]
|
||||
[auto-ap.forms :as forms]
|
||||
[re-frame.core :as re-frame]
|
||||
[auto-ap.views.utils :refer [->$ action-cell-width date->str with-user dispatch-event]]))
|
||||
|
||||
(defn form []
|
||||
[:div])
|
||||
(re-frame/reg-sub
|
||||
::can-submit
|
||||
(fn [db]
|
||||
true))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::saved
|
||||
(forms/triggers-stop ::form)
|
||||
(fn [{:keys [db]} [_ {:keys [edit-user]}]]
|
||||
{:dispatch [::modal/modal-closed]}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::saving
|
||||
[with-user (forms/in-form [::form])]
|
||||
(fn [{:keys [user db]} [_ ]]
|
||||
(let [provider-account-id (:id (:data db))]
|
||||
{:http {:token user
|
||||
:method :post
|
||||
:owns-state {:single ::form}
|
||||
:headers {"Content-Type" "application/edn"}
|
||||
:uri (str "/api/yodlee2/reauthenticate/" provider-account-id)
|
||||
:body {:client-id (:client-id (:data db))
|
||||
"loginForm"
|
||||
{"row"
|
||||
(->> db
|
||||
:data
|
||||
:login
|
||||
(sort-by (fn [[k v]] k))
|
||||
(map second)
|
||||
(map (fn [row]
|
||||
{"field"
|
||||
(mapv (fn [[k v]]
|
||||
{"id" k
|
||||
"value" v})
|
||||
row)})))}
|
||||
"field"
|
||||
(mapv (fn [[k v]]
|
||||
{"id" k
|
||||
"value" v})
|
||||
(-> db :data :mfa))}
|
||||
|
||||
:on-success [::saved]}})))
|
||||
|
||||
(def reauthenticate-form (forms/vertical-form {:submit-event [::saving]
|
||||
:change-event [::forms/change ::form]
|
||||
:can-submit [::can-submit]
|
||||
:id ::form}))
|
||||
(defn form [{:keys [provider-account]}]
|
||||
(let [{error :error account-data :data } @(re-frame/subscribe [::forms/form [::form (:id provider-account)]])
|
||||
|
||||
{:keys [form-inline field error-notification submit-button]} reauthenticate-form
|
||||
]
|
||||
(form-inline {:title "Reauthenticate"}
|
||||
[:<>
|
||||
(error-notification)
|
||||
(doall
|
||||
(for [[row i] (map vector (-> account-data :provider-account :loginForm last :row) (range))
|
||||
f (:field row)
|
||||
:let [options (map :optionValue (:option f))]]
|
||||
^{:key (:id f)}
|
||||
[:div
|
||||
(field (:label row)
|
||||
[:input.input {:type "text" :field [:login i (:id f)]}])
|
||||
(if (seq options)
|
||||
[:ul
|
||||
(for [o options]
|
||||
^{:key o}
|
||||
[:li [:pre o]])])]))
|
||||
(doall
|
||||
(for [f (-> account-data :provider-account :field)]
|
||||
^{:key (:id f)}
|
||||
(field (:label f)
|
||||
[:input.input {:type "text" :mfa [:form (:id f)] :value (-> f :field first :value)}])))])))
|
||||
|
||||
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::reauthenticate-start
|
||||
(fn [{:keys [db]} [_ provider-account client-id]]
|
||||
(println provider-account)
|
||||
{:db (-> db
|
||||
(forms/start-form ::form {:id (:id provider-account)
|
||||
:client-id client-id
|
||||
:provider-account provider-account}))
|
||||
:dispatch [::modal/modal-requested {:title (str "Reauthenticate " (:id provider-account))
|
||||
:body [form {:provider-account provider-account}]
|
||||
:cancel? false
|
||||
:confirm {:value "Reauthenticate"
|
||||
:status-from [::status/single ::form]
|
||||
:class "is-primary"
|
||||
:on-click (dispatch-event [::saving])
|
||||
:close-event [::status/completed ::form]}}]}))
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
[auto-ap.views.components.buttons :as buttons]
|
||||
[auto-ap.views.components.grid :as grid]
|
||||
[auto-ap.views.components.modal :as modal]
|
||||
[auto-ap.views.pages.admin.users.form :as form]
|
||||
[auto-ap.views.pages.admin.yodlee2.form :as form]
|
||||
[auto-ap.views.utils :refer [->$ action-cell-width date->str with-user dispatch-event]]
|
||||
[re-frame.core :as re-frame]
|
||||
[auto-ap.forms :as forms]))
|
||||
@@ -107,7 +107,7 @@
|
||||
[:li (:name a) " - " (:number a) [:div.tag (->$ (:available-balance a))]])]]
|
||||
[grid/cell {}
|
||||
[:div.buttons
|
||||
[buttons/fa-icon {:event [::form/editing c]
|
||||
[buttons/fa-icon {:event [::form/reauthenticate-start c (:id (:client c))]
|
||||
:icon "fa-pencil"}]
|
||||
[buttons/fa-icon {:event [::request-refresh (:id c) (:id (:client c))]
|
||||
:class (status/class-for (get statuses (:id c)))
|
||||
|
||||
Reference in New Issue
Block a user