Permalink
Browse files

Merge branch 'feature/if-user' of https://github.com/amalloy/4clojure

…into develop

Conflicts:
	resources/public/script/foreclojure.js
  • Loading branch information...
amcnamara committed Oct 16, 2011
2 parents e2911e3 + bc124ae commit d8a506f425b26666a2d81f23eeb165433b6401e6
View
@@ -1,9 +1,9 @@
-(defproject foreclojure "1.5.0.2"
- :description "4clojure - a website for lisp beginners"
+(defproject foreclojure "1.5.1.1"
+ :description "4clojure - a website for learning Clojure"
:dependencies [[clojure "1.2.1"]
[clojure-contrib "1.2.0"]
[compojure "0.6.2"]
- [hiccup "0.2.4"]
+ [hiccup "0.3.6"]
[clojail "0.4.0-SNAPSHOT"]
[sandbar "0.4.0-SNAPSHOT"]
[org.clojars.christophermaier/congomongo "0.1.4-SNAPSHOT"]
@@ -232,19 +232,12 @@ img.gravatar{
padding-bottom: 5px;;
}
-#user-table{
+#user-table, #server-user-table{
float: left;
width: 100%;
padding: 15px;
}
-#server-user-table{
- float: left;
- width: 100%;
- padding: 15px;
-}
-
-
/*
* By default only show the text label for the "Following" column on
* the users page. If they have javascript turned on (detected
@@ -267,6 +260,14 @@ img.gravatar{
display: none;
}
+/*
+ * If datatables is fetching stuff from the server, we definitely have
+ * javascript enabled, so hide the span to begin with.
+ */
+#server-user-table span.following {
+ display: none;
+}
+
span.error, div.error {
color: red;
@@ -312,7 +313,9 @@ div#main {
}
div.message #flash-text {}
-div.message #error-text {}
+div.message #error-text {
+ color: red;
+}
div#prob-title {
font-size: 15pt;
@@ -41,9 +41,9 @@ $(document).ready(function() {
$("#all-users-link").html("[show <a href=\"/users/all\">all</a>]");
- $("#user-table").addClass("js-enabled");
+ $("#user-table,#server-user-table").addClass("js-enabled");
- $("#user-table input.following").live("click", function(e) {
+ $("#user-table,#server-user-table input.following").live("click", function(e) {
e.preventDefault();
var $checkbox = $(this)
var $form = $checkbox.parents("form")
@@ -59,6 +59,7 @@ $(document).ready(function() {
});
return false;
});
+
});
var difficulty = {
@@ -94,6 +95,19 @@ jQuery.fn.dataTableExt.afnSortData['user-name'] = function(oSettings, iColumn)
return aData;
}
+// See comments for above function to make sense of this mess
+jQuery.fn.dataTableExt.afnSortData['following'] = function(oSettings, iColumn)
+{
+ var aData = [];
+ $('td:eq('+iColumn+') span.following', oSettings.oApi._fnGetTrNodes(oSettings)).each(function () {
+ var followingText = $(this).text();
+ if (!followingText || followingText == "") { followingText = "no" }
+ aData.push(followingText);
+ });
+ return aData;
+}
+
+
function configureDataTables(){
$('#problem-table').dataTable( {
@@ -127,14 +141,19 @@ function configureDataTables(){
{"sType": "numeric"},
{"sSortDataType": "user-name"},
{"sType": "numeric"},
- {"sType": "string"},
- {"sType": "string"}
+ {"sSortDataType": "following"}
]
} );
$('#server-user-table').dataTable( {
- "iDisplayLength":10,
+ "aoColumns": [
+ null,
+ null,
+ null,
+ {"bSortable": false}
+ ],
+ "iDisplayLength":100,
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "/datatable/users"
View
@@ -9,6 +9,7 @@
[foreclojure.datatable :only [datatable-routes]]
[foreclojure.problems :only [problems-routes]]
[foreclojure.login :only [login-routes]]
+ [foreclojure.settings :only [settings-routes]]
[foreclojure.register :only [register-routes]]
[foreclojure.golf :only [golf-routes]]
[foreclojure.ring :only [resources wrap-strip-trailing-slash wrap-url-as-file wrap-versioned-expiry split-hosts wrap-404 wrap-debug]]
@@ -46,7 +47,8 @@
graph-routes
api-routes
datatable-routes
- golf-routes)
+ golf-routes
+ settings-routes)
((if (:wrap-reload config)
#(wrap-reload % '(foreclojure.core))
identity))
@@ -6,5 +6,7 @@
(def datatable-routes
(-> (routes
- (GET "/datatable/users" [& more] {:body (user-datatable-query more)}))
+ (GET "/datatable/users" [& more]
+ {:body (user-datatable-query more)
+ :status 200}))
(wrap-json)))
View
@@ -3,9 +3,8 @@
[ring.util.response :as response])
(:import [org.jasypt.util.password StrongPasswordEncryptor])
(:use [hiccup.form-helpers :only [form-to label text-field password-field check-box]]
- [foreclojure.utils :only [from-mongo flash-error flash-msg with-user form-row assuming send-email login-url]]
+ [foreclojure.utils :only [from-mongo flash-error flash-msg form-row assuming send-email login-url]]
[foreclojure.template :only [def-page content-page]]
- [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,84 +49,6 @@
(response/redirect (or location "/problems")))
(flash-error "/login" "Error logging in."))))
-(defn account-settings-box [user]
- [:table
- (form-to [:post "/login/update"]
- (map form-row
- [[text-field :new-username "Username" user]
- [password-field :old-pwd "Current password"]
- [password-field :pwd "New password"]
- [password-field :repeat-pwd "Repeat password"]])
- [:tr
- [:td [:button {:type "submit"} "Reset now"]]])])
-
-(defn js-settings-box [user-obj]
- (list
- [: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"]])))
-
-(defn hide-settings-box [user-obj]
- (list
- [: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"]])))
-
-(def-page update-credentials-page []
- (with-user [{:keys [user] :as user-obj}]
- {:title "Change password"
- :content
- (content-page
- {:main
- (list
- [:h2 "Change password for " user]
- [:div#account-settings (account-settings-box user)]
- [:hr]
- [:h2 "Disable JavaScript Code Box"]
- [:div#settings-codebox (js-settings-box user-obj)]
- [:hr]
- [:h2 "Hide My Solutions"]
- [:div#settings-follow (hide-settings-box user-obj)])})}))
-
-(defn do-update-credentials! [new-username old-pwd new-pwd repeat-pwd]
- (with-user [{:keys [user pwd]}]
- (let [encryptor (StrongPasswordEncryptor.)
- new-pwd-hash (.encryptPassword encryptor new-pwd)
- new-lower-user (.toLowerCase new-username)]
- (assuming [(or (= new-lower-user user) (nil? (fetch-one :users :where {:user new-lower-user})))
- "User already exists",
- (< 3 (.length new-lower-user) 14)
- "Username must be 4-13 characters long",
- (= new-lower-user
- (first (re-seq #"[A-Za-z0-9_]+" new-lower-user)))
- "Username must be alphanumeric"
- (or (empty? new-pwd) (< 6 (.length new-pwd)))
- "New password must be at least seven characters long",
- (= new-pwd repeat-pwd)
- "New password was not entered identically twice"
- (.checkPassword encryptor old-pwd pwd)
- "Old password incorrect"]
- (do
- (update! :users {:user user}
- {:$set {:pwd (if (not-empty new-pwd) new-pwd-hash pwd) :user new-lower-user}}
- :upsert false)
- (session/session-put! :user new-lower-user)
- (flash-msg "/problems"
- (str "Account for " new-lower-user " updated successfully")))
- (flash-error "/login/update" why)))))
-
(def-page reset-password-page []
{:title "Reset password"
:content
@@ -196,20 +117,10 @@
(POST "/login" {{:strs [user pwd]} :form-params}
(do-login user pwd))
- (GET "/login/update" [] (update-credentials-page))
- (POST "/login/update" {{:strs [new-username old-pwd pwd repeat-pwd]} :form-params}
- (do-update-credentials! new-username old-pwd pwd repeat-pwd))
-
(GET "/login/reset" [] (reset-password-page))
(POST "/login/reset" [email]
(do-reset-password! email))
(GET "/logout" []
(do (session/session-delete-key! :user)
- (response/redirect "/")))
-
- (POST "/users/set-disable-codebox" [disable-codebox]
- (set-disable-codebox disable-codebox))
-
- (POST "/users/set-hide-solutions" [hide-solutions]
- (set-hide-solutions hide-solutions)))
+ (response/redirect "/"))))
@@ -5,7 +5,7 @@
[ring.util.response :as response]
[cheshire.core :as json])
(:import [org.apache.commons.mail EmailException])
- (:use [foreclojure.utils :only [from-mongo get-user get-solved login-link flash-msg flash-error row-class approver? can-submit? send-email image-builder with-user as-int maybe-update escape-html]]
+ (:use [foreclojure.utils :only [from-mongo get-user get-solved login-link flash-msg flash-error row-class approver? can-submit? send-email image-builder if-user with-user as-int maybe-update escape-html]]
[foreclojure.ring-utils :only [*url*]]
[foreclojure.template :only [def-page content-page]]
[foreclojure.social :only [tweet-link gist!]]
@@ -256,15 +256,13 @@ Return a map, {:message, :error, :url, :num-tests-passed}."
:golfChart (html (render-golf-chart))})))
(defn wants-no-javascript-codebox? []
- (when (session/session-get :user)
- (with-user [{:keys [user] :as user-obj}]
- (disable-codebox? user-obj))))
+ (if-user [{:keys [user] :as user-obj}]
+ (disable-codebox? user-obj)))
(def-page code-box [id]
(let [{:keys [_id title difficulty tags description
restricted tests approved user]}
(get-problem (Integer. id)),
- session-user (session/session-get :user)
title (str (when-not approved
"Unapproved: ")
title)]
@@ -273,12 +271,11 @@ Return a map, {:message, :error, :url, :num-tests-passed}."
:content
[:div
[:div#prob-title title]
- (if session-user
- (with-user [{:keys [solved]}]
- (if (some #{(Integer. id)} solved)
- (link-to (str "/problem/solutions/" id)
- [:button#solutions-link {:type "submit"} "Solutions"])
- [:div {:style "clear: right; margin-bottom: 15px;"} "&nbsp;"]))
+ (if-user [{:keys [solved]}]
+ (if (some #{(Integer. id)} solved)
+ (link-to (str "/problem/solutions/" id)
+ [:button#solutions-link {:type "submit"} "Solutions"])
+ [:div {:style "clear: right; margin-bottom: 15px;"} "&nbsp;"])
[:div {:style "clear: right; margin-bottom: 15px;"} "&nbsp;"])
[:hr]
[:table#tags
@@ -365,12 +362,11 @@ Return a map, {:message, :error, :url, :num-tests-passed}."
(defn show-solutions [id]
(let [problem-id (Integer. id)
user (session/session-get :user)]
- (if user
- (with-user [{:keys [solved]}]
- (if (some #{problem-id} solved)
- (show-solutions-page problem-id)
- (flash-error (str "/problem/" problem-id)
- "You must solve this problem before you can see others' solutions!")))
+ (if-user [{:keys [solved]}]
+ (if (some #{problem-id} solved)
+ (show-solutions-page problem-id)
+ (flash-error (str "/problem/" problem-id)
+ "You must solve this problem before you can see others' solutions!"))
(do
(session/session-put! :login-to *url*)
(flash-error "/login" "You must log in to see solutions!")))))
Oops, something went wrong.

0 comments on commit d8a506f

Please sign in to comment.