Get user profile

This commit is contained in:
kagel 2016-08-23 16:00:53 +03:00
parent c97627c6cf
commit e47c25d1ca
6 changed files with 32 additions and 22 deletions

View File

@ -29,11 +29,6 @@
:title "commitETH API"
:description "commitETH API"}}}}
(GET "/authenticated" []
:auth-rules authenticated?
:current-user user
(ok {:user user}))
(context "/api" []
(POST "/user/address" []
:auth-rules authenticated?
@ -42,4 +37,8 @@
(let [result (users/update-user-address user address)]
(if (= 1 result)
(ok)
(internal-server-error))))))
(internal-server-error))))
(GET "/user" []
:auth-rules authenticated?
:current-user user
(ok {:user (users/get-user (:login user))}))))

View File

@ -3,7 +3,8 @@
[re-frame.core :as rf]))
(defn input [{:keys [value-path]}]
(let [val (reagent/atom nil)
(let [init-val @(rf/subscribe [:get-in value-path])
val (reagent/atom init-val)
save #(let [v (-> @val str clojure.string/trim)]
(when (seq v)
(rf/dispatch [:assoc-in value-path v])))]

View File

@ -3,4 +3,4 @@
(def default-db
{:page :home
:user nil
:address nil})
:user-profile nil})

View File

@ -21,12 +21,19 @@
(reg-event-db
:set-active-user
(fn [db [_ user]]
(dispatch [:load-user-profile])
(assoc db :user user)))
(reg-event-db
:set-user-address
(fn [db [_ address]]
(assoc db :address address)))
:load-user-profile
(GET "/api/user"
{:headers {"Accept" "application/transit+json"}
:handler #(dispatch [:set-user-profile %])}))
(reg-event-db
:set-user-profile
(fn [db [_ user-profile]]
(assoc db :user-profile user-profile)))
(defn save-user-address [params]
(POST "/api/user/address"

View File

@ -1,6 +1,7 @@
(ns commiteth.profile.page
(:require [re-frame.core :as rf]
[commiteth.common :refer [input]]))
[commiteth.common :refer [input]]
[commiteth.subscriptions :refer [user-address-path]]))
(defn save-address
[login address]
@ -10,12 +11,12 @@
(defn address-settings []
(let [user (rf/subscribe [:user])
login (:login @user)
address (rf/subscribe [:address])]
address (rf/subscribe [:get-in user-address-path])]
(fn []
[:div.form-group
[:label "Address"]
[input {:placeholder "Address"
:value-path [:address]}]
:value-path user-address-path}]
[:button.btn.btn-primary.btn-lg
{:on-click (save-address login @address)}
"Save"]])))

View File

@ -12,6 +12,8 @@
(:user db)))
(reg-sub
:address
(fn [db _]
(:address db)))
:get-in
(fn [db [_ path] ]
(get-in db path)))
(def user-address-path [:user-profile :user :address])