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

@ -1,11 +1,9 @@
(ns wanijo.domain.schema
(:require [clojurewerkz.neocons.rest.cypher :as cypher]
[clojure.spec.alpha :as spec]
[wanijo.neo4j :as neo4j]
[wanijo.devmode :as devmode]))
(:require [clojure.spec.alpha :as spec]
[wanijo.neo4j :as neo4j]))
(spec/def ::name
(spec/and string? not-empty int?))
(spec/and string? not-empty))
(spec/def ::created-at
(spec/or :int (spec/and int?
@ -13,13 +11,27 @@
:str (spec/and string?
#(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!
:query
"MATCH (s:schema)-[:created_by]->(u:user)
WHERE u.ident = {ident}
WHERE u.uuid = {uuid}
RETURN s
ORDER BY s.name"
:params {:ident ident}
:alias "s"
))
:params {:uuid user-uuid}
: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]))
(defn find! [ident]
(first
(neo4j/query-rawdata!
:query
"MATCH (n:user)
WHERE n.ident = {ident}
RETURN n"
:alias "n"
:params {:ident ident}))
:params {:ident ident})))

@ -6,7 +6,7 @@
:refer [wrap-defaults site-defaults]]
[ring.util.response :as rur]
[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.schema.routes :refer [schema-routes]]
[wanijo.devmode :as devmode]))

@ -24,7 +24,8 @@
(defn query-rawdata!
[& {:keys [query alias params]
:or {params {}}}]
(devmode/send-to-bar (str (butiful-query query)
(devmode/send-to-bar
(str (butiful-query query)
"<br>---Params---<br>"
params))
(->>

@ -14,8 +14,9 @@
(defn- overview! [req]
(let [session (:session req)
ident (:ident session)
schemas (domain-schema/all-created-by! ident)]
uuid (:uuid session)
schemas (domain-schema/all-created-by! uuid)]
(println schemas)
(page/layout!
:session session
:content
@ -39,7 +40,11 @@
(defn- new! [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)))
(defroutes schema-routes

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

Loading…
Cancel
Save