   (:db-config (app-config)))
 
 
+(defn open-id-login-form [req]
+  [:div {:class "container"}
+   [:h2 "Authenticating with various services using OpenID"]
+   [:h3 "Current Status " [:small "(this will change when you log in/out)"]]
+   (if-let [auth (friend/current-authentication req)]
+     [:p "Some information delivered by your OpenID provider:"
+      [:ul (for [[k v] auth
+                 :let [[k v] (if (= :identity k)
+                               ["Your OpenID identity" (str (subs v 0 (* (count v) 2/3)) "…")]
+                               [k v])]]
+             [:li [:strong (str (name k) ": ")] v])]]
+     [:div
+      [:h3 "Login with…"]
+      (for [{:keys [name url]} providers
+            :let [base-login-url (context-uri req (str "/login?identifier=" url))
+                  dom-id (str (gensym))]]
+        [:form {:method "POST" :action (context-uri req "login")
+                :onsubmit (when (.contains ^String url "username")
+                            (format "var input = document.getElementById(%s); input.value = input.value.replace('username', prompt('What is your %s username?')); return true;"
+                                    (str \' dom-id \') name))}
+         [:input {:type "hidden" :name "identifier" :value url :id dom-id}]
+         [:input {:type "submit" :class "button" :value name}]])
+      [:p "…or, with a user-provided OpenID URL:"]
+      [:form {:method "POST" :action (context-uri req "login")}
+       [:input {:type "text" :name "identifier" :style "width:250px;"}]
+       [:input {:type "submit" :class "button" :value "Login"}]]])
+   [:h3 "Logging out"]
+   [:p [:a {:href (context-uri req "logout")} "Click here to log out"] "."]])
 
 (defn get-userdata [username]
   {:username username

            [clojure.edn :as edn]
            [cemerick.friend :as friend]
            [clojure.java.io :as io]
            (cemerick.friend [workflows :as workflows]
                             [credentials :as creds])
            [nomad :refer [defconfig]]
            [frodo.web :refer [App]]))

(defconfig app-config (io/resource "config.edn"))

(defn is-dev? []
  (= :dev (:env app-config)))

(def login-form
  [:div {:class "container"}


(defroutes app-routes
  (GET "/" [] (h/html5 pretty-head (pretty-body
                                   [:a {:href "/signin"} "Login"])))
  (GET "/user/profile" []
       (friend/authenticated
                         (slurp "resources/public/html/index.html")))
  (GET "/user/data" request
       (friend/authenticated
                         (->
                          (:email (friend/current-authentication))
                          (get-userdata)
                          response)))
  (POST "/user/save" {body :body}
        (friend/authenticated
                          (do (save-document body)
                              (response
                               {:status  "OK"}))))
  (GET "/signin" request
       (h/html5
        pretty-head
        (pretty-body (open-id-login-form request))))
  (GET "/login2" request
       (h/html5 pretty-head (pretty-body login-form)))
  (GET "/logout" req
    (friend/logout* (redirect (str (:context req) "/"))))
