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
/.lein-*
/.nrepl-port
/resources/public/css

@ -2,14 +2,23 @@
:description "FIXME: write description"
:url "http://example.com/FIXME"
:min-lein-version "2.0.0"
:dependencies [[org.clojure/clojure "1.8.0"]
:dependencies [[org.clojure/clojure "1.9.0"]
[compojure "1.5.1"]
[ring/ring-defaults "0.2.1"]
[clojurewerkz/neocons "3.2.0"]
[clojurewerkz/neocons "3.2.0"
:exclusions [commons-codec]]
[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"]]
:ring {:handler wanijo.handler/app}
:profiles
{:dev {:dependencies [[javax.servlet/servlet-api "2.5"]
[ring/ring-mock "0.3.0"]]}})
:profiles {:dev {:dependencies [[javax.servlet/servlet-api "2.5"]
[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 {
font-family: sans-serif;
}
@ -21,7 +26,7 @@ a:active {
"nav main sidebar"
"footer footer footer";
margin: auto;
max-width: 70%;
max-width: 900px;
border-top: 1px solid #ccc;
}
@ -39,15 +44,15 @@ aside {
header, footer, main, nav, aside {
border-bottom: 1px solid #ccc;
padding: .2rem 1rem .2rem 1rem;
padding: @text-padding-v @text-padding-h;
}
header {
grid-area: header;
display: grid;
grid-template-columns: 20% 80%;
grid-template-columns: 40% 60%;
align-items: center;
border-left: 1rem solid #ccc;
border-left: @accent-border-width solid #ccc;
}
.app-title {
@ -57,7 +62,7 @@ header {
.app-title__hello {
font-size: 1rem;
margin-left: 1rem;
margin-left: @text-padding-h;
font-weight: normal;
font-style: italic;
}
@ -68,7 +73,8 @@ header {
.header-content__link {
display: inline-block;
padding: .2rem .5rem;
padding: @text-padding-v @text-padding-h / 2;
margin-right: @accent-border-width;
}
footer {
@ -79,29 +85,24 @@ form {
display: grid;
grid-template-columns: 30% 70%;
grid-auto-flow: row;
}
form label,
form input,
form select,
form textarea,
form section.flash {
label, input, select, textarea, .flash {
margin-bottom: .7rem;
padding: .2rem .5rem;
}
form section.flash {
grid-column: 1/3;
border: 1px solid #ccc;
border-left-width: 1rem;
padding: .7rem;
padding: @text-padding-v @text-padding-h / 2;
}
form label {
label {
grid-column: 1;
}
form input,
form select {
input, select {
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
(:require [compojure.core :refer [POST GET defroutes]]
[ring.util.response :refer [redirect]]
[ring.util.anti-forgery :refer [anti-forgery-field]]
[buddy.hashers :as hashers]
[wanijo.auth.view :as auth-view]
[wanijo.neo4j :as neo]))
[hiccup.form :as hform]
[wanijo.view :as view]
[wanijo.neo4j :as neo4j]))
(defn- login-check! [req]
(let [{{:keys [uname pw]} :params} req
unode (neo/find-user! uname)
unode (neo4j/find-user! uname)
pwmatch (when-let [hash (:pw unode)]
(hashers/check pw hash))]
(if pwmatch
@ -17,8 +19,25 @@
(-> (redirect "/login")
(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
(GET "/login" [] auth-view/login)
(GET "/login" [] login)
(POST "/login-check" [] login-check!)
(GET "/logout" [] (fn [_] (-> (redirect "/login")
(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
(:require [compojure.core :refer :all]
(:require [compojure.core :refer [defroutes
routes]]
[compojure.route :as route]
[ring.middleware.defaults :refer [wrap-defaults site-defaults]]
[ring.util.response :as rur]
[hiccup.page :as hp]
[wanijo.auth.routes :refer [auth-routes]]
[wanijo.view :refer [layout]]))
(defn- home [req]
(layout :title "home" :session (:session req)))
[wanijo.home.routes :refer [home-routes]]
[wanijo.schema.routes :refer [schema-routes]]))
(defn- wrap-login-redirect [handler]
(fn [req]
@ -19,7 +17,8 @@
(defroutes app-routes
(routes auth-routes)
(wrap-login-redirect
(GET "/" [] home))
(routes home-routes
schema-routes))
(route/not-found "Not Found"))
(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
(:require [clojurewerkz.neocons.rest.nodes :as nodes]
[clojurewerkz.neocons.rest.labels :as labels]
[clojurewerkz.neocons.rest.cypher :as cypher]
[buddy.hashers :as hashers]
[wanijo.neo4j :as neo4j]))
(defn create-user! [ident pw]
(let [node (nodes/create
(cypher/tquery
neo4j/conn
"CREATE (n:user)
SET n.ident = {ident}
SET n.pw = {pw}"
{:ident ident
:pw (hashers/derive pw)})]
(labels/add neo4j/conn node "user")))
:pw (hashers/derivce pw)}))

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

Loading…
Cancel
Save