Permalink
Browse files

Merge branch 'release/1.1.5'

  • Loading branch information...
2 parents 175ef19 + b630b8d commit 5487bffc89d666f327b38a44fedfc2311a70b4a7 @amalloy amalloy committed Sep 1, 2011
View
2 project.clj
@@ -1,4 +1,4 @@
-(defproject foreclojure "1.1.4"
+(defproject foreclojure "1.1.5"
:description "4clojure - a website for lisp beginners"
:dependencies [[clojure "1.2.1"]
[clojure-contrib "1.2.0"]
View
2 resources/public/css/style.css
@@ -168,6 +168,7 @@ a.novisited {color: #00e;}
.rss {
width: 24px;
float: left;
+ clear: left;
background-image: url('../images/feed.png');
background-repeat: no-repeat;
background-position: top right;
@@ -189,7 +190,6 @@ div.message {
font-size: 16px;
width: 75%;
float: left;
- position: absolute;
}
span#prob-title {
View
6 resources/public/script/foreclojure.js
@@ -29,22 +29,24 @@ function configureDataTables(){
$('#problem-table').dataTable( {
"iDisplayLength": 25,
- "aaSorting": [[ 3, "desc" ]],
+ "aaSorting": [[ 4, "desc" ]],
"aoColumns": [
null,
null,
null,
null,
+ null,
{ "sType": "string" }
]
} );
$('#unapproved-problems').dataTable( {
"iDisplayLength": 25,
- "aaSorting": [[ 2, "desc" ]],
+ "aaSorting": [[ 3, "desc" ]],
"aoColumns": [
null,
null,
+ null,
null
]
} );
View
7 src/foreclojure/core.clj
@@ -11,6 +11,8 @@
(:require [compojure [route :as route] [handler :as handler]]
[sandbar.stateful-session :as session]))
+(def *block-server* false)
+
(defroutes main-routes
(GET "/" [] (welcome-page))
login-routes
@@ -39,7 +41,8 @@
(defn run []
(prepare-mongo)
- (run-jetty (var app) {:join? false :port 8080}))
+ (run-jetty (var app) {:join? *block-server* :port 8080}))
(defn -main [& args]
- (run))
+ (binding [*block-server* true]
+ (run)))
View
47 src/foreclojure/login.clj
@@ -47,7 +47,7 @@
(response/redirect (or location "/problems")))
(flash-error "Error logging in." "/login"))))
-(def-page update-password-page []
+(def-page update-credentials-page []
(with-user [{:keys [user] :as user-obj}]
[:div#account-settings
[:div#update-pwd
@@ -56,26 +56,39 @@
[:table
(form-to [:post "/login/update"]
(map form-row
- [[password-field :old-pwd "Current password"]
- [password-field :pwd "New password"]
- [password-field :repeat-pwd "Repeat password"]])
+ [[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 do-update-password! [old-pwd new-pwd repeat-pwd]
+(defn do-update-credentials! [new-username old-pwd new-pwd repeat-pwd]
(with-user [{:keys [user pwd]}]
- (let [encryptor (StrongPasswordEncryptor.)]
- (assuming [(= new-pwd repeat-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"]
- (let [new-pwd-hash (.encryptPassword encryptor new-pwd)]
- (update! :users {:user user}
- {:$set {:pwd new-pwd-hash}}
- :upsert false)
- (flash-msg (str "Password for " user " updated successfully")
- "/problems"))
- (flash-error why "/login/update")))))
+ (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 (str "Account for " new-lower-user " updated successfully")
+ "/problems"))
+ (flash-error why "/login/update")))))
(def-page reset-password-page []
[:div
@@ -143,9 +156,9 @@
(POST "/login" {{:strs [user pwd]} :form-params}
(do-login user pwd))
- (GET "/login/update" [] (update-password-page))
- (POST "/login/update" {{:strs [old-pwd pwd repeat-pwd]} :form-params}
- (do-update-password! old-pwd pwd repeat-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]
View
35 src/foreclojure/problems.clj
@@ -27,7 +27,7 @@
([criteria]
(from-mongo
(fetch :problems
- :only [:_id :title :tags :times-solved :user]
+ :only [:_id :title :difficulty :tags :times-solved :user]
:where criteria
:sort {:_id 1}))))
@@ -237,16 +237,17 @@ Return a map, {:message, :error, :url, :num-tests-passed}."
:golfChart (html (render-golf-chart))})))
(def-page code-box [id]
- (let [{:keys [_id title tags description restricted tests approved user]}
+ (let [{:keys [_id title difficulty tags description restricted tests approved user]}
(get-problem (Integer. id))]
[:div
[:span#prob-title
(when-not approved
"Unapproved: ")
title]
[:hr]
- [:div#tags "Tags: "
- (s/join " " tags)]
+ [:table#tags
+ [:tr [:td "Difficulty:"] [:td (or difficulty "N/A")]]
+ [:tr [:td "Topics:"] [:td (s/join " " tags)]]]
[:br]
(when-not approved
[:div#submitter "Submitted by: "
@@ -293,18 +294,20 @@ Return a map, {:message, :error, :url, :num-tests-passed}."
[:thead
[:tr
[:th "Title"]
- [:th "Tags"]
+ [:th "Difficulty"]
+ [:th "Topics"]
[:th "Submitted By"]
[:th "Times Solved"]
[:th "Solved?"]]]
(let [solved (get-solved (session/session-get :user))
problems (get-problem-list)]
(map-indexed
- (fn [x {:keys [title times-solved tags user], id :_id}]
+ (fn [x {:keys [title difficulty times-solved tags user], id :_id}]
[:tr (row-class x)
[:td.titlelink
[:a {:href (str "/problem/" id)}
title]]
+ [:td.centered difficulty]
[:td.centered
(s/join " " (map #(str "<span class='tag'>" % "</span>")
tags))]
@@ -323,15 +326,17 @@ Return a map, {:message, :error, :url, :num-tests-passed}."
[:thead
[:tr
[:th "Title"]
- [:th "Tags"]
+ [:th "Difficulty"]
+ [:th "Topics"]
[:th "Submitted By"]]]
(let [problems (get-problem-list {:approved false})]
(map-indexed
- (fn [x {:keys [title tags user], id :_id}]
+ (fn [x {:keys [title difficulty tags user], id :_id}]
[:tr (row-class x)
[:td.titlelink
[:a {:href (str "/problem/" id)}
title]]
+ [:td.centered difficulty]
[:td.centered
(s/join " " (map #(str "<span class='tag'>" % "</span>")
tags))]
@@ -352,7 +357,9 @@ Return a map, {:message, :error, :url, :num-tests-passed}."
(hidden-field :prob-id (session/flash-get :prob-id))
(label :title "Problem Title")
(text-field :title (session/flash-get :title))
- (label :tags "Tags (space separated)")
+ (label :diffulty "Difficulty")
+ (drop-down :difficulty ["Elementary" "Easy" "Medium" "Hard"] (session/flash-get :difficulty))
+ (label :tags "Topics (space separated)")
(text-field :tags (session/flash-get :tags))
(label :restricted "Restricted Functions (space separated)")
(text-field :restricted (session/flash-get :restricted))
@@ -367,7 +374,7 @@ Return a map, {:message, :error, :url, :num-tests-passed}."
(defn create-problem
"create a user submitted problem"
- [title tags restricted description code id author]
+ [title difficulty tags restricted description code id author]
(let [user (session/session-get :user)]
(if (can-submit? user)
(let [id (or id
@@ -392,6 +399,7 @@ Return a map, {:message, :error, :url, :num-tests-passed}."
{:_id id}
{:_id id
:title title
+ :difficulty difficulty
:times-solved 0
:description description
:tags (re-seq #"\S+" tags)
@@ -404,10 +412,11 @@ Return a map, {:message, :error, :url, :num-tests-passed}."
(defn edit-problem [id]
(if (approver? (session/session-get :user))
- (let [{:keys [title user tags restricted description tests]} (get-problem id)]
+ (let [{:keys [title user difficulty tags restricted description tests]} (get-problem id)]
(doseq [[k v] {:prob-id id
:author user
:title title
+ :difficulty difficulty
:tags (s/join " " tags)
:restricted (s/join " " restricted)
:description description
@@ -453,8 +462,8 @@ Return a map, {:message, :error, :url, :num-tests-passed}."
(GET "/problems" [] (problem-page))
(GET "/problem/:id" [id] (code-box id))
(GET "/problems/submit" [] (problem-submission-page))
- (POST "/problems/submit" [prob-id author title tags restricted description code]
- (create-problem title tags restricted description code (when (not= "" prob-id) (Integer. prob-id)) author))
+ (POST "/problems/submit" [prob-id author title difficulty tags restricted description code]
+ (create-problem title difficulty tags restricted description code (when (not= "" prob-id) (Integer. prob-id)) author))
(GET "/problems/unapproved" [] (unapproved-problems))
(POST "/problem/edit" [id]
(edit-problem (Integer. id)))

0 comments on commit 5487bff

Please sign in to comment.