 
 (defroutes app-routes
   (GET "/" [] (h/html5 pretty-head (pretty-body
-                                   [:a {:href "/login"} "Login"])))
+                                   [:a {:href "/signin"} "Login"])))
   (GET "/user/profile" []
-       (friend/authorize #{::user}
+       (friend/authenticated
                          (slurp "resources/public/html/index.html")))
   (GET "/user/data" request
-       (friend/authorize #{::user}
+       (friend/authenticated
                          (->
-                          (:username (friend/current-authentication))
+                          (:email (friend/current-authentication))
                           (get-userdata)
                           response)))
   (POST "/user/save" {body :body}
-        (friend/authorize #{::user}
+        (friend/authenticated
                           (do (save-document body)
                               (response
                                {:status  "OK"}))))
-  (GET "/login" request
+  (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) "/"))))

  (-> (handler/site app-routes)
      (init-middleware)
      (friend/authenticate {:allow-anon? true
                            :login-uri "/login"
                            :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)))
                            :credential-fn
                            (partial creds/bcrypt-credential-fn users)
                            :workflows [(workflows/interactive-form)]})
      (ring-json/wrap-json-body {:keywords? true})
      (ring-json/wrap-json-response)
      (keyword-params/wrap-keyword-params)

            [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]])
  (: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"}
