Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'feature/privacy' into develop
  • Loading branch information
amalloy committed Sep 16, 2011
2 parents 5a1004a + 75fd9c0 commit 2116421
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 14 deletions.
34 changes: 26 additions & 8 deletions src/foreclojure/login.clj
Expand Up @@ -4,7 +4,7 @@
(:import [org.jasypt.util.password StrongPasswordEncryptor])
(:use [hiccup.form-helpers :only [form-to label text-field password-field check-box]]
[foreclojure.utils :only [def-page from-mongo flash-error flash-msg with-user form-row assuming send-email login-url]]
[foreclojure.users :only [disable-codebox? set-disable-codebox]]
[foreclojure.users :only [disable-codebox? set-disable-codebox hide-solutions? set-hide-solutions]]
[compojure.core :only [defroutes GET POST]]
[useful.map :only [keyed]]
[clojail.core :only [thunk-timeout]]
Expand Down Expand Up @@ -50,6 +50,7 @@
(response/redirect (or location "/problems")))
(flash-error "Error logging in." "/login"))))

;; TODO this page is getting hella gross. Need a real Settings page soon.
(def-page update-credentials-page []
{:title "Change password"
:content
Expand All @@ -66,16 +67,29 @@
[password-field :pwd "New password"]
[password-field :repeat-pwd "Repeat password"]])
[:tr
[:td [:button {:type "submit"} "Reset now"]]])]
[:div#settings-codebox
[:h2 "Disable JavaScript Code Box"]
[:p "Selecting this will disable the JavaScript code entry box and just give you plain text entry"]
(form-to [:post "/users/set-disable-codebox"]
(check-box :disable-codebox
[:td [:button {:type "submit"} "Reset now"]]])]
[:hr]
[:div#settings-codebox
[:h2 "Disable JavaScript Code Box"]
[:p "Selecting this will disable the JavaScript code entry box and just give you plain text entry"]
(form-to [:post "/users/set-disable-codebox"]
(check-box :disable-codebox
(disable-codebox? user-obj))
[:label {:for "disable-codebox"}
"Disable JavaScript in code entry box"]
[:br]
[:div#button-div
[:button {:type "submit"} "Submit"]])]
[:hr]
[:div#settings-follow
[:h2 "Hide My Solutions"]
[:p "When you solve a problem, we allow any user who has solved a problem to view your solutions to that problem. Check this box to keep your solutions private."]
(form-to [:post "/users/set-hide-solutions"]
(check-box :hide-solutions
(hide-solutions? user-obj))
[:label {:for "hide-solutions"}
"Hide my solutions"]
[:br]
[:div#button-div
[:button {:type "submit"} "Submit"]])]]])})

Expand Down Expand Up @@ -187,4 +201,8 @@
(response/redirect "/")))

(POST "/users/set-disable-codebox" [disable-codebox]
(set-disable-codebox disable-codebox)))
(set-disable-codebox disable-codebox))

(POST "/users/set-hide-solutions" [hide-solutions]
(println "POST")
(set-hide-solutions hide-solutions)))
5 changes: 3 additions & 2 deletions src/foreclojure/problems.clj
Expand Up @@ -333,14 +333,15 @@ Return a map, {:message, :error, :url, :num-tests-passed}."
(with-user [{:keys [following]}]
(if (empty? following)
[:p "You can only see solutions of users whom you follow. Click on any name from the " (link-to "/users" "users") " listing page to see their profile, and click follow from there."]
(if (some (complement nil?) (map #(get-solution % problem-id) following))
(if (some (complement nil?) (map #(get-solution :public % problem-id) following))
(interpose [:hr {:style "margin-top: 20px; margin-bottom: 20px;"}]
(for [f-user-id following
:let [f-user (:user (from-mongo
(fetch-one :users
:where {:_id f-user-id}
:only [:user])))
f-code (get-solution f-user-id problem-id)]
f-code (get-solution :public
f-user-id problem-id)]
:when f-code]
[:div.follower-solution
[:div.follower-username (str f-user "'s solution:")]
Expand Down
15 changes: 11 additions & 4 deletions src/foreclojure/solutions.clj
Expand Up @@ -3,10 +3,17 @@
(:use [somnium.congomongo :only [fetch-one update!]]
[useful.debug :only [?]]))

(defn get-solution [user-id problem-id]
(:code (fetch-one :solutions
:where {:user user-id
:problem problem-id})))
(defn get-solution
([perm-level user-id problem-id]
(when (or (= :private perm-level)
(not (:hide-solutions (fetch-one :users
:where {:_id user-id}
:only [:hide-solutions]))))
(get-solution user-id problem-id)))
([user-id problem-id]
(:code (fetch-one :solutions
:where {:user user-id
:problem problem-id}))))

(defn save-solution [user-id problem-id code]
(update! :solutions
Expand Down
10 changes: 10 additions & 0 deletions src/foreclojure/users.clj
Expand Up @@ -54,6 +54,9 @@
(defn disable-codebox? [user]
(true? (:disable-code-box user)))

(defn hide-solutions? [user]
(true? (:hide-solutions user)))

(defn email-address [username]
(:email (fetch-one :users :where {:user username})))

Expand Down Expand Up @@ -176,6 +179,13 @@
{:$set {:disable-code-box (boolean disable-flag)}})
(response/redirect "/problems")))

(defn set-hide-solutions [hide-flag]
(with-user [{:keys [_id]}]
(update! :users
{:_id _id}
{:$set {:hide-solutions (boolean hide-flag)}})
(response/redirect "/problems")))

(defroutes users-routes
(GET "/users" [] (users-page))
(GET "/user/:username" [username] (user-profile username))
Expand Down

0 comments on commit 2116421

Please sign in to comment.