parent
96e48825d2
commit
89f6e08c4f
@ -1,11 +1,20 @@
|
|||||||
(ns wanijo.auth.handler
|
(ns wanijo.auth.handler
|
||||||
(:require [ring.util.response :as rur]))
|
(:require [ring.util.response :as rur]
|
||||||
|
[wanijo.neo4j :as neo]
|
||||||
|
[buddy.hashers :as bh]))
|
||||||
|
|
||||||
(defn login-check [req]
|
(defn login-check! [req]
|
||||||
(let [{{:keys [uname pw]} :params} req]
|
(let [{{:keys [uname pw]} :params} req
|
||||||
(if (and (= uname "admin")
|
unode (neo/find-user! uname)
|
||||||
(= pw "pw"))
|
pwmatch (when-let [hash (:pw unode)]
|
||||||
|
(bh/check pw hash))]
|
||||||
|
(if pwmatch
|
||||||
(-> (rur/redirect "/")
|
(-> (rur/redirect "/")
|
||||||
(assoc-in [:session :ident] uname))
|
(assoc-in [:session :ident] uname)
|
||||||
|
(assoc-in [:session :unode] unode))
|
||||||
(-> (rur/redirect "/login")
|
(-> (rur/redirect "/login")
|
||||||
(assoc :flash :invalid-credentials)))))
|
(assoc :flash :invalid-credentials)))))
|
||||||
|
|
||||||
|
(defn logout [req]
|
||||||
|
(-> (rur/redirect "/login")
|
||||||
|
(assoc :session nil)))
|
||||||
|
@ -0,0 +1,16 @@
|
|||||||
|
(ns wanijo.neo4j
|
||||||
|
(:require [clojurewerkz.neocons.rest :as nr]
|
||||||
|
[clojurewerkz.neocons.rest.nodes :as nrn]
|
||||||
|
[clojurewerkz.neocons.rest.cypher :as nrc]))
|
||||||
|
|
||||||
|
(def conn (nr/connect "http://neo4j:b@localhost:7474/db/data"))
|
||||||
|
|
||||||
|
(defn find-user! [ident]
|
||||||
|
(some->
|
||||||
|
(nrc/tquery
|
||||||
|
conn
|
||||||
|
"MATCH (n:user) WHERE n.ident = {ident} RETURN n"
|
||||||
|
{:ident ident})
|
||||||
|
first
|
||||||
|
(get "n")
|
||||||
|
:data))
|
@ -1,23 +1,34 @@
|
|||||||
(ns wanijo.view
|
(ns wanijo.view
|
||||||
(:require [hiccup.page :refer [html5]]))
|
(:require [hiccup.page :refer [html5
|
||||||
|
include-css]]))
|
||||||
|
|
||||||
(defn layout
|
(defn layout
|
||||||
[& {:keys [authed? content title]
|
[& {:keys [content title session]
|
||||||
:or {authed? true
|
:or {content []
|
||||||
content []
|
title nil
|
||||||
title "wan ijo"}}]
|
session {}}}]
|
||||||
(html5
|
(let [ident (:ident session)
|
||||||
[:head
|
authed? (some? ident)]
|
||||||
[:meta {:charset "utf-8"}]
|
(html5
|
||||||
[:title title]
|
[:head
|
||||||
[:link {:rel "stylesheet"
|
[:meta {:charset "utf-8"}]
|
||||||
:href "/css/app.css"}]]
|
[:meta {:name "viewport"
|
||||||
[:body
|
:content "width=device-width,initial-scale=1,shrink-to-fit=no"}]
|
||||||
[:section.grid
|
[:title (str "wan ijo" (when title (str " - " title)))]
|
||||||
[:header
|
(include-css "/css/app.css")]
|
||||||
[:h1 "wan ijo"]]
|
[:body
|
||||||
[:nav (when authed? "nav")]
|
[:section.grid
|
||||||
(vec (concat [:main] content))
|
[:header
|
||||||
[:aside (when authed? "aside")]
|
[:h1.app-title "wan ijo"
|
||||||
[:footer
|
(when authed?
|
||||||
[:small "stuff with objects"]]]]))
|
[:small.app-title__hello
|
||||||
|
(str "O, " ident)])]
|
||||||
|
(when authed?
|
||||||
|
[:section.header-content
|
||||||
|
[:a.header-content__link {:href "/logout"}
|
||||||
|
"Lape"]])]
|
||||||
|
[:nav (when authed? "nav")]
|
||||||
|
(vec (concat [:main] content))
|
||||||
|
[:aside (when authed? "aside")]
|
||||||
|
[:footer
|
||||||
|
[:small "Ilo pali e ijo"]]]])))
|
||||||
|
Loading…
Reference in new issue