Skip to content

Commit

Permalink
Merge branch 'release/1.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
amalloy committed Sep 12, 2011
2 parents 5487bff + f05dc0d commit ce29962
Show file tree
Hide file tree
Showing 21 changed files with 680 additions and 449 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -47,6 +47,7 @@ vaguely like this:
* [Devin Walters](https://github.com/devn) (devn)
* [Michael Kohl](https://github.com/citizen428) (citizen428)
* [Martin Sander](https://github.com/marvinthepa) (0x89)
* [Alex McNamara](https://github.com/amcnamara) (amcnamara)


Problem sources:
Expand Down
6 changes: 5 additions & 1 deletion config.clj
Expand Up @@ -7,4 +7,8 @@
:problem-submission true
:advanced-user-count 50
:pass ""
:golfing-active true}
:repo-url "https://github.com/4clojure/4clojure"
:golfing-active true
;; this list is just for bootstrapping - the real DB is authoritative
:contributors ["amalloy" "dbyrne" "raynes" "cmeier" "devn" "0x89"
"citizen428" "daviddavis" "clinteger" "amcnamara"]}
4 changes: 2 additions & 2 deletions project.clj
@@ -1,4 +1,4 @@
(defproject foreclojure "1.1.5"
(defproject foreclojure "1.2.0"
:description "4clojure - a website for lisp beginners"
:dependencies [[clojure "1.2.1"]
[clojure-contrib "1.2.0"]
Expand All @@ -8,7 +8,7 @@
[sandbar "0.4.0-SNAPSHOT"]
[org.clojars.christophermaier/congomongo "0.1.4-SNAPSHOT"]
[org.jasypt/jasypt "1.7"]
[amalloy/utils "[0.3.7,)"]
[useful "0.7.0-beta1"]
[amalloy/ring-gzip-middleware "[0.1.0,)"]
[clj-github "1.0.1"]
[ring "0.3.7"]
Expand Down
56 changes: 56 additions & 0 deletions resources/public/css/style.css
Expand Up @@ -9,6 +9,19 @@ body {

img {border:none}

div.progress-bar-bg {
border: 1px solid black;
height: 7px;
width: 100px;
display: block;
}

div.progress-bar {
background-color: #00FF00;
height: 100%;
display: block;
float: left;
}

#account.header-option {
float:right;
Expand Down Expand Up @@ -103,6 +116,11 @@ a.novisited {color: #00e;}
#menu a {text-decoration: none; font-size: 14px; font-weight:bold;}
#menu a.menu {margin: 15px;}

.user-profile-link{
text-decoration: none;
color: black;
}

#user-info{
float:right;
}
Expand Down Expand Up @@ -296,6 +314,22 @@ td.title-link {
font-size: 16px;
}

td.count-total {
font-weight: bold;
}

td.count-total-value {
font-weight: bold;
text-align: right;
width: 45px;
}

td.count-value {
text-align: right;
width: 45px;
padding-left: 15px;
}

table.my-table th {
padding: 10px 0px 0px 0px;
font-size: 14px;
Expand Down Expand Up @@ -398,5 +432,27 @@ button:active {

a.graph-class :hover {color: #445599;}

#help-content{
width: 90%;
}

#github-banner {
float: right;
display: block;
border: 0px;
width: 135px;
height: 135px;
margin-top: -20px;
background-image: url(/images/banner.png);
background-repeat: no-repeat;
background-position: top right;
}

#github-banner a {
width: 100%;
height: 100%;
display: block;
}



Binary file added resources/public/images/banner.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions resources/public/script/foreclojure.js
Expand Up @@ -80,6 +80,10 @@ function configureCodeBox(){
//If we have javascript on then we remove it and replace it with
//the proper div
var oldBox = $('#code-box');
var disableJavaScriptCodeBox = $('#disable-javascript-codebox');
if (disableJavaScriptCodeBox.length){
return;
}
var hiddenCodeInput = "<input type=\"hidden\" value=\"blank\" name=\"code\" id=\"code\">";
oldBox.replaceWith("<div id=\"code-div\"> <pre id=\"editor\">" + oldBox.val() + "</pre></div>"+hiddenCodeInput);

Expand Down
4 changes: 4 additions & 0 deletions src/foreclojure/config.clj
Expand Up @@ -5,3 +5,7 @@
(def config-file (file (System/getProperty "user.dir") "config.clj"))

(def config (safely read-config config-file))

;; Defs both for convenience and compile-time verification of simple settings
(def repo-url (or (:repo-url config)
(throw (Exception. "config.clj needs a :repo-url key"))))
33 changes: 22 additions & 11 deletions src/foreclojure/core.clj
@@ -1,15 +1,26 @@
(ns foreclojure.core
(:use compojure.core
[foreclojure static problems login register golf ring
users config social version graphs mongo utils]
ring.adapter.jetty
somnium.congomongo
(ring.middleware (reload :only [wrap-reload])
(stacktrace :only [wrap-stacktrace])
[file-info :only [wrap-file-info]]
[gzip :only [wrap-gzip]]))
(:require [compojure [route :as route] [handler :as handler]]
[sandbar.stateful-session :as session]))
(:require [compojure.route :as route]
[compojure.handler :as handler]
[sandbar.stateful-session :as session])
(:use [compojure.core :only [defroutes GET]]
[foreclojure.static :only [static-routes welcome-page]]
[foreclojure.problems :only [problems-routes]]
[foreclojure.login :only [login-routes]]
[foreclojure.register :only [register-routes]]
[foreclojure.golf :only [golf-routes]]
[foreclojure.ring :only [resources wrap-strip-trailing-slash wrap-url-as-file]]
[foreclojure.users :only [users-routes]]
[foreclojure.config :only [config]]
[foreclojure.social :only [social-routes]]
[foreclojure.version :only [version-routes]]
[foreclojure.graphs :only [graph-routes]]
[foreclojure.mongo :only [prepare-mongo]]
[foreclojure.utils :only [wrap-uri-binding]]
[ring.adapter.jetty :only [run-jetty]]
[ring.middleware.reload :only [wrap-reload]]
[ring.middleware.stacktrace :only [wrap-stacktrace]]
[ring.middleware.file-info :only [wrap-file-info]]
[ring.middleware.gzip :only [wrap-gzip]]))

(def *block-server* false)

Expand Down
15 changes: 8 additions & 7 deletions src/foreclojure/golf.clj
@@ -1,11 +1,12 @@
(ns foreclojure.golf
(:use hiccup.form-helpers
hiccup.page-helpers
[foreclojure utils config users]
compojure.core
somnium.congomongo)
(:require [ring.util.response :as response]
[sandbar.stateful-session :as session]))
(:require [ring.util.response :as response]
[sandbar.stateful-session :as session])
(:use [hiccup.form-helpers :only [form-to check-box]]
[hiccup.page-helpers :only [link-to]]
[foreclojure.utils :only [def-page with-user]]
[foreclojure.users :only [golfer?]]
[compojure.core :only [defroutes POST GET]]
[somnium.congomongo :only [update!]]))

(def-page golfer-page []
"Your preferences have been saved.")
Expand Down
23 changes: 11 additions & 12 deletions src/foreclojure/graphs.clj
@@ -1,22 +1,21 @@
(ns foreclojure.graphs
(:use compojure.core
(foreclojure utils)
somnium.congomongo
(amalloy.utils [transform :only [with-adjustments]]
[reorder :only [reorder]]))
(:require (incanter [charts :as chart]
[core :as incanter]
[stats :as stats]))
(:import (java.io ByteArrayInputStream
ByteArrayOutputStream)))
(:require [incanter.charts :as chart]
[incanter.core :as incanter]
[incanter.stats :as stats])
(:import [java.io ByteArrayInputStream
ByteArrayOutputStream])
(:use [compojure.core :only [defroutes GET]]
[foreclojure.utils :only [from-mongo]]
[somnium.congomongo :only [fetch-one]]
[useful.utils :only [with-adjustments]]))

(defn un-group
"Turn a compact set of [data-point num-repetitions] pairs into a
bunch of repeated data points so that incanter will make a histogram
of them."
[frequencies]
(mapcat (partial apply (reorder repeat))
frequencies))
(apply concat (for [[x count] frequencies]
(repeat count x))))

(defn fetch-score-frequencies [problem-id]
(into {}
Expand Down
137 changes: 79 additions & 58 deletions src/foreclojure/login.clj
@@ -1,38 +1,41 @@
(ns foreclojure.login
(:import org.jasypt.util.password.StrongPasswordEncryptor)
(:use hiccup.form-helpers
hiccup.page-helpers
[foreclojure utils config users]
compojure.core
[amalloy.utils :only [rand-in-range keywordize]]
[clojail.core :only [thunk-timeout]]
clojure.stacktrace
somnium.congomongo)
(:require [sandbar.stateful-session :as session]
[ring.util.response :as response]))
(:require [sandbar.stateful-session :as session]
[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 [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]]
[compojure.core :only [defroutes GET POST]]
[useful.map :only [keyed]]
[clojail.core :only [thunk-timeout]]
[clojure.stacktrace :only [print-cause-trace]]
[somnium.congomongo :only [update! fetch-one]]))

(def-page my-login-page [location]
(when location
(session/session-put! :login-to location)
nil) ;; don't include this in HTML output
[:div.error
(session/flash-get :error)
(session/flash-get :message)]
(form-to [:post "/login"]
[:table
[:tr
[:td (label :user "Username")]
[:td (text-field :user)]]
[:tr
[:td (label :pwd "Password")]
[:td (password-field :pwd)]]
[:tr
[:td]
[:td [:button {:type "submit"} "Log In"]]]
[:tr
[:td]
[:td
[:a {:href "/login/reset"} "Forgot your password?"]]]]))
{:title "4clojure - login"
:content
(list
(when location
(session/session-put! :login-to location)
nil) ;; don't include this in HTML output
[:div.error
(session/flash-get :error)
(session/flash-get :message)]
(form-to [:post "/login"]
[:table
[:tr
[:td (label :user "Username")]
[:td (text-field :user)]]
[:tr
[:td (label :pwd "Password")]
[:td (password-field :pwd)]]
[:tr
[:td]
[:td [:button {:type "submit"} "Log In"]]]
[:tr
[:td]
[:td
[:a {:href "/login/reset"} "Forgot your password?"]]]]))})

(defn do-login [user pwd]
(let [user (.toLowerCase user)
Expand All @@ -48,20 +51,33 @@
(flash-error "Error logging in." "/login"))))

(def-page update-credentials-page []
(with-user [{:keys [user] :as user-obj}]
[:div#account-settings
[:div#update-pwd
[:h2 "Change password for " user]
[:span.error (session/flash-get :error)]
[: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"]]])]]]))
{:title "Change password"
:content
(with-user [{:keys [user] :as user-obj}]
[:div#account-settings
[:div#update-pwd
[:h2 "Change password for " user]
[:span.error (session/flash-get :error)]
[: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"]]])]
[: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"]])]]])})

(defn do-update-credentials! [new-username old-pwd new-pwd repeat-pwd]
(with-user [{:keys [user pwd]}]
Expand Down Expand Up @@ -91,23 +107,25 @@
(flash-error why "/login/update")))))

(def-page reset-password-page []
[:div
[:div#reset-help
[:h3 "Forgot your password?"]
[:div "Enter your email address and we'll send you a new password."]
[:div
[:span.error (session/flash-get :error)]
(form-to [:post "/login/reset"]
(label :email "Email")
(text-field :email)
[:button {:type "submit"} "Reset!"])]]])
{:title "Reset password"
:content
[:div
[:div#reset-help
[:h3 "Forgot your password?"]
[:div "Enter your email address and we'll send you a new password."]
[:div
[:span.error (session/flash-get :error)]
(form-to [:post "/login/reset"]
(label :email "Email")
(text-field :email)
[:button {:type "submit"} "Reset!"])]]]})

(let [pw-chars "abcdefghijklmnopqrstuvxyzABCDEFGHIJKLMNOPQRSTUVWXY1234567890"]
(defn random-pwd []
(let [pw (apply str
(repeatedly 10 #(rand-nth pw-chars)))
hash (.encryptPassword (StrongPasswordEncryptor.) pw)]
(keywordize [pw hash]))))
(keyed [pw hash]))))

(defn try-to-email [email name id]
(let [{:keys [pw hash]} (random-pwd)]
Expand Down Expand Up @@ -166,4 +184,7 @@

(GET "/logout" []
(do (session/session-delete-key! :user)
(response/redirect "/"))))
(response/redirect "/")))

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

0 comments on commit ce29962

Please sign in to comment.