major structure overhaul

integration-tests
Josha von Gizycki 7 years ago
parent b62c25df8d
commit 82cd9ed367

@ -1,15 +1,15 @@
(ns wanijo.auth
(ns wanijo.framework.auth
(:require [compojure.core :refer [POST GET defroutes]]
[ring.util.response :refer [redirect]]
[ring.util.anti-forgery :refer [anti-forgery-field]]
[buddy.hashers :as hashers]
[hiccup.form :as hform]
[wanijo.view.page :as page]
[wanijo.domain.user :as domain-user]))
[wanijo.framework.view :as view]
[wanijo.user.domain :as user-domain]))
(defn- login-check! [req]
(let [{{:keys [uname pw]} :params} req
unode (domain-user/find! uname)
unode (user-domain/find! uname)
pwmatch (when-let [hash (:pw unode)]
(hashers/check pw hash))]
(if pwmatch
@ -20,7 +20,7 @@
(assoc :flash :invalid-credentials)))))
(defn login [req]
(page/layout!
(view/layout!
:content
[[:h1 "Kama ken"]
(hform/form-to

@ -1,4 +1,4 @@
(ns wanijo.devmode
(ns wanijo.framework.devmode
(:require [hiccup.core :as hcore]))
(def bar-entries (atom []))

@ -0,0 +1,43 @@
(ns wanijo.framework.form
(:require [clojure.spec.alpha :as spec]
[hiccup.form :as hform]
[wanijo.framework.view :as view]))
(defn spec-to-errmsg [label spec-key field-value]
(view/flash-error
(map
(fn [prob]
[:p
"Field "
[:span.flash__field label]
" must comply to "
[:span.flash__pred (:pred prob)]])
(:clojure.spec.alpha/problems
(spec/explain-data spec-key field-value)))))
(defn field-valid? [value spec-key req]
(or (empty? (:form-params req))
(spec/valid? spec-key value)))
(defn field [form-def field req]
(let [field-value (get-in req [:params field])
field-def (get-in form-def [:fields field])
{:keys [label required] spec-key :spec} field-def]
(list
(when-not (field-valid? field-value spec-key req)
(spec-to-errmsg label spec-key field-value))
(hform/label field label)
(hform/text-field {:required (when required "required")}
field
field-value))))
(defn valid? [form-def req]
(reduce-kv
(fn [result field value]
(if-let [field-spec (get-in form-def [:fields field :spec])]
(if (spec/valid? field-spec value)
true
(reduced false))
result))
true
(:params req)))

@ -1,6 +1,7 @@
(ns wanijo.neo4j
(ns wanijo.framework.neo4j
(:require [neo4j-clj.core :as db]
[wanijo.devmode :as devmode]))
[wanijo.framework.devmode :as devmode])
(:import (java.util UUID)))
(def conn
(delay (db/connect
@ -11,7 +12,7 @@
(defmacro defquery [& args] `(db/defquery ~@args))
(defn uuid []
(str (java.util.UUID/randomUUID)))
(str (UUID/randomUUID)))
(defn butiful-query [qry]
(->> qry

@ -1,4 +1,4 @@
(ns wanijo.repl
(ns wanijo.framework.repl
(:require [buddy.hashers :as hashers]
[neo4j-clj.core :as db]
[wanijo.neo4j :as neo4j]))

@ -0,0 +1,49 @@
(ns wanijo.framework.view
(:require [hiccup.page :refer
[html5 include-css]]))
(defn btnlink
([target caption]
(btnlink target caption ""))
([target caption class]
[:a {:href target}
[:button {:class class}
caption]]))
(defn layout!
[& {:keys [content title session]
:or {content []
title nil
session {}}}]
(let [ident (:ident session)
authed? (some? ident)
devmode? (:devmode session)]
(html5
[:head
[:meta {:charset "utf-8"}]
[: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")
(when devmode? (include-css "/css/devmode.css"))]
[:body
[:section.grid
[:header
[:h1.app-title "wan ijo"
(when authed?
[:small.app-title__hello
(str "O, " ident)])]
(when authed?
[:section.header-content
(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")]
[:footer
[:small "Ilo pali e ijo"]]]])))
(defn flash-error [content]
[:section.flash--error
[:h2.flash__heading--error "Pakala"]
content])

@ -6,10 +6,10 @@
:refer [wrap-defaults site-defaults]]
[ring.util.response :as rur]
[ring.middleware.session.cookie :as session-cookie]
[wanijo.auth :refer [auth-routes]]
[wanijo.home.routes :refer [home-routes]]
[wanijo.schema.routes :refer [schema-routes]]
[wanijo.devmode :as devmode]))
[wanijo.framework.auth :refer [auth-routes]]
[wanijo.framework.devmode :as devmode]))
(defn- wrap-login-redirect [handler]
(fn [req]

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

@ -1,6 +1,6 @@
(ns wanijo.domain.schema
(ns wanijo.schema.domain
(:require [clojure.spec.alpha :as spec]
[wanijo.neo4j :as neo4j]))
[wanijo.framework.neo4j :as neo4j]))
(spec/def ::name
(spec/and string? not-empty))

@ -1,14 +1,15 @@
(ns wanijo.schema.routes
(:require [compojure.core :refer [defroutes GET POST]]
[ring.util.response :as resp]
[wanijo.domain.schema :as domain-schema]
[wanijo.view.forms :as forms]
[wanijo.framework.view :as view]
[wanijo.framework.form :as form]
[wanijo.schema.domain :as domain]
[wanijo.schema.view :as view-schema]))
(defn- new! [req]
(if (forms/valid? view-schema/new-form req)
(if (form/valid? view-schema/new-form req)
(do
(domain-schema/create-new!
(domain/create-new!
(get-in req [:params :schema-name])
(get-in req [:session :uuid]))
(resp/redirect "/schema"))

@ -1,9 +1,9 @@
(ns wanijo.schema.view
(:require [hiccup.form :as hform]
[ring.util.anti-forgery :refer [anti-forgery-field]]
[wanijo.view.page :as page]
[wanijo.domain.schema :as domain-schema]
[wanijo.view.forms :as forms]))
[wanijo.framework.view :as view]
[wanijo.framework.form :as form]
[wanijo.schema.domain :as domain]))
(def new-form
{:fields {:schema-name {:label "Nimi"
@ -13,8 +13,8 @@
(defn overview! [req]
(let [session (:session req)
uuid (:uuid session)
schemas (domain-schema/all-created-by! uuid)]
(page/layout!
schemas (domain/all-created-by! uuid)]
(view/layout!
:session session
:content
[[:h1 "Ali jaki ijo"]
@ -31,6 +31,6 @@
[:h1 "Pali sin e jaki ijo"]
(hform/form-to
[:post "/schema/new"]
(forms/field new-form :schema-name req)
(form/field new-form :schema-name req)
(hform/submit-button "Pali")
(anti-forgery-field))])))

@ -1,5 +1,5 @@
(ns wanijo.domain.user
(:require [wanijo.neo4j :as neo4j]))
(ns wanijo.user.domain
(:require [wanijo.framework.neo4j :as neo4j]))
(neo4j/defquery
find-user

@ -1,43 +0,0 @@
(ns wanijo.view.forms
(:require [hiccup.form :as hform]
[clojure.spec.alpha :as spec]
[wanijo.view.page :as page]))
(defn spec-to-errmsg [label spec-key field-value]
(page/flash-error
(map
(fn [prob]
[:p
"Field "
[:span.flash__field label]
" must comply to "
[:span.flash__pred (:pred prob)]])
(:clojure.spec.alpha/problems
(spec/explain-data spec-key field-value)))))
(defn field-valid? [value spec-key req]
(or (empty? (:form-params req))
(spec/valid? spec-key value)))
(defn field [form-def field req]
(let [field-value (get-in req [:params field])
field-def (get-in form-def [:fields field])
{:keys [label required] spec-key :spec} field-def]
(list
(when-not (field-valid? field-value spec-key req)
(spec-to-errmsg label spec-key field-value))
(hform/label field label)
(hform/text-field {:required (when required "required")}
field
field-value))))
(defn valid? [form-def req]
(reduce-kv
(fn [result field value]
(if-let [field-spec (get-in form-def [:fields field :spec])]
(if (spec/valid? field-spec value)
true
(reduced false))
result))
true
(:params req)))

@ -1,49 +0,0 @@
(ns wanijo.view.page
(:require [hiccup.page :refer
[html5 include-css]]))
(defn btnlink
([target caption]
(btnlink target caption ""))
([target caption class]
[:a {:href target}
[:button {:class class}
caption]]))
(defn layout!
[& {:keys [content title session]
:or {content []
title nil
session {}}}]
(let [ident (:ident session)
authed? (some? ident)
devmode? (:devmode session)]
(html5
[:head
[:meta {:charset "utf-8"}]
[: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")
(when devmode? (include-css "/css/devmode.css"))]
[:body
[:section.grid
[:header
[:h1.app-title "wan ijo"
(when authed?
[:small.app-title__hello
(str "O, " ident)])]
(when authed?
[:section.header-content
(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")]
[:footer
[:small "Ilo pali e ijo"]]]])))
(defn flash-error [content]
[:section.flash--error
[:h2.flash__heading--error "Pakala"]
content])
Loading…
Cancel
Save