From b0d89da01c7b9e062b75f2d53fec68721b9ec765 Mon Sep 17 00:00:00 2001 From: Josha von Gizycki Date: Wed, 21 Mar 2018 16:54:51 +0100 Subject: [PATCH] nicer buttons, restructuring in auth --- resources/public/css/app.css | 6 +++--- src/wanijo/auth/handler.clj | 20 -------------------- src/wanijo/auth/routes.clj | 21 ++++++++++++++++++--- src/wanijo/view.clj | 14 ++++++++++++-- 4 files changed, 33 insertions(+), 28 deletions(-) delete mode 100644 src/wanijo/auth/handler.clj diff --git a/resources/public/css/app.css b/resources/public/css/app.css index 755090e..298e713 100644 --- a/resources/public/css/app.css +++ b/resources/public/css/app.css @@ -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 { diff --git a/src/wanijo/auth/handler.clj b/src/wanijo/auth/handler.clj deleted file mode 100644 index e3f8492..0000000 --- a/src/wanijo/auth/handler.clj +++ /dev/null @@ -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))) diff --git a/src/wanijo/auth/routes.clj b/src/wanijo/auth/routes.clj index 22ec939..eb5f753 100644 --- a/src/wanijo/auth/routes.clj +++ b/src/wanijo/auth/routes.clj @@ -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))))) diff --git a/src/wanijo/view.clj b/src/wanijo/view.clj index 73aedc7..4272248 100644 --- a/src/wanijo/view.clj +++ b/src/wanijo/view.clj @@ -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")]