parent
89f6e08c4f
commit
b0d89da01c
@ -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)))))
|
||||
|
Loading…
Reference in new issue