From abdf9301a47391080c4d46db3eeda125a155480c Mon Sep 17 00:00:00 2001 From: Akihito Terazawa Date: Wed, 12 Jul 2017 10:24:06 +0900 Subject: [PATCH 1/4] Enable oauth2.0 authentication. --- .../job_streamer/console/components/root.cljs | 84 +++++++++++-------- 1 file changed, 51 insertions(+), 33 deletions(-) diff --git a/src/cljs/job_streamer/console/components/root.cljs b/src/cljs/job_streamer/console/components/root.cljs index 8038fd2..c99b4b6 100644 --- a/src/cljs/job_streamer/console/components/root.cljs +++ b/src/cljs/job_streamer/console/components/root.cljs @@ -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.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.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"]]]]]]]))) + (for [[id {:keys [name icon]}] oauth-providers] + [:div.ui.segment + [:form.ui.large.login.form + {:on-submit (fn [e] + (.preventDefault e) + (set! (.-href js/location) (api/url-for (str "/oauth/" id))))} + [:button.ui.fluid.large.teal.submit.button {:type "submit"} + [:i.icon {:class (or icon "openid")}] + (str "Login using " name)]]])]]]]]]))) From fb52851983ff5821f835cf2190209c0a6ff9c887 Mon Sep 17 00:00:00 2001 From: Akihito Terazawa Date: Fri, 14 Jul 2017 09:44:25 +0900 Subject: [PATCH 2/4] Sophisticated OAuth login form. --- .../job_streamer/console/components/root.cljs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/cljs/job_streamer/console/components/root.cljs b/src/cljs/job_streamer/console/components/root.cljs index c99b4b6..1b53780 100644 --- a/src/cljs/job_streamer/console/components/root.cljs +++ b/src/cljs/job_streamer/console/components/root.cljs @@ -397,13 +397,13 @@ [:button.ui.fluid.large.teal.submit.button{:type "submit"} "Login"]]]]] [:div.row [:div.column - [:div.ui.stacked.segment - (for [[id {:keys [name icon]}] oauth-providers] + [:div.ui.stacked.segments + (for [[id {:keys [name class-name]}] oauth-providers] [:div.ui.segment - [:form.ui.large.login.form - {:on-submit (fn [e] - (.preventDefault e) - (set! (.-href js/location) (api/url-for (str "/oauth/" id))))} - [:button.ui.fluid.large.teal.submit.button {:type "submit"} - [:i.icon {:class (or icon "openid")}] - (str "Login using " name)]]])]]]]]]))) + [: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)]])]]]]]]))) + From 6b462fa7f24fcb4b2f80c91664068e1b875fe614 Mon Sep 17 00:00:00 2001 From: Akihito Terazawa Date: Fri, 14 Jul 2017 14:57:39 +0900 Subject: [PATCH 3/4] Remove oauth form if no oauth config. --- .../job_streamer/console/components/root.cljs | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/cljs/job_streamer/console/components/root.cljs b/src/cljs/job_streamer/console/components/root.cljs index 1b53780..4e63b84 100644 --- a/src/cljs/job_streamer/console/components/root.cljs +++ b/src/cljs/job_streamer/console/components/root.cljs @@ -395,15 +395,16 @@ (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)]])]]]]]]))) + (when (not-empty oauth-providers) + [: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)]])]]])]]]))) From ea671ebbd5e301f70eac97d27e9af3830d61015c Mon Sep 17 00:00:00 2001 From: seki Date: Fri, 14 Jul 2017 18:07:30 +0900 Subject: [PATCH 4/4] Fixed the virsion for release. --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 90a27f9..29fa924 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.0.5 +1.1.0-BETA