summaryrefslogtreecommitdiff
path: root/src/site.clj
diff options
context:
space:
mode:
Diffstat (limited to 'src/site.clj')
-rwxr-xr-xsrc/site.clj29
1 files changed, 16 insertions, 13 deletions
diff --git a/src/site.clj b/src/site.clj
index 167f4d5..60f07d7 100755
--- a/src/site.clj
+++ b/src/site.clj
@@ -155,12 +155,6 @@
(def *dumps-per-page* 20)
-(defn maybe-parse-int [s f]
- (if s (Integer/parseInt s) f))
-
-(defn maybe-parse-long [s f]
- (if s (Long/parseLong s) f))
-
(defn count-messages-by-room [room-id image-only]
(let [query (str "SELECT COUNT(*) "
"FROM messages m, users u "
@@ -210,13 +204,17 @@
;; Templates
-(defn fetch-template [template-name session]
- (let [st (.getInstanceOf template-group template-name)]
- (if (and st (session :nick))
+;; TODO: avoid exception
+(defn fetch-template [template session]
+ (let [st (.getInstanceOf template-group template)]
+ (if (session :nick)
(do (.setAttribute st "user_nick" (session :nick))
(.setAttribute st "isadmin" (session :is_admin))))
st))
+(defn serve-template [template session]
+ (.toString (fetch-template template session)))
+
;; Login code
(defn session-map-from-db
@@ -301,7 +299,7 @@
invalid-nick-reason (is-invalid-nick? nick)]
(cond invalid-nick-reason (resp-error invalid-nick-reason)
(fetch-nick nick) (resp-error "NICK_TAKEN")
- :else (with-connection db
+ :else (with-connection *db*
(insert-values :users
[:nick :hash :email]
[nick hash email])
@@ -338,7 +336,7 @@
(defn update-user-db [user-id attr val]
- (with-connection db
+ (with-connection *db*
(update-values "users" ["user_id = ?" user-id] {attr val})))
(defn download-avatar [session url]
@@ -430,7 +428,7 @@
(let [is-image (is-image? content)
qry (str "INSERT INTO messages (user_id, room_id, content, is_image) "
"VALUES (?, ?, ?, ?) RETURNING message_id")]
- (with-connection db
+ (with-connection *db*
((first (do-select [qry user-id room-id content is-image]))
:message_id))))
@@ -596,7 +594,7 @@
(defroutes pichat
(GET "/" (no-cache (landing session)))
(GET "/favicon.ico" (serve-static "static" "favicon.ico"))
- (GET "/u/:nick" (profile session (params :nick) "0"))
+ (GET "/u/:nick" (profile session (params :nick) "0"))
(GET "/u/:nick/" (profile session (params :nick) "0"))
(GET "/u/:nick/:offset" (profile session
(params :nick)
@@ -621,6 +619,11 @@
(POST "/msg" (validated-msg session params))
(POST "/submit-registration" (register session params))
(POST "/update-profile" (update-profile session params))
+ (GET "/about_us" (serve-template "about_us" session))
+ (GET "/goodies" (serve-template "goodies" session))
+ (GET "/help" (serve-template "help" session))
+ (GET "/privacy" (serve-template "privacy" session))
+ (GET "/terms" (serve-template "terms" session))
(ANY "*" (unknown-page params)))
(defroutes multipart