css experiments, neo4j

integration-tests
Josha von Gizycki 7 years ago
parent 96e48825d2
commit 89f6e08c4f

@ -6,7 +6,8 @@
[compojure "1.5.1"] [compojure "1.5.1"]
[ring/ring-defaults "0.2.1"] [ring/ring-defaults "0.2.1"]
[clojurewerkz/neocons "3.2.0"] [clojurewerkz/neocons "3.2.0"]
[hiccup "1.0.5"]] [hiccup "1.0.5"]
[buddy "2.0.0"]]
:plugins [[lein-ring "0.9.7"]] :plugins [[lein-ring "0.9.7"]]
:ring {:handler wanijo.handler/app} :ring {:handler wanijo.handler/app}
:profiles :profiles

@ -2,6 +2,17 @@ body {
font-family: sans-serif; font-family: sans-serif;
} }
a:link,
a:visited {
color: blue;
text-decoration: none;
}
a:hover,
a:active {
text-decoration: underline;
}
.grid { .grid {
display: grid; display: grid;
grid-template-columns: 20% 70% 10%; grid-template-columns: 20% 70% 10%;
@ -33,27 +44,64 @@ header, footer, main, nav, aside {
header { header {
grid-area: header; grid-area: header;
display: grid;
grid-template-columns: 20% 80%;
align-items: center;
border-left: 1rem solid #ccc;
}
.app-title {
grid-column: 1;
font-size: 1.5rem;
}
.app-title__hello {
font-size: 1rem;
margin-left: 1rem;
font-weight: normal;
font-style: italic;
}
.header-content {
grid-column: 2;
}
.header-content__link {
padding-top: .5rem;
display: inline-block;
} }
footer { footer {
grid-area: footer; grid-area: footer;
} }
.form-group { form {
display: flex; display: grid;
margin-bottom: 1rem; grid-template-columns: 30% 70%;
grid-auto-flow: row;
}
form label,
form input,
form select,
form textarea,
form section.flash {
margin-bottom: .7rem;
padding: .2rem .5rem;
} }
.form-group label { form section.flash {
width: 30%; grid-column: 1/3;
border: 1px solid #ccc;
border-left-width: 1rem;
padding: .7rem;
} }
.form-group input, form label {
.form-group select { grid-column: 1;
width: 70%;
padding: .1rem;
} }
.form-group input[type=submit] { form input,
width: auto; form select {
grid-column: 2;
} }

@ -1,11 +1,20 @@
(ns wanijo.auth.handler (ns wanijo.auth.handler
(:require [ring.util.response :as rur])) (:require [ring.util.response :as rur]
[wanijo.neo4j :as neo]
[buddy.hashers :as bh]))
(defn login-check [req] (defn login-check! [req]
(let [{{:keys [uname pw]} :params} req] (let [{{:keys [uname pw]} :params} req
(if (and (= uname "admin") unode (neo/find-user! uname)
(= pw "pw")) pwmatch (when-let [hash (:pw unode)]
(bh/check pw hash))]
(if pwmatch
(-> (rur/redirect "/") (-> (rur/redirect "/")
(assoc-in [:session :ident] uname)) (assoc-in [:session :ident] uname)
(assoc-in [:session :unode] unode))
(-> (rur/redirect "/login") (-> (rur/redirect "/login")
(assoc :flash :invalid-credentials))))) (assoc :flash :invalid-credentials)))))
(defn logout [req]
(-> (rur/redirect "/login")
(assoc :session nil)))

@ -5,4 +5,5 @@
(defroutes auth-routes (defroutes auth-routes
(GET "/login" [] auth-view/login) (GET "/login" [] auth-view/login)
(POST "/login-check" [] auth-handler/login-check)) (POST "/login-check" [] auth-handler/login-check!)
(GET "/logout" [] auth-handler/logout))

@ -6,17 +6,17 @@
(defn login [req] (defn login [req]
(layout (layout
:authed? false :authed? false
:content [[:h1 "Login"] :content
(hf/form-to [[:h1 "Kama ken"]
[:post "/login-check"] (hf/form-to
[:dif.form-group [:post "/login-check"]
(:flash req)] (when (:flash req) [:section.flash (:flash req)])
[:div.form-group ;;
(hf/label "uname" "Username") (hf/label "uname" "Nimi")
[:input#uname {:name "uname"}]] (hf/text-field {:required "required"} "uname")
[:div.form-group ;;
(hf/label "pw" "Password") (hf/label "pw" "Toki Pimeja")
(hf/password-field {:id "pw"} "pw")] (hf/password-field {:required "required"} "pw")
[:div.form-group ;;
(hf/submit-button "Login")] (hf/submit-button "Kama")
(anti-forgery-field))])) (anti-forgery-field))]))

@ -7,28 +7,21 @@
[wanijo.auth.routes :refer [auth-routes]] [wanijo.auth.routes :refer [auth-routes]]
[wanijo.view :refer [layout]])) [wanijo.view :refer [layout]]))
(defn- home [_] (defn- home [req]
(layout :title "home")) (layout :title "home" :session (:session req)))
(defn- wrap-login-redirect [handler]
(fn [req]
(if-not (get-in req [:session :ident])
(rur/redirect "/login")
(handler req))))
(defroutes app-routes (defroutes app-routes
(routes auth-routes) (routes auth-routes)
(GET "/" [] home) (wrap-login-redirect
(GET "/" [] home))
(route/not-found "Not Found")) (route/not-found "Not Found"))
(defn- wrap-login-redirect [handler]
(fn [req]
(let [ident (get-in req [:session :ident])
uri (:uri req)]
(println ident (:session req))
(if (and (nil? ident)
(not (or (clojure.string/ends-with? uri ".css")
(clojure.string/ends-with? uri ".js")
(= uri "/login-check")
(= uri "/login"))))
(rur/redirect "/login")
(handler req)))))
(def app (def app
(-> app-routes (-> app-routes
wrap-login-redirect
(wrap-defaults site-defaults))) (wrap-defaults site-defaults)))

@ -0,0 +1,16 @@
(ns wanijo.neo4j
(:require [clojurewerkz.neocons.rest :as nr]
[clojurewerkz.neocons.rest.nodes :as nrn]
[clojurewerkz.neocons.rest.cypher :as nrc]))
(def conn (nr/connect "http://neo4j:b@localhost:7474/db/data"))
(defn find-user! [ident]
(some->
(nrc/tquery
conn
"MATCH (n:user) WHERE n.ident = {ident} RETURN n"
{:ident ident})
first
(get "n")
:data))

@ -1,23 +1,34 @@
(ns wanijo.view (ns wanijo.view
(:require [hiccup.page :refer [html5]])) (:require [hiccup.page :refer [html5
include-css]]))
(defn layout (defn layout
[& {:keys [authed? content title] [& {:keys [content title session]
:or {authed? true :or {content []
content [] title nil
title "wan ijo"}}] session {}}}]
(html5 (let [ident (:ident session)
[:head authed? (some? ident)]
[:meta {:charset "utf-8"}] (html5
[:title title] [:head
[:link {:rel "stylesheet" [:meta {:charset "utf-8"}]
:href "/css/app.css"}]] [:meta {:name "viewport"
[:body :content "width=device-width,initial-scale=1,shrink-to-fit=no"}]
[:section.grid [:title (str "wan ijo" (when title (str " - " title)))]
[:header (include-css "/css/app.css")]
[:h1 "wan ijo"]] [:body
[:nav (when authed? "nav")] [:section.grid
(vec (concat [:main] content)) [:header
[:aside (when authed? "aside")] [:h1.app-title "wan ijo"
[:footer (when authed?
[:small "stuff with objects"]]]])) [:small.app-title__hello
(str "O, " ident)])]
(when authed?
[:section.header-content
[:a.header-content__link {:href "/logout"}
"Lape"]])]
[:nav (when authed? "nav")]
(vec (concat [:main] content))
[:aside (when authed? "aside")]
[:footer
[:small "Ilo pali e ijo"]]]])))

Loading…
Cancel
Save