This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require 'local-dev) | |
(local-dev/init-app-engine) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(local-dev/start-server (var example)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defroutes public-routes | |
(GET "/" [] (main-page))) | |
(defroutes admin-routes | |
(GET "/admin/new" [] (render-page "New Post" new-form)) | |
(POST "/admin/post" [title body] (create-post title body))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn wrap-requiring-admin [application] | |
(fn [request] | |
(let [{:keys [user-service]} (users/user-info request)] | |
(if (.isUserAdmin user-service) | |
(application request) | |
{:status 403 :body "Access denied. You must be logged in as admin user!"})))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(wrap! admin-routes | |
wrap-requiring-admin | |
users/wrap-requiring-login | |
users/wrap-with-user-info) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defroutes example | |
public-routes | |
(ANY "/admin/*" [] admin-routes) | |
(route/not-found "Page not found")) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn side-bar [] | |
(let [ui (users/user-info)] | |
[:div#sidebar | |
[:h3 "Current User"] | |
(if-let [user (:user ui)] | |
[:ul | |
[:li "Logged in as " (.getEmail user)] | |
[:li (link-to (.createLogoutURL (:user-service ui) "/") "Logout")]] | |
[:ul | |
[:li "Not logged in"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
env-proxy (proxy [ApiProxy$Environment] [] | |
(isLoggedIn [] false) | |
(getRequestNamespace [] "") | |
(getDefaultNamespace [] "") | |
(getAttributes [] att) | |
(getAppId [] "_local_")) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def login-info (atom {:logged-in? false | |
:admin? false | |
:email "" | |
:auth-domain ""})) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn- set-app-engine-environment [] | |
"Sets up the App Engine environment for the current thread." | |
(let [att (HashMap. {"com.google.appengine.server_url_key" | |
(str "http://localhost:" *port*)}) | |
env-proxy (proxy [ApiProxy$Environment] [] | |
(isLoggedIn [] (:logged-in? @login-info)) | |
(getEmail [] (:email @login-info)) | |
(getAuthDomain [] (:auth-domain @login-info)) | |
(isAdmin [] (:admin? @login-info)) | |
(getRequestNamespace [] "") |