Skip to content

Instantly share code, notes, and snippets.

@zentrope zentrope/login.cljs
Last active Aug 29, 2015

What would you like to do?
(defn- handle-change
[e owner field]
(om/set-state! owner field (value! owner (name field))))
(defn- handle-submit
[state owner]
(om/set-state! owner :error-msg "")
(let [{:keys [user pass]} (om/get-state owner)
creds {:user user :pass pass}
response (chan)]
(net/log-in! response creds)
(take! response (fn [[topic msg]]
(case topic
:login-pass (set-auth! state true user)
:login-fail (om/set-state! owner :error-msg "Unable to auth.")
(defn- login-component
[state owner opts]
(init-state [_]
{:user "" :pass "" :error-msg ""})
;; om/IDidMount
;; (did-mount [_]
;; (focus! owner "user"))
(render-state [_ {:keys [user pass error-msg]}]
(dom/section nil
(dom/h1 nil "Log in")
(dom/table nil
(dom/tr nil
(dom/th nil "account")
(dom/td nil
(dom/input #js {:ref "user" :type "text" :maxsize "50"
:onChange #(handle-change % owner :user)
:value user})))
(dom/tr nil
(dom/th nil "password")
(dom/td nil
(dom/input #js {:ref "pass" :type "password" :maxsize "50"
:onChange #(handle-change % owner :pass)
:value pass}))))
(dom/p nil error-msg)
(dom/div nil
(dom/button #js {:onClick #(handle-submit state owner)} "SIGN IN"))))))

This comment has been minimized.

Copy link
Owner Author

zentrope commented May 16, 2014

Broken in OM 0.6.1 and above?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.