Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'feature/privacy' into develop

  • Loading branch information...
commit 2116421385b81f3b41a1634e0ea3ce3cc5ccc7ad 2 parents 5a1004a + 75fd9c0
@amalloy amalloy authored
View
34 src/foreclojure/login.clj
@@ -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]]
@@ -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
@@ -66,17 +67,30 @@
[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"]])]]])})
(defn do-update-credentials! [new-username old-pwd new-pwd repeat-pwd]
@@ -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)))
View
5 src/foreclojure/problems.clj
@@ -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:")]
View
15 src/foreclojure/solutions.clj
@@ -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
View
10 src/foreclojure/users.clj
@@ -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})))
@@ -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))
Please sign in to comment.
Something went wrong with that request. Please try again.