Created
September 20, 2010 19:30
-
-
Save brentonashworth/588503 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def properties | |
{:username "Username" | |
:password "Password"}) | |
(def security-policy | |
[#"/admin.*" :admin | |
#"/permission-denied.*" :any | |
#"/login.*" :any | |
#".*\.(css|js|png|jpg|gif)$" :any | |
#".*" #{:admin :user}]) | |
;; The old way | |
(defrecord DemoAdapter [] | |
FormAuthAdapter | |
(load-user [this username password] | |
(merge (database/find-user username) {:login-password password})) | |
(validate-password [this] | |
(fn [m] | |
(if (= (:password m) (:login-password m)) | |
m | |
(add-validation-error m "Incorrect username or password!"))))) | |
(defn form-authentication-adapter [] | |
(merge (DemoAdapter.) properties)) | |
(defroutes my-routes | |
(form-authentication-routes (fn [request form] (layout form)) | |
(form-authentication-adapter)) | |
(ANY "*" [] (layout (home-view)))) | |
(def app | |
(-> my-routes | |
(with-security security-policy form-authentication) | |
wrap-stateful-session)) | |
;; The new way | |
(defauth form-auth | |
:type :form | |
:load (fn [username password] | |
(merge (database/find-user username) {:login-password password})) | |
:validator #(if (= (:password %) (:login-password %)) | |
% | |
(add-validation-error % "Incorrect username or password!")) | |
:properties properties) | |
(defroutes my-routes | |
(form-auth (fn [request form] (layout form))) | |
(ANY "*" [] (layout (home-view)))) | |
(def app | |
(-> my-routes | |
(with-security security-policy form-auth) | |
wrap-stateful-session)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment