From c416d211c261292d77d45ab12f10ce44b6ac036b Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Mon, 18 Jun 2012 23:29:40 +0200 Subject: Publish FOAF+SSL key data on profile pages. --- src/mulk/benki/id.clj | 35 +++++++++++++++++++++++++++-------- src/mulk/benki/util.clj | 13 +++++++++++-- 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/src/mulk/benki/id.clj b/src/mulk/benki/id.clj index d1f8263..20925e7 100644 --- a/src/mulk/benki/id.clj +++ b/src/mulk/benki/id.clj @@ -22,12 +22,12 @@ (def profile-base-uri (str (:base-uri @benki-config) "/id/")) -(defn user-owns-nickname? [user nickname] +(defn nickname-user [nickname] (with-dbt - (sql/with-query-results results - ["SELECT 't' FROM user_nicknames WHERE nickname = ? AND \"user\" = ?" - nickname *user*] - (doall (seq results))))) + (:user (query1 "SELECT \"user\" FROM user_nicknames WHERE nickname = ?" nickname)))) + +(defn user-owns-nickname? [user nickname] + (= (nickname-user nickname) user)) (defn fail-authentication [] {:status 403, :type "text/plain", :body "Not authorized."}) @@ -80,9 +80,28 @@ (def profile-page {}) -(defn show-profile-page [] +(defn show-profile-page [user] (layout profile-page "A Profile Page" - [:p "This is a profile page."])) + [:div {:typeof "foaf:Person"} + [:h2 "Public Keys"] + [:div {:rel "cert:key"} + [:div {:typeof "cert:RSAPublicKey"} + [:dl + (with-dbt + (sql/with-query-results keys ["SELECT * FROM user_rsa_keys WHERE \"user\" = ?" user] + (doall + (for [{modulus :modulus, + exponent :exponent} + keys] + (list + [:dt "Modulus (hex)"] + [:dd {:property "cert:modulus" + :datatype "xsd:hexBinary"} + (fmt nil "~X" modulus)] + [:dt "Exponent"] + [:dd {:property "cert:exponent" + :datatype "xsd:integer"} + (fmt nil "~D" exponent)])))))]]]])) (defn render-xrds [nickname] {:status 200 @@ -111,7 +130,7 @@ (if (re-find #"application/xrds\+xml" (get-in (request/ring-request) [:headers "accept"])) (render-xrds nickname) - (show-profile-page))) + (show-profile-page (nickname-user nickname)))) (defpage [:get "/~:nickname"] {nickname :nickname} (redirect (link :profile nickname))) diff --git a/src/mulk/benki/util.clj b/src/mulk/benki/util.clj index 7f85ead..4c8a141 100644 --- a/src/mulk/benki/util.clj +++ b/src/mulk/benki/util.clj @@ -36,7 +36,14 @@ ;; defpartial is just defn + html. (defpartial layout [kind title & content] - (html5 {:xml? true} + (xml-declaration "UTF-8") + (doctype :html5) + [:html {:xmlns "http://www.w3.org/1999/xhtml" + "xml:lang" "en" + :lang "en" + "xmlns:cert" "http://www.w3.org/ns/auth/cert#" + "xmlns:foaf" "http://xmlns.com/foaf/0.1/" + "xmlns:xsd" "http://www.w3.org/2001/XMLSchema#"} [:head {:data-logged-in (if *user* "true" "false"), :data-websocket-base (:websocket-base @benki-config)} [:title title] @@ -50,12 +57,14 @@ [:link {:type "text/css" :rel "stylesheet" :href (resolve-uri "/style/benki.css")}] + [:link {:rel "profile" + :href "http://www.w3.org/1999/xhtml/vocab"}] [:meta {:content "initial-scale=1.0, width=device-width" :name "viewport"}] (:head kind)] [:body [:h1 title] content - (:bottom kind)])) + (:bottom kind)]]) (defmulti user-nickname type) (defmethod user-nickname java.lang.String [x] -- cgit v1.2.3