Skip to content

Commit

Permalink
Feature login page (#13)
Browse files Browse the repository at this point in the history
* Add login page

Co-authored-by: Iain Wood <iain.wood@flexiana.com>

* Fix header margin

Co-authored-by: Iain Wood <iain.wood@flexiana.com>

---------

Co-authored-by: Iain Wood <iain.wood@flexiana.com>
  • Loading branch information
gmsvalente and Iain Wood authored Dec 8, 2023
1 parent b724a06 commit e66efda
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
(ns {{main/ns}}.controllers.auth
(:require
[ring.util.response :refer [response]]))

;;; TODO
;;; Authenticate fn is just a placeholder you need to implement the logic to handle the login data sent from the login page

(defn authenticate
[state]
(let [req-form-params (get-in state [:request :form-params])]
(assoc state :response (response (str req-form-params)))))
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
(ns {{main/ns}}.controllers.login
(:require
[ring.util.response :refer [response]]
[hiccup.page :as hp]))

(defn page
[]
(hp/html5
[:body {:style {:height "400px"}}
[:div {:style {:height "100%"
:display "flex"
:align-items "center"
:justify-content "center"
:flex-direction "column"}}
[:h1 {:style {:margin-bottom "80px"}}
(str "{{main/ns}}")]
[:form {:action "/auth"
:method "post"}
[:div {:style {:display "flex"
:flex-direction "column"}}
[:label "Username"]
[:input {:type "text"
:id "username"
:name "username"
:placeholder "Username"}]]

[:div {:style {:display "flex"
:flex-direction "column"}}
[:label "Password"]
[:input {:type "password"
:id "password"
:name "password"
:placeholder "Password"}]]
[:input {:type "submit"
:value (str "Login")}]]]]))

(defn login-page
[state]
(assoc state :response (response (page))))
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
[{{main/ns}}.controllers.index :as index]
[{{main/ns}}.controllers.re-frame :as re-frame]
[{{main/ns}}.controllers.swagger :as swc]
[{{main/ns}}.controllers.auth :refer [authenticate]]
[{{main/ns}}.controllers.login :refer [login-page]]
[xiana.config :as config]
[xiana.db :as db]
[xiana.interceptor :as interceptors]
Expand All @@ -21,6 +23,8 @@
^:no-doc ["/re-frame" {:action #'re-frame/handle-index
:swagger {:produces ["text/html"]}}]
^:no-doc ["/assets/*" (ring/create-resource-handler {:path "/"})]
["/login" {:get {:action #'login-page}}]
["/auth" {:post {:action #'authenticate}}]
["/api" {:post {:action #'index/handle-post
:parameters {:body {:first-name string?
:last-name string?
Expand Down
2 changes: 2 additions & 0 deletions resources/flexiana/xiana_unstable/template.edn
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

["build/src/backend/app_name/controllers" "src/backend/{{main/file}}/controllers"
{"re_frame.tmpl" "re_frame.clj"
"login.tmpl" "login.clj"
"auth.tmpl" "auth.clj"
"index.tmpl" "index.clj"
"swagger.tmpl" "swagger.clj"}]

Expand Down

0 comments on commit e66efda

Please sign in to comment.