integration-tests
Josha von Gizycki 6 years ago
parent 88213b8d5d
commit ee21f5f7c1

@ -5,13 +5,9 @@
[buddy.hashers :as hashers]
[hiccup.form :as hform]
[wanijo.framework.view :as view]
[wanijo.framework.routing :refer [register path]]
[wanijo.framework.routing :refer [register! path]]
[wanijo.user.domain :as user-domain]))
(register :auth-login "/login")
(register :auth-login-check "/login-check")
(register :auth-logout "/logout")
(defn- login-check! [req]
(let [{{:keys [uname pw]} :params} req
unode (user-domain/find! uname)
@ -42,7 +38,7 @@
(anti-forgery-field))]))
(defroutes routes
(GET "/login" [] login!)
(POST "/login-check" [] login-check!)
(GET "/logout" [] (-> (redirect "/login")
(GET (register! :auth-login "/login") [] login!)
(POST (register! :auth-login-check "/login-check") [] login-check!)
(GET (register! :auth-logout "/logout") [] (-> (redirect "/login")
(assoc :session nil))))

@ -64,37 +64,6 @@
field-id
field-value)))
(defn drop-down
([form-def field req]
{:pre [(spec/valid? ::form form-def)]}
(drop-down form-def field req
(get-in form-def [:fields field :options])))
([form-def field req options]
{:pre [(spec/valid? ::form form-def)]}
(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/drop-down field
options
field-value)))))
(defn check-box [form-def field req]
{:pre [(spec/valid? ::form form-def)]}
(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/check-box field
(some? field-value)
field-value))))
(defn valid? [form-def req]
{:pre [(spec/valid? ::form form-def)]}
(reduce-kv

@ -4,10 +4,6 @@
(def all-routes
(atom {}))
(defn register [id path]
(swap! all-routes
assoc id path))
(defn register! [id path]
(swap! all-routes
assoc id path)
@ -52,6 +48,3 @@
(let [path (id @all-routes)]
(check-params id path params)
(parse-path path params))))
(defn raw-path [id]
(id @all-routes))

@ -1,9 +1,7 @@
(ns wanijo.home.routes
(:require [compojure.core :refer [defroutes GET]]
[wanijo.framework.routing :refer [register]]
[wanijo.framework.routing :refer [register!]]
[wanijo.home.view :as home-view]))
(register :home "/")
(defroutes routes
(GET "/" [] home-view/root!))
(GET (register! :home "/") [] home-view/root!))

Loading…
Cancel
Save