Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature login page #13

Merged
merged 2 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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