Skip to content

Instantly share code, notes, and snippets.

@dpick
Created March 2, 2013 16:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dpick/5071762 to your computer and use it in GitHub Desktop.
Save dpick/5071762 to your computer and use it in GitHub Desktop.
Anonymous users with friend
(defn credential-fn [guid]
(if-let [user (persistence/find-user-by-guid guid)]
(assoc user :roles #{:fashion.server/user})))
(defn guid [request]
(if (empty? (:session request))
(let [user (persistence/create-user {:guid (java.util.UUID/randomUUID) :password (str (java.util.UUID/randomUUID))})]
(workflows/make-auth (assoc user :roles #{:fashion.server/user} :identity (:guid user)) {:cemerick.friend/workflow :guid}))
(let [user (persistence/find-user-by-guid (get-in request [:session :cemerick.friend/identity :current]))]
(when user
(workflows/make-auth (assoc user :roles #{:fashion.server/user} :identity (:guid user)) {::cemerick.friend/workflow :guid ::friend/redirect-on-auth? false})))))
(defn secure-app [app]
(-> app
(friend/authenticate { :credential-fn (partial creds/bcrypt-credential-fn credential-fn)
:workflows [(workflows/interactive-form) guid] })))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment