Skip to content
Browse files

First draft on gravatars.

Top Users page looks all right, but surely can be improved.
Profile page looks an absolute mess, and I'm out of my depth in
CSS. Can someone (@gigasquid, @amcnamara?) have a look?
  • Loading branch information...
1 parent 52ab45f commit 258535be30b49fddc9479629eacb571e4674ba45 @amalloy amalloy committed Oct 1, 2011
Showing with 32 additions and 6 deletions.
  1. +8 −0 resources/public/css/style.css
  2. +24 −6 src/foreclojure/users.clj
8 resources/public/css/style.css
@@ -134,6 +134,14 @@ a.novisited {color: #00e;}
color: black;
+ float:left;
+ float:right;
30 src/foreclojure/users.clj
@@ -1,14 +1,17 @@
(ns foreclojure.users
(:require [ring.util.response :as response]
+ [clojure.string :as string]
[sandbar.stateful-session :as session])
(:use [foreclojure.utils :only [from-mongo row-class rank-class get-user with-user]]
[foreclojure.template :only [def-page content-page]]
+ [foreclojure.ring-utils :only [*http-scheme*]]
[foreclojure.config :only [config repo-url]]
[somnium.congomongo :only [fetch-one fetch update!]]
[compojure.core :only [defroutes GET POST]]
[hiccup.form-helpers :only [form-to hidden-field]]
[ :only [link-to]]
- [clojure.contrib.json :only [json-str]]))
+ [clojure.contrib.json :only [json-str]])
+ (:import org.apache.commons.codec.digest.DigestUtils))
(def golfer-tags (into [:contributor]
(when (:golfing-active config)
@@ -23,7 +26,7 @@
(defn get-users []
(fetch :users
- :only [:user :solved :contributor])))
+ :only [:user :solved :contributor :email])))
(defn get-ranked-users []
(let [users (get-users)
@@ -66,6 +69,18 @@
(link-to (str "mailto:" (email-address username))
+(let [canonical-email (comp string/trim string/lower-case)
+ md5 #(DigestUtils/md5Hex %)]
+ (defn gravatar-img [{:keys [email size class] :or {size 24}}]
+ (let [hash (md5 (canonical-email email))
+ url (str (name *http-scheme*) "://"
+ hash "?s=" size "&d=identicon")]
+ [:img (conj {:src url, :alt "gravatar icon"
+ :width size :height size}
+ (when class {:class class}))])))
(defn format-user-ranking [{:keys [rank user contributor solved]}]
(when user
@@ -102,12 +117,13 @@
[:th {:style "width: 200px;"} "Username"]
[:th {:style "width: 180px;"} "Problems Solved"]
[:th "Following"]]]
- (map-indexed (fn [rownum {:keys [_id position rank user contributor solved]}]
+ (map-indexed (fn [rownum {:keys [_id email position rank user contributor solved]}]
[:tr (row-class rownum)
[:td (rank-class position) rank]
(when contributor [:span.contributor "* "])
- [:a.user-profile-link {:href (str "/user/" user)} user]]
+ [:a.user-profile-link {:href (str "/user/" user)} user]
+ (gravatar-img {:email email :class "gravatar"})]
[:td.centered (count solved)]
[:td (following-checkbox user-id following _id user)]])
@@ -158,11 +174,13 @@
(def-page user-profile [username]
(let [page-title (str "User: " username)
- user-id (:_id (get-user username))]
+ {user-id :_id email :email} (get-user username)]
{:title page-title
- [:div.user-profile-name page-title]
+ [:div.user-profile-name (gravatar-img {:email email, :size 80
+ :class "user-profile-img"})
+ page-title]
(if (session/session-get :user)
(with-user [{:keys [_id following]}]
(if (not= _id user-id)

0 comments on commit 258535b

Please sign in to comment.
Something went wrong with that request. Please try again.