             [clojure.edn :as edn]
             [cemerick.friend :as friend]
             [clojure.java.io :as io]
+            [cemerick.friend.openid :as openid]
             (cemerick.friend [workflows :as workflows]
                              [credentials :as creds])
             [nomad :refer [defconfig]]
-            [frodo.web :refer [App]]))
+            [frodo.web :refer [App]])
+  (:import java.net.URI))
 
 (defconfig app-config (io/resource "config.edn"))
+
+(def providers [{:name "Google" :url "https://www.google.com/accounts/o8/id"}
+                {:name "Yahoo" :url "http://me.yahoo.com/"}
+                {:name "AOL" :url "http://openid.aol.com/"}
+                {:name "Wordpress.com" :url "http://username.wordpress.com"}
+                {:name "MyOpenID" :url "http://username.myopenid.com/"}])
 
 (defn is-dev? []
   (= :dev (:env app-config)))
+
+(defn resolve-uri
+  [context uri]
+  (let [context (if (instance? URI context) context (URI. context))]
+    (.resolve context uri)))
+
+(defn context-uri
+  "Resolves a [uri] against the :context URI (if found) in the provided
+   Ring request.  (Only useful in conjunction with compojure.core/context.)"
+  [{:keys [context]} uri]
+  (if-let [base (and context (str context "/"))]
+    (str (resolve-uri base uri))
+    uri))
 
 (def login-form
   [:div {:class "container"}

  (:db-config (app-config)))



(defn get-userdata [username]
  {:username username

  (-> (handler/site app-routes)
      (init-middleware)
      (friend/authenticate {:allow-anon? true
                            :default-landing-uri "/user/profile"
                            :unauthorized-handler #(do
                                                     ( println (friend/current-authentication))
                                                     ( -> (h/html5 [:h2 "You do not have sufficient privileges to access " (:uri %)])
                                                          response
                                                          (status 401)))
                            :workflows [(openid/workflow
                                         :openid-uri "/login"
                                         :credential-fn identity)]})
      (ring-json/wrap-json-body {:keywords? true})
      (ring-json/wrap-json-response)
      (keyword-params/wrap-keyword-params)
