nicer buttons, restructuring in auth

integration-tests
Josha von Gizycki 7 years ago
parent 89f6e08c4f
commit b0d89da01c

@ -4,7 +4,7 @@ body {
a:link, a:link,
a:visited { a:visited {
color: blue; color: #555;
text-decoration: none; text-decoration: none;
} }
@ -39,7 +39,7 @@ aside {
header, footer, main, nav, aside { header, footer, main, nav, aside {
border-bottom: 1px solid #ccc; border-bottom: 1px solid #ccc;
padding: .5rem 1rem .2rem 1rem; padding: .2rem 1rem .2rem 1rem;
} }
header { header {
@ -67,8 +67,8 @@ header {
} }
.header-content__link { .header-content__link {
padding-top: .5rem;
display: inline-block; display: inline-block;
padding: .2rem .5rem;
} }
footer { footer {

@ -1,20 +0,0 @@
(ns wanijo.auth.handler
(:require [ring.util.response :as rur]
[wanijo.neo4j :as neo]
[buddy.hashers :as bh]))
(defn login-check! [req]
(let [{{:keys [uname pw]} :params} req
unode (neo/find-user! uname)
pwmatch (when-let [hash (:pw unode)]
(bh/check pw hash))]
(if pwmatch
(-> (rur/redirect "/")
(assoc-in [:session :ident] uname)
(assoc-in [:session :unode] unode))
(-> (rur/redirect "/login")
(assoc :flash :invalid-credentials)))))
(defn logout [req]
(-> (rur/redirect "/login")
(assoc :session nil)))

@ -1,9 +1,24 @@
(ns wanijo.auth.routes (ns wanijo.auth.routes
(:require [compojure.core :refer [POST GET defroutes]] (:require [compojure.core :refer [POST GET defroutes]]
[ring.util.response :refer [redirect]]
[buddy.hashers :as hashers]
[wanijo.auth.view :as auth-view] [wanijo.auth.view :as auth-view]
[wanijo.auth.handler :as auth-handler])) [wanijo.neo4j :as neo]))
(defn- login-check! [req]
(let [{{:keys [uname pw]} :params} req
unode (neo/find-user! uname)
pwmatch (when-let [hash (:pw unode)]
(hashers/check pw hash))]
(if pwmatch
(-> (redirect "/")
(assoc-in [:session :ident] uname)
(assoc-in [:session :unode] unode))
(-> (redirect "/login")
(assoc :flash :invalid-credentials)))))
(defroutes auth-routes (defroutes auth-routes
(GET "/login" [] auth-view/login) (GET "/login" [] auth-view/login)
(POST "/login-check" [] auth-handler/login-check!) (POST "/login-check" [] login-check!)
(GET "/logout" [] auth-handler/logout)) (GET "/logout" [] (fn [_] (-> (redirect "/login")
(assoc :session nil)))))

@ -2,6 +2,14 @@
(:require [hiccup.page :refer [html5 (:require [hiccup.page :refer [html5
include-css]])) include-css]]))
(defn btnlink
([target caption]
(btnlink target caption ""))
([target caption class]
[:a {:href target}
[:button {:class class}
caption]]))
(defn layout (defn layout
[& {:keys [content title session] [& {:keys [content title session]
:or {content [] :or {content []
@ -25,8 +33,10 @@
(str "O, " ident)])] (str "O, " ident)])]
(when authed? (when authed?
[:section.header-content [:section.header-content
[:a.header-content__link {:href "/logout"} (btnlink
"Lape"]])] "/logout"
"Lape"
"header-content__link")])]
[:nav (when authed? "nav")] [:nav (when authed? "nav")]
(vec (concat [:main] content)) (vec (concat [:main] content))
[:aside (when authed? "aside")] [:aside (when authed? "aside")]

Loading…
Cancel
Save