You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
wanijo/src/wanijo/auth/routes.clj

25 lines
868 B

(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.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" [] login-check!)
(GET "/logout" [] (fn [_] (-> (redirect "/login")
(assoc :session nil)))))