parent
96e48825d2
commit
89f6e08c4f
@ -1,11 +1,20 @@
|
||||
(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]
|
||||
(let [{{:keys [uname pw]} :params} req]
|
||||
(if (and (= uname "admin")
|
||||
(= pw "pw"))
|
||||
(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 :ident] uname)
|
||||
(assoc-in [:session :unode] unode))
|
||||
(-> (rur/redirect "/login")
|
||||
(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
|
||||
(:require [hiccup.page :refer [html5]]))
|
||||
(:require [hiccup.page :refer [html5
|
||||
include-css]]))
|
||||
|
||||
(defn layout
|
||||
[& {:keys [authed? content title]
|
||||
:or {authed? true
|
||||
content []
|
||||
title "wan ijo"}}]
|
||||
(html5
|
||||
[:head
|
||||
[:meta {:charset "utf-8"}]
|
||||
[:title title]
|
||||
[:link {:rel "stylesheet"
|
||||
:href "/css/app.css"}]]
|
||||
[:body
|
||||
[:section.grid
|
||||
[:header
|
||||
[:h1 "wan ijo"]]
|
||||
[:nav (when authed? "nav")]
|
||||
(vec (concat [:main] content))
|
||||
[:aside (when authed? "aside")]
|
||||
[:footer
|
||||
[:small "stuff with objects"]]]]))
|
||||
[& {:keys [content title session]
|
||||
:or {content []
|
||||
title nil
|
||||
session {}}}]
|
||||
(let [ident (:ident session)
|
||||
authed? (some? ident)]
|
||||
(html5
|
||||
[:head
|
||||
[:meta {:charset "utf-8"}]
|
||||
[:meta {:name "viewport"
|
||||
:content "width=device-width,initial-scale=1,shrink-to-fit=no"}]
|
||||
[:title (str "wan ijo" (when title (str " - " title)))]
|
||||
(include-css "/css/app.css")]
|
||||
[:body
|
||||
[:section.grid
|
||||
[:header
|
||||
[:h1.app-title "wan ijo"
|
||||
(when authed?
|
||||
[: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