move auth.clj, creating schemas, fixing typos

integration-tests
Josha von Gizycki 7 years ago
parent 5e61ab10b7
commit d7947c431a

@ -1,10 +1,10 @@
(ns wanijo.auth.routes (ns wanijo.auth
(: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]] [ring.util.anti-forgery :refer [anti-forgery-field]]
[buddy.hashers :as hashers] [buddy.hashers :as hashers]
[hiccup.form :as hform] [hiccup.form :as hform]
[wanijo.view :as view] [wanijo.view.page :as page]
[wanijo.domain.user :as domain-user])) [wanijo.domain.user :as domain-user]))
(defn- login-check! [req] (defn- login-check! [req]
@ -14,12 +14,13 @@
(hashers/check pw hash))] (hashers/check pw hash))]
(if pwmatch (if pwmatch
(-> (redirect "/") (-> (redirect "/")
(assoc-in [:session :ident] uname)) (assoc-in [:session :ident] uname)
(assoc-in [:session :uuid] (:uuid unode)))
(-> (redirect "/login") (-> (redirect "/login")
(assoc :flash :invalid-credentials))))) (assoc :flash :invalid-credentials)))))
(defn login [req] (defn login [req]
(view/layout! (page/layout!
:content :content
[[:h1 "Kama ken"] [[:h1 "Kama ken"]
(hform/form-to (hform/form-to

@ -1,11 +1,9 @@
(ns wanijo.domain.schema (ns wanijo.domain.schema
(:require [clojurewerkz.neocons.rest.cypher :as cypher] (:require [clojure.spec.alpha :as spec]
[clojure.spec.alpha :as spec] [wanijo.neo4j :as neo4j]))
[wanijo.neo4j :as neo4j]
[wanijo.devmode :as devmode]))
(spec/def ::name (spec/def ::name
(spec/and string? not-empty int?)) (spec/and string? not-empty))
(spec/def ::created-at (spec/def ::created-at
(spec/or :int (spec/and int? (spec/or :int (spec/and int?
@ -13,13 +11,27 @@
:str (spec/and string? :str (spec/and string?
#(re-matches #"\d{4}\d{2}\d{2}\d{2}\d{2}\d{2}" %)))) #(re-matches #"\d{4}\d{2}\d{2}\d{2}\d{2}\d{2}" %))))
(defn all-created-by! [ident] (defn all-created-by! [user-uuid]
(neo4j/query-rawdata! (neo4j/query-rawdata!
:query :query
"MATCH (s:schema)-[:created_by]->(u:user) "MATCH (s:schema)-[:created_by]->(u:user)
WHERE u.ident = {ident} WHERE u.uuid = {uuid}
RETURN s RETURN s
ORDER BY s.name" ORDER BY s.name"
:params {:ident ident} :params {:uuid user-uuid}
:alias "s" :alias "s"))
))
(defn create-new! [name user-uid]
(:uuid
(neo4j/query-rawdata!
:query
"MATCH (u:user)
WHERE u.uuid = {u_uuid}
CREATE (s:schema)-[:created_by]->(u)
SET s.name = {name}
SET s.uuid = {s_uuid}
RETURN s"
:params {:u_uuid user-uid
:name name
:s_uuid (neo4j/uuid)}
:alias "s")))

@ -2,10 +2,11 @@
(:require [wanijo.neo4j :as neo4j])) (:require [wanijo.neo4j :as neo4j]))
(defn find! [ident] (defn find! [ident]
(neo4j/query-rawdata! (first
:query (neo4j/query-rawdata!
"MATCH (n:user) :query
WHERE n.ident = {ident} "MATCH (n:user)
RETURN n" WHERE n.ident = {ident}
:alias "n" RETURN n"
:params {:ident ident})) :alias "n"
:params {:ident ident})))

@ -6,7 +6,7 @@
:refer [wrap-defaults site-defaults]] :refer [wrap-defaults site-defaults]]
[ring.util.response :as rur] [ring.util.response :as rur]
[ring.middleware.session.cookie :as session-cookie] [ring.middleware.session.cookie :as session-cookie]
[wanijo.auth.routes :refer [auth-routes]] [wanijo.auth :refer [auth-routes]]
[wanijo.home.routes :refer [home-routes]] [wanijo.home.routes :refer [home-routes]]
[wanijo.schema.routes :refer [schema-routes]] [wanijo.schema.routes :refer [schema-routes]]
[wanijo.devmode :as devmode])) [wanijo.devmode :as devmode]))

@ -24,9 +24,10 @@
(defn query-rawdata! (defn query-rawdata!
[& {:keys [query alias params] [& {:keys [query alias params]
:or {params {}}}] :or {params {}}}]
(devmode/send-to-bar (str (butiful-query query) (devmode/send-to-bar
"<br>---Params---<br>" (str (butiful-query query)
params)) "<br>---Params---<br>"
params))
(->> (->>
(cypher/tquery (conn!) query params) (cypher/tquery (conn!) query params)
(map #(get % alias)) (map #(get % alias))

@ -14,8 +14,9 @@
(defn- overview! [req] (defn- overview! [req]
(let [session (:session req) (let [session (:session req)
ident (:ident session) uuid (:uuid session)
schemas (domain-schema/all-created-by! ident)] schemas (domain-schema/all-created-by! uuid)]
(println schemas)
(page/layout! (page/layout!
:session session :session session
:content :content
@ -39,7 +40,11 @@
(defn- new! [req] (defn- new! [req]
(if (forms/valid? new-schema-form req) (if (forms/valid? new-schema-form req)
(resp/redirect "/schema") (do
(domain-schema/create-new!
(get-in req [:params :schema-name])
(get-in req [:session :uuid]))
(resp/redirect "/schema"))
(overview! req))) (overview! req)))
(defroutes schema-routes (defroutes schema-routes

@ -32,13 +32,12 @@
field-value)))) field-value))))
(defn valid? [form-def req] (defn valid? [form-def req]
(clojure.pprint/pprint req)
(reduce-kv (reduce-kv
(fn [result field value] (fn [result field value]
(if (spec/valid? (if-let [field-spec (get-in form-def [:fields field :spec])]
(get-in form-def [:fields field :spec]) (if (spec/valid? field-spec value)
value) true
true (reduced false))
(reduced false))) result))
true true
(:params req))) (:params req)))

Loading…
Cancel
Save