css experiments, neo4j

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

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

@ -2,6 +2,17 @@ body {
font-family: sans-serif;
}
a:link,
a:visited {
color: blue;
text-decoration: none;
}
a:hover,
a:active {
text-decoration: underline;
}
.grid {
display: grid;
grid-template-columns: 20% 70% 10%;
@ -33,27 +44,64 @@ header, footer, main, nav, aside {
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 {
grid-area: footer;
}
.form-group {
display: flex;
margin-bottom: 1rem;
form {
display: grid;
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 {
width: 30%;
form section.flash {
grid-column: 1/3;
border: 1px solid #ccc;
border-left-width: 1rem;
padding: .7rem;
}
.form-group input,
.form-group select {
width: 70%;
padding: .1rem;
form label {
grid-column: 1;
}
.form-group input[type=submit] {
width: auto;
form input,
form select {
grid-column: 2;
}

@ -1,11 +1,20 @@
(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]
(let [{{:keys [uname pw]} :params} req]
(if (and (= uname "admin")
(= pw "pw"))
(defn login-check! [req]
(let [{{:keys [uname pw]} :params} req
unode (neo/find-user! uname)
pwmatch (when-let [hash (:pw unode)]
(bh/check pw hash))]
(if pwmatch
(-> (rur/redirect "/")
(assoc-in [:session :ident] uname))
(assoc-in [:session :ident] uname)
(assoc-in [:session :unode] unode))
(-> (rur/redirect "/login")
(assoc :flash :invalid-credentials)))))
(defn logout [req]
(-> (rur/redirect "/login")
(assoc :session nil)))

@ -5,4 +5,5 @@
(defroutes auth-routes
(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]
(layout
:authed? false
:content [[:h1 "Login"]
:content
[[:h1 "Kama ken"]
(hf/form-to
[:post "/login-check"]
[:dif.form-group
(:flash req)]
[:div.form-group
(hf/label "uname" "Username")
[:input#uname {:name "uname"}]]
[:div.form-group
(hf/label "pw" "Password")
(hf/password-field {:id "pw"} "pw")]
[:div.form-group
(hf/submit-button "Login")]
(when (:flash req) [:section.flash (:flash req)])
;;
(hf/label "uname" "Nimi")
(hf/text-field {:required "required"} "uname")
;;
(hf/label "pw" "Toki Pimeja")
(hf/password-field {:required "required"} "pw")
;;
(hf/submit-button "Kama")
(anti-forgery-field))]))

@ -7,28 +7,21 @@
[wanijo.auth.routes :refer [auth-routes]]
[wanijo.view :refer [layout]]))
(defn- home [_]
(layout :title "home"))
(defroutes app-routes
(routes auth-routes)
(GET "/" [] home)
(route/not-found "Not Found"))
(defn- home [req]
(layout :title "home" :session (:session req)))
(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"))))
(if-not (get-in req [:session :ident])
(rur/redirect "/login")
(handler req)))))
(handler req))))
(defroutes app-routes
(routes auth-routes)
(wrap-login-redirect
(GET "/" [] home))
(route/not-found "Not Found"))
(def app
(-> app-routes
wrap-login-redirect
(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
(:require [hiccup.page :refer [html5]]))
(:require [hiccup.page :refer [html5
include-css]]))
(defn layout
[& {:keys [authed? content title]
:or {authed? true
content []
title "wan ijo"}}]
[& {:keys [content title session]
:or {content []
title nil
session {}}}]
(let [ident (:ident session)
authed? (some? ident)]
(html5
[:head
[:meta {:charset "utf-8"}]
[:title title]
[:link {:rel "stylesheet"
:href "/css/app.css"}]]
[:meta {:name "viewport"
:content "width=device-width,initial-scale=1,shrink-to-fit=no"}]
[:title (str "wan ijo" (when title (str " - " title)))]
(include-css "/css/app.css")]
[:body
[:section.grid
[:header
[:h1 "wan ijo"]]
[:h1.app-title "wan ijo"
(when authed?
[: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 "stuff with objects"]]]]))
[:small "Ilo pali e ijo"]]]])))

Loading…
Cancel
Save