Skip to content

Commit

Permalink
Introduces permissions to control access to the admin page and a (cur…
Browse files Browse the repository at this point in the history
…rently nonfunctional) 'post' form.
  • Loading branch information
thurn committed Nov 17, 2010
1 parent 41982e1 commit da5a5bd
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 29 deletions.
11 changes: 8 additions & 3 deletions resources/WEB-INF/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@
<url-pattern>/*</url-pattern>
</servlet-mapping>

<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<security-constraint>
<web-resource-collection>
<url-pattern>/admin/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>admin</role-name>
</auth-constraint>
</security-constraint>

</web-app>
55 changes: 29 additions & 26 deletions src/ackbar/core.clj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(ns ackbar.core
(:use compojure.core hiccup.core)
(:use compojure.core hiccup.core hiccup.form-helpers hiccup.page-helpers)
(:require [appengine-magic.core :as ae]))

(defn wrap-result [result]
Expand All @@ -10,40 +10,42 @@

(defn result [str] (wrap-result {:title str :body [:h1 str]}))

(defn response-wrapper [title body]
{:status 200
:headers {"Content-Type" "text/html"}
:body (xhtml [:head [:title title]]
[:body body])})

(defn render-page
"Retrieve a page from the datastore and render it for display to the user"
[page]
(result (str "Rendered Page: " page)))

(defn admin-page
"Displays the Ackbar Admin Page"
[]
(result "Admin Page"))

(defn admin-login-page
"Displays the Ackbar Admin Login Page"
[]
(result "Admin Login Page"))

(defn admin-logout-page
"Displays the Ackbar Admin Logout Page"
[]
(result "Admin Logout Page"))

(defn admin-add-page
"Displays the Ackbar Admin 'Add Page' Page"
[]
(result "Admin Page"))
(response-wrapper "Add Page"
(form-to [:post "/admin/add-page"]
(label "title" "Title:")
[:br]
(text-field "title")
[:br]
(label "body" "Body:")
[:br]
(text-area {:cols 80 :rows 40} "body")
[:br]
(submit-button "Submit")
)))

(defn admin-edit-page
"Displays the Ackbar Admin 'Edit Page' Page"
[]
(result "Admin Page"))
(result "Admin Edit Page"))

(defn admin-delete-page
"Displays the Ackbar Admin 'Delete Page' Page"
[]
(result "Admin Page"))
(result "Admin Delete Page"))

(defn combined-js
"A link to the minified and combined javascript for the project"
Expand All @@ -58,19 +60,20 @@
(defn canonical-name
"Converts a given page name to a standard format, suitable for use in a URL."
[str]
str
)
str)

; Special Pages: home, admin, 404, navbar
(defroutes ackbar-app-handler
(GET "/" [] (render-page "home"))
(GET "/admin/home" [] (admin-page))
(GET "/admin/login" [] (admin-login-page))
(GET "/admin/logout" [] (admin-logout-page))
(GET "/admin/add-page" [] (admin-add-page))
(POST "/admin/add-page" {params :params} (render-page "add page post"))
(GET "/admin/edit-page" [] (admin-edit-page))
(POST "/admin/edit-page" {params :params} (render-page "edit page post"))
(GET "/admin/delete-page" [] (admin-delete-page))
(POST "/admin/delete-page" {params :params} (render-page "delete page post"))
(GET "/static/combined.js" [] (combined-js))
(GET "/static/combined.css" [] (combined-css))
(GET "/:name" [name] (render-page (canonical-name name))))
(GET "/:name" [name] (render-page (canonical-name name)))
(ANY "*" [] (render-page "404")))

(ae/def-appengine-app ackbar-app #'ackbar-app-handler)
(ae/def-appengine-app ackbar-app #'ackbar-app-handler)

0 comments on commit da5a5bd

Please sign in to comment.