Skip to content

Commit

Permalink
Merge pull request #119 from miyamoen/feature/oauth-authn
Browse files Browse the repository at this point in the history
Feature/oauth authn
  • Loading branch information
kkasai authored Jul 14, 2017
2 parents 23248d4 + fb52851 commit dfeaf7a
Showing 1 changed file with 52 additions and 34 deletions.
86 changes: 52 additions & 34 deletions src/cljs/job_streamer/console/components/root.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -349,43 +349,61 @@
(init-state [_]
{:errors nil
:username ""
:password ""})
(render-state [_ {:keys [username password errors]}]
:password ""
:oauth-providers {}})
(will-mount [_]
(api/request "/oauth" :GET
{:handler (fn [response]
(om/set-state! owner :oauth-providers response))}))
(render-state [_ {:keys [username password errors oauth-providers]}]
(html
[:div.full.height
[:div.ui.fixed.inverted.teal.menu
[:div.header.item [:img.ui.image {:alt "JobStreamer" :src "/img/logo.png"}]]]
[:div.main.grid.content.full.height
[:div.ui.middle.aligned.center.aligned.login.grid
[:div.column
[:h2.ui.header
[:div.content
[:img.ui.image {:src "/img/logo.png"}]]]
[:form.ui.large.login.form
(merge {:on-submit (fn [e]
(.preventDefault e)
(api/request (api/url-for "/auth") :POST
{:user/id username :user/password password}
{:handler #(set! (.-href js/location) "/")
:error-handler #(om/set-state! owner :errors (or (:messages %)
["A Control bus is NOT found."]))
:unauthorized-handler #(om/set-state! owner :errors (:messages %))}))}
(when errors {:class "error"}))
[:div.ui.stacked.segment
[:div.ui.error.message
(map #(vec [:p %]) errors)]
[:div.field
[:div.ui.left.icon.input
[:i.user.icon]
[:input {:type "text" :name "username" :id "username" :placeholder "User name" :value username
:on-change (fn [e]
(let [username (.. js/document (getElementById "username") -value)]
(om/set-state! owner :username username)))}]]]
[:div.field
[:div.ui.left.icon.input
[:i.lock.icon]
[:input {:type "password" :name "password" :id "password" :placeholder "Password" :value password
:on-change (fn [e]
(let [password (.. js/document (getElementById "password") -value)]
(om/set-state! owner :password password)))}]]]
[:button.ui.fluid.large.teal.submit.button{:type "submit"} "Login"]]]]]]])))
[:div.row
[:div.column
[:h2.ui.header
[:div.content
[:img.ui.image {:src "/img/logo.png"}]]]
[:form.ui.large.login.form
(merge {:on-submit (fn [e]
(.preventDefault e)
(api/request (api/url-for "/auth") :POST
{:user/id username :user/password password}
{:handler #(set! (.-href js/location) "/")
:error-handler #(om/set-state! owner :errors (or (:messages %)
["A Control bus is NOT found."]))
:unauthorized-handler #(om/set-state! owner :errors (:messages %))}))}
(when errors {:class "error"}))
[:div.ui.stacked.segment
[:div.ui.error.message
(map #(vec [:p %]) errors)]
[:div.field
[:div.ui.left.icon.input
[:i.user.icon]
[:input {:type "text" :name "username" :id "username" :placeholder "User name" :value username
:on-change (fn [e]
(let [username (.. js/document (getElementById "username") -value)]
(om/set-state! owner :username username)))}]]]
[:div.field
[:div.ui.left.icon.input
[:i.lock.icon]
[:input {:type "password" :name "password" :id "password" :placeholder "Password" :value password
:on-change (fn [e]
(let [password (.. js/document (getElementById "password") -value)]
(om/set-state! owner :password password)))}]]]
[:button.ui.fluid.large.teal.submit.button{:type "submit"} "Login"]]]]]
[:div.row
[:div.column
[:div.ui.stacked.segments
(for [[id {:keys [name class-name]}] oauth-providers]
[:div.ui.segment
[:button.ui.fluid.large.button {:class (or class-name "teal")
:on-click (fn [e]
(.preventDefault e)
(set! (.-href js/location) (api/url-for (str "/oauth/" id))))}
[:i.icon {:class (or class-name "openid")}]
(str "Login using " name)]])]]]]]])))

0 comments on commit dfeaf7a

Please sign in to comment.