Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 65 lines (57 sloc) 2.584 kb
6f54558 @amalloy Add an opt-in UI. Still kinda crep, but what can you do
amalloy authored
1 (ns foreclojure.golf
04d150f @amcnamara Cleaned up namespace declarations.
amcnamara authored
2 (:require [ring.util.response :as response]
5e6af1b @Raynes Upgrade dependencies and move to Clojure 1.4.
Raynes authored
3 [noir.session :as session])
4 (:use [hiccup.form :only [form-to check-box]]
5 [hiccup.element :only [link-to]]
6504415 @amcnamara Initial template update.
amcnamara authored
6 [foreclojure.utils :only [with-user]]
8958e5c @amcnamara More style fixes. Templated unapproved problems, settings/golf, login
amcnamara authored
7 [foreclojure.template :only [def-page content-page]]
ba91988 @amcnamara Made ns bindings amalloy-friendly.
amcnamara authored
8 [foreclojure.users :only [golfer?]]
9 [compojure.core :only [defroutes POST GET]]
10 [somnium.congomongo :only [update!]]))
6f54558 @amalloy Add an opt-in UI. Still kinda crep, but what can you do
amalloy authored
11
12 (def-page golfer-page []
13 "Your preferences have been saved.")
14
8958e5c @amcnamara More style fixes. Templated unapproved problems, settings/golf, login
amcnamara authored
15 (defn golf-opt-in-box [user-obj]
16 (list
17 [:table
18 (form-to [:post "/golf/opt-in"]
19 [:tr
20 [:td
21 (check-box :opt-in
22 (golfer? user-obj))
23 [:label {:for "opt-in"}
24 "I want to join the golf league and compete to find the shortest solutions"]]]
25 [:tr [:td [:button {:type "submit"} "Update"]]])]))
26
bd67030 @amalloy Create a separate page for opting-in to golf stuff. Hopefully this wi…
amalloy authored
27 (def-page opt-in-page []
8958e5c @amcnamara More style fixes. Templated unapproved problems, settings/golf, login
amcnamara authored
28 (with-user [{:keys [user] :as user-obj}]
29 {:title "Account Settings"
30 :content
31 (content-page
32 {:heading "League sign-up"
33 :sub-heading (list "While the primary purpose of 4clojure.com is to teach Clojure \"by doing\", you may "
34 "also choose to compete for the shortest solution. This is affectionately known as "
35 (link-to "http://lbrandy.com/blog/2008/09/what-code-golf-taught-me-about-python/" "code golf")
36 ": the lower your score the better, get it? If you choose to participate, we'll score "
37 "your correct solutions based on the number of non-whitespace characters (and some more "
38 "metrics in the future). We'll also provide a chart showing how you stack up compared "
39 "to everyone else on the site.")
40 :main (golf-opt-in-box user-obj)})}))
bd67030 @amalloy Create a separate page for opting-in to golf stuff. Hopefully this wi…
amalloy authored
41
6f54558 @amalloy Add an opt-in UI. Still kinda crep, but what can you do
amalloy authored
42 (defn set-golfer [opt-in]
43 (with-user [{:keys [_id]}]
44 (update! :users
45 {:_id _id}
46 {:$set {:golfer (boolean opt-in)}})
47 (response/redirect "/golf/opt-in")))
48
49 (defroutes golf-routes
50 (POST "/golf/opt-in" [opt-in]
51 (set-golfer opt-in))
52 (GET "/golf/opt-in" []
bd67030 @amalloy Create a separate page for opting-in to golf stuff. Hopefully this wi…
amalloy authored
53 (golfer-page))
54
55 (GET "/league" []
56 (comment ;; be smarter somehow in future. not sure what the right UI is, atm
5e6af1b @Raynes Upgrade dependencies and move to Clojure 1.4.
Raynes authored
57 (if-let [username (session/get :user)]
bd67030 @amalloy Create a separate page for opting-in to golf stuff. Hopefully this wi…
amalloy authored
58 (let [user-obj (get-user username)]
59 (if-not (golfer? user-obj)
60 (response/redirect "/leag")))))
61 (opt-in-page))
62
63 (GET "/league/opt-in" []
64 (opt-in-page)))
Something went wrong with that request. Please try again.