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:visited {
color: blue;
color: #555;
text-decoration: none;
}
@ -39,7 +39,7 @@ aside {
header, footer, main, nav, aside {
border-bottom: 1px solid #ccc;
padding: .5rem 1rem .2rem 1rem;
padding: .2rem 1rem .2rem 1rem;
}
header {
@ -67,8 +67,8 @@ header {
}
.header-content__link {
padding-top: .5rem;
display: inline-block;
padding: .2rem .5rem;
}
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
(:require [compojure.core :refer [POST GET defroutes]]
[ring.util.response :refer [redirect]]
[buddy.hashers :as hashers]
[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
(GET "/login" [] auth-view/login)
(POST "/login-check" [] auth-handler/login-check!)
(GET "/logout" [] auth-handler/logout))
(POST "/login-check" [] login-check!)
(GET "/logout" [] (fn [_] (-> (redirect "/login")
(assoc :session nil)))))

@ -2,6 +2,14 @@
(: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 []
@ -25,8 +33,10 @@
(str "O, " ident)])]
(when authed?
[:section.header-content
[:a.header-content__link {:href "/logout"}
"Lape"]])]
(btnlink
"/logout"
"Lape"
"header-content__link")])]
[:nav (when authed? "nav")]
(vec (concat [:main] content))
[:aside (when authed? "aside")]

Loading…
Cancel
Save