Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
120 lines (107 sloc) 3.68 KB
(ns clojars.web
(:require [clojure.contrib.sql :as sql])
(:use [clojars.db]
[clojars.web dashboard group jar login search user common]
(defn not-found-doc []
(html [:h1 "Page not found"]
[:p "Thundering typhoons! I think we lost it. Sorry!"]))
(defmacro with-account [body]
`(if-let [~'account (~'session :account)]
(do ~body)
(redirect "/login")))
(defmacro try-account [body]
`(let [~'account (~'session :account)]
(do ~body)))
(defroutes main-routes
(GET "/search" {session :session params :params}
(search account params)))
(GET "/profile" {session :session params :params}
(profile-form account)))
(POST "/profile" {session :session params :params}
(update-profile account params)))
(GET "/login" {params :params}
(POST "/login" {params :params}
(login params))
(POST "/register" {params :params}
(register params))
(GET "/register" {params :params}
(POST "/forgot-password" {params :params}
(forgot-password params))
(GET "/forgot-password" {params :params}
(GET "/logout" request
(let [response (redirect "/")]
(assoc-in response [:session :account] nil)))
(GET "/" {session :session params :params}
(if account
(dashboard account)
(index-page account))))
(GET ["/groups/:group", :group #"[^/]+"] {session :session {group "group"} :params }
(if-let [members (with-db (group-members group))]
(show-group account group members))
(POST ["/groups/:group", :group #"[^/]+"] {session :session {group "group" user "user"} :params }
(if-let [members (with-db (group-members group))]
(some #{user} members)
(show-group account group members "They're already a member!")
(and (some #{account} members)
(find-user user))
(do (add-member group user)
(show-group account group
(conj members user)))
(show-group account group members (str "No such user: "
(h user)))))
(GET "/users/:username" {session :session {username "username"} :params}
(if-let [user (with-db (find-user username))]
(show-user account user))
(GET "/:jarname" {session :session {jarname "jarname"} :params}
(if-let [jar (with-db (find-canon-jar jarname))]
(show-jar account jar))
(GET ["/:group/:jarname", :group #"[^/]+", :jarname #"[^/]+"]
{session :session {group "group" jarname "jarname"} :params}
(if-let [jar (with-db (find-jar group jarname))]
(show-jar account jar))
(GET "/:user" {session :session {user "user"} :params}
(if-let [user (with-db (find-user user))]
(show-user account user))
(ANY "*" {session :session}
(html-doc (session :account) "Page not found" (not-found-doc))))
(def clojars-app
(-> main-routes
(wrap-file "public")
;(require 'swank.swank)
;(swank.swank/start-server "/dev/null" :port 4005)
;(use 'clojure.contrib.repl-utils)
;(show server)
;(.stop server)
;(with-db (find-jar "leiningen"))
;(def server (run-server {:port 8000} "/*" (servlet clojars-app)))
Something went wrong with that request. Please try again.