restructuring, some neo4j, css -> less

integration-tests
Josha von Gizycki 7 years ago
parent a6f084d0b8
commit d90a5bede2

1
.gitignore vendored

@ -8,3 +8,4 @@ pom.xml.asc
*.class *.class
/.lein-* /.lein-*
/.nrepl-port /.nrepl-port
/resources/public/css

@ -2,14 +2,23 @@
:description "FIXME: write description" :description "FIXME: write description"
:url "http://example.com/FIXME" :url "http://example.com/FIXME"
:min-lein-version "2.0.0" :min-lein-version "2.0.0"
:dependencies [[org.clojure/clojure "1.8.0"] :dependencies [[org.clojure/clojure "1.9.0"]
[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"
:exclusions [commons-codec]]
[hiccup "1.0.5"] [hiccup "1.0.5"]
[buddy "2.0.0"]] [buddy "2.0.0"
:exclusions [cheshire
commons-codec
com.fasterxml.jackson.core/jackson-core
com.fasterxml.jackson.core/jackson-dataformat-smile
com.fasterxml.jackson.core/jackson-dataformat-cbor]]]
:plugins [[lein-ring "0.9.7"]] :plugins [[lein-ring "0.9.7"]]
:ring {:handler wanijo.handler/app} :ring {:handler wanijo.handler/app}
:profiles :profiles {:dev {:dependencies [[javax.servlet/servlet-api "2.5"]
{:dev {:dependencies [[javax.servlet/servlet-api "2.5"] [ring/ring-mock "0.3.0"]]
[ring/ring-mock "0.3.0"]]}}) :plugins [[lein-less "1.7.5"]]}}
:less {:source-paths ["resources/app/stylesheets"]
:target-path "resources/public/css"}
:hooks [leiningen.less])

@ -1,3 +1,8 @@
@ci-color: #ccc;
@text-padding-v: .2rem;
@text-padding-h: 1rem;
@accent-border-width: 1rem;
body { body {
font-family: sans-serif; font-family: sans-serif;
} }
@ -21,7 +26,7 @@ a:active {
"nav main sidebar" "nav main sidebar"
"footer footer footer"; "footer footer footer";
margin: auto; margin: auto;
max-width: 70%; max-width: 900px;
border-top: 1px solid #ccc; border-top: 1px solid #ccc;
} }
@ -39,15 +44,15 @@ aside {
header, footer, main, nav, aside { header, footer, main, nav, aside {
border-bottom: 1px solid #ccc; border-bottom: 1px solid #ccc;
padding: .2rem 1rem .2rem 1rem; padding: @text-padding-v @text-padding-h;
} }
header { header {
grid-area: header; grid-area: header;
display: grid; display: grid;
grid-template-columns: 20% 80%; grid-template-columns: 40% 60%;
align-items: center; align-items: center;
border-left: 1rem solid #ccc; border-left: @accent-border-width solid #ccc;
} }
.app-title { .app-title {
@ -57,7 +62,7 @@ header {
.app-title__hello { .app-title__hello {
font-size: 1rem; font-size: 1rem;
margin-left: 1rem; margin-left: @text-padding-h;
font-weight: normal; font-weight: normal;
font-style: italic; font-style: italic;
} }
@ -68,7 +73,8 @@ header {
.header-content__link { .header-content__link {
display: inline-block; display: inline-block;
padding: .2rem .5rem; padding: @text-padding-v @text-padding-h / 2;
margin-right: @accent-border-width;
} }
footer { footer {
@ -79,29 +85,24 @@ form {
display: grid; display: grid;
grid-template-columns: 30% 70%; grid-template-columns: 30% 70%;
grid-auto-flow: row; grid-auto-flow: row;
}
form label, label, input, select, textarea, .flash {
form input,
form select,
form textarea,
form section.flash {
margin-bottom: .7rem; margin-bottom: .7rem;
padding: .2rem .5rem; padding: @text-padding-v @text-padding-h / 2;
} }
form section.flash { label {
grid-column: 1/3;
border: 1px solid #ccc;
border-left-width: 1rem;
padding: .7rem;
}
form label {
grid-column: 1; grid-column: 1;
} }
form input, input, select {
form select {
grid-column: 2; grid-column: 2;
}
.flash {
grid-column: 1/3;
border: 1px solid #ccc;
border-left-width: @accent-border-width;
padding: .7rem;
}
} }

@ -1,13 +1,15 @@
(ns wanijo.auth.routes (ns wanijo.auth.routes
(:require [compojure.core :refer [POST GET defroutes]] (:require [compojure.core :refer [POST GET defroutes]]
[ring.util.response :refer [redirect]] [ring.util.response :refer [redirect]]
[ring.util.anti-forgery :refer [anti-forgery-field]]
[buddy.hashers :as hashers] [buddy.hashers :as hashers]
[wanijo.auth.view :as auth-view] [hiccup.form :as hform]
[wanijo.neo4j :as neo])) [wanijo.view :as view]
[wanijo.neo4j :as neo4j]))
(defn- login-check! [req] (defn- login-check! [req]
(let [{{:keys [uname pw]} :params} req (let [{{:keys [uname pw]} :params} req
unode (neo/find-user! uname) unode (neo4j/find-user! uname)
pwmatch (when-let [hash (:pw unode)] pwmatch (when-let [hash (:pw unode)]
(hashers/check pw hash))] (hashers/check pw hash))]
(if pwmatch (if pwmatch
@ -17,8 +19,25 @@
(-> (redirect "/login") (-> (redirect "/login")
(assoc :flash :invalid-credentials))))) (assoc :flash :invalid-credentials)))))
(defn login [req]
(view/layout!
:content
[[:h1 "Kama ken"]
(hform/form-to
[:post "/login-check"]
(when (:flash req) [:section.flash (:flash req)])
;;
(hform/label "uname" "Nimi")
(hform/text-field {:required "required"} "uname")
;;
(hform/label "pw" "Toki Pimeja")
(hform/password-field {:required "required"} "pw")
;;
(hform/submit-button "Kama")
(anti-forgery-field))]))
(defroutes auth-routes (defroutes auth-routes
(GET "/login" [] auth-view/login) (GET "/login" [] login)
(POST "/login-check" [] login-check!) (POST "/login-check" [] login-check!)
(GET "/logout" [] (fn [_] (-> (redirect "/login") (GET "/logout" [] (fn [_] (-> (redirect "/login")
(assoc :session nil))))) (assoc :session nil)))))

@ -1,22 +0,0 @@
(ns wanijo.auth.view
(:require [hiccup.form :as hf]
[wanijo.view :refer [layout]]
[ring.util.anti-forgery :refer [anti-forgery-field]]))
(defn login [req]
(layout
:authed? false
:content
[[:h1 "Kama ken"]
(hf/form-to
[:post "/login-check"]
(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))]))

@ -0,0 +1,14 @@
(ns wanijo.domain.schema
(:require [clojurewerkz.neocons.rest.cypher :as cypher]
[wanijo.neo4j :as neo4j]))
(defn all-created-by! [ident]
(->>
(cypher/tquery
neo4j/conn
"MATCH (s:schema)-[created_by]->(u:user)
WHERE u.ident = {ident}
RETURN s
ORDER BY s.created_at"
{:ident ident})
(map #(:data (get "s")))))

@ -1,14 +1,12 @@
(ns wanijo.handler (ns wanijo.handler
(:require [compojure.core :refer :all] (:require [compojure.core :refer [defroutes
routes]]
[compojure.route :as route] [compojure.route :as route]
[ring.middleware.defaults :refer [wrap-defaults site-defaults]] [ring.middleware.defaults :refer [wrap-defaults site-defaults]]
[ring.util.response :as rur] [ring.util.response :as rur]
[hiccup.page :as hp]
[wanijo.auth.routes :refer [auth-routes]] [wanijo.auth.routes :refer [auth-routes]]
[wanijo.view :refer [layout]])) [wanijo.home.routes :refer [home-routes]]
[wanijo.schema.routes :refer [schema-routes]]))
(defn- home [req]
(layout :title "home" :session (:session req)))
(defn- wrap-login-redirect [handler] (defn- wrap-login-redirect [handler]
(fn [req] (fn [req]
@ -19,7 +17,8 @@
(defroutes app-routes (defroutes app-routes
(routes auth-routes) (routes auth-routes)
(wrap-login-redirect (wrap-login-redirect
(GET "/" [] home)) (routes home-routes
schema-routes))
(route/not-found "Not Found")) (route/not-found "Not Found"))
(def app (def app

@ -0,0 +1,6 @@
(ns wanijo.home.routes
(:require [compojure.core :refer [defroutes GET]]
[wanijo.home.view :as home-view]))
(defroutes home-routes
(GET "/" [] home-view/root!))

@ -0,0 +1,5 @@
(ns wanijo.home.view
(:require [wanijo.view :as view]))
(defn root! [req]
(view/layout! :session (:session req)))

@ -1,12 +1,15 @@
(ns wanijo.repl (ns wanijo.repl
(:require [clojurewerkz.neocons.rest.nodes :as nodes] (:require [clojurewerkz.neocons.rest.nodes :as nodes]
[clojurewerkz.neocons.rest.labels :as labels] [clojurewerkz.neocons.rest.labels :as labels]
[clojurewerkz.neocons.rest.cypher :as cypher]
[buddy.hashers :as hashers] [buddy.hashers :as hashers]
[wanijo.neo4j :as neo4j])) [wanijo.neo4j :as neo4j]))
(defn create-user! [ident pw] (defn create-user! [ident pw]
(let [node (nodes/create (cypher/tquery
neo4j/conn neo4j/conn
"CREATE (n:user)
SET n.ident = {ident}
SET n.pw = {pw}"
{:ident ident {:ident ident
:pw (hashers/derive pw)})] :pw (hashers/derivce pw)}))
(labels/add neo4j/conn node "user")))

@ -0,0 +1,25 @@
(ns wanijo.schema.routes
(:require [compojure.core :refer [defroutes GET]]
[wanijo.domain.schema :as domain-schemas]
[wanijo.view :as view]))
(defn- overview! [req]
(let [session (:session req)
ident (:ident session)
schemas (domain-schemas/all-created-by! ident)]
(view/layout!
:session session
:content
[[:table
[:thead
[:tr
[:th "Nimi"]
[:th "Tenpo kama"]]]
[:tbody
(for [schema schemas]
[:tr
[:td (:name schema)]
[:td (:created_at schema)]])]]])))
(defroutes schema-routes
(GET "/schema" [] overview!))

@ -10,11 +10,12 @@
[:button {:class class} [:button {:class class}
caption]])) caption]]))
(defn layout (defn layout!
[& {:keys [content title session] [& {:keys [content title session]
:or {content [] :or {content []
title nil title nil
session {}}}] session {}}}]
(println session)
(let [ident (:ident session) (let [ident (:ident session)
authed? (some? ident)] authed? (some? ident)]
(html5 (html5
@ -33,10 +34,8 @@
(str "O, " ident)])] (str "O, " ident)])]
(when authed? (when authed?
[:section.header-content [:section.header-content
(btnlink (btnlink "/schema" "Jaki Ijo" "header-content__link")
"/logout" (btnlink "/logout" "Lape" "header-content__link")])]
"Lape"
"header-content__link")])]
[:nav (when authed? "nav")] [:nav (when authed? "nav")]
(vec (concat [:main] content)) (vec (concat [:main] content))
[:aside (when authed? "aside")] [:aside (when authed? "aside")]

Loading…
Cancel
Save