aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Barksdale <amatus.amongus@gmail.com>2012-04-04 21:59:12 -0500
committerDavid Barksdale <amatus.amongus@gmail.com>2012-04-04 21:59:12 -0500
commitabbb4cf8b090bb95087f52dcc42927d13f792e36 (patch)
tree71b20b626214ca5b02ebfde87f661e1e83666ca6
parent58d95efffff28e28d4f8db885b7abe7613728740 (diff)
Added flag form and login sessions.
-rw-r--r--src/ctf_website/views/flag.clj22
-rw-r--r--src/ctf_website/views/home.clj21
-rw-r--r--src/ctf_website/views/login.clj8
3 files changed, 43 insertions, 8 deletions
diff --git a/src/ctf_website/views/flag.clj b/src/ctf_website/views/flag.clj
new file mode 100644
index 0000000..c174215
--- /dev/null
+++ b/src/ctf_website/views/flag.clj
@@ -0,0 +1,22 @@
+(ns ctf-website.views.flag
+ (:require [ctf-website.views.common :as common]
+ [noir.session :as session])
+ (:use [noir.core :only [defpage]]
+ [hiccup.core :only [html]]))
+
+(def no-session
+ (common/layout
+ [:p "You seem to have lost your session. Try to "
+ [:a {:href "login"} "login"]
+ " again."]))
+
+(def good
+ (common/layout
+ [:p "Your flag was accepted."]))
+
+(defpage
+ [:post "/flag"] {:keys [flag]}
+ (let [username (session/get :user)]
+ (if (nil? username)
+ no-session
+ good)))
diff --git a/src/ctf_website/views/home.clj b/src/ctf_website/views/home.clj
index dafb578..450d605 100644
--- a/src/ctf_website/views/home.clj
+++ b/src/ctf_website/views/home.clj
@@ -1,9 +1,20 @@
(ns ctf-website.views.home
- (:require [ctf-website.views.common :as common])
+ (:require [ctf-website.views.common :as common]
+ [noir.session :as session])
(:use [noir.core :only [defpage]]
[hiccup.core :only [html]]))
-(defpage "/" []
- (common/layout
- [:h1 "Austin 2600 CTF server"]
- [:a {:href "login"} "Compete"]))
+(defpage
+ "/" []
+ (let [username (session/get :user)]
+ (common/layout
+ [:h1 "Austin 2600 CTF server"]
+ (if (nil? username)
+ [:a {:href "login"} "Compete"]
+ [:form {:method "POST"
+ :action "flag"}
+ [:p (str "Submit flag as " username ":")
+ [:input {:type "text"
+ :name "flag"}]
+ [:input {:type "submit"
+ :value "Submit"}]]]))))
diff --git a/src/ctf_website/views/login.clj b/src/ctf_website/views/login.clj
index 2909c56..063ee74 100644
--- a/src/ctf_website/views/login.clj
+++ b/src/ctf_website/views/login.clj
@@ -1,5 +1,6 @@
(ns ctf-website.views.login
- (:require [ctf-website.views.common :as common])
+ (:require [ctf-website.views.common :as common]
+ [noir.session :as session])
(:import net.sf.jpam.Pam)
(:use [noir.core :only [defpage]]
[hiccup.core :only [html]]))
@@ -8,8 +9,9 @@
(let [pam (Pam.)
authenticated (.authenticateSuccessful pam username password)]
(if authenticated
- (common/layout
- [:p "You're in"])
+ (do
+ (session/put! :user username)
+ (ring.util.response/redirect "/"))
(common/layout
[:p "Go away"]))))