            items)]
      [:div.navbar-right
       [:ul.nav.navbar-nav.navbar-right
-       (if-let [user (friend/current-authentication)]
-         (html
-           [:li
-            [:a {:href "#"} (users/full-name user)]]
-           [:li
-            (glyph-link :log-out "/logout" {:title "Click here to sign out."
-                                            :data-method :post})])
-         (html
-           [:li
-            [:a {:href "/signup"} "Sign up"]]
-           [:li
-            (glyph-link :log-in "/login" {:title "Click here to sign in."})]))]]]]])
+       (if user
+         (authenticated-user-nav user entity)
+         (unauthenticated-nav))]]]]])
+
+(def item-templates
+  [{:url "/entities/:entity-id/accounts"     :caption "Accounts"}
+   {:url "/entities/:entity-id/transactions" :caption "Transactions"}
+   {:url "/entities/:entity-idcommodities"  :caption "Commodities"}])
 
 (defn primary-nav
   "Renders the site primary navigation"
-  []
-  (let [user (friend/current-authentication)
-        items [{:url "/entities"     :caption "Entities"}
-               {:url "/transactions" :caption "Transactions"}
-               {:url "/commodities"  :caption "Commodities"}]]
-    (bootstrap-nav items)))
+  [entity]
+  (if-let [user (friend/current-authentication)]
+    (if-let [entity (or entity (first (entities/select (env :db) (:id user))))]
+      (let [items (->> item-templates
+                       (map (fn [item]
+                              (update-in item
+                                         [:url]
+                                         #(string/replace % ":entity-id" (str (:id entity)))))))]
+        (bootstrap-nav items user entity))
+      (bootstrap-nav [] user nil))
+    (bootstrap-nav [] nil nil)))
 
 (defn render-alerts
   "Renders notifications as HTML"

                                   (s/join " " (glyph-button-css options)))
                            (dissoc :size :level))))

; TODO Wrap this up in a sharable library
(defn bootstrap-nav
  "Renders the site navigation using the structure for twitter bootstrap"
  [items]
  [:nav.navbar.navbar-default
   [:div.container
    [:div.navbar-header

(ns clj-money.web.shared
  (:require [clojure.tools.logging :as log]
            [clojure.set :as set]
            [clojure.string :as string]
            [environ.core :refer [env]]
            [hiccup.core :refer :all]
            [hiccup.page :refer :all]
            [clojure.string :as s]
            [cemerick.friend :as friend]
            [clj-money.models.users :as users]
            [clj-money.models.entities :as entities])
  (:use clj-money.inflection))

(defn glyph-link
