aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Barksdale <amatus@amatus.name>2015-12-30 16:14:29 -0600
committerDavid Barksdale <amatus@amatus.name>2015-12-30 16:14:29 -0600
commit9c09e8189f04fe2e3d88b00f750f61800b47541e (patch)
tree2c6d351775beee60cb459f4ff4b640689d085702
parent8e92287880895931d077baf1a9f05f88b7371c7c (diff)
Login, flag submission, table style
-rw-r--r--.gitignore1
-rw-r--r--assets/css/main.css17
-rw-r--r--src/app/api.clj20
-rw-r--r--src/app/rpc.cljs13
-rw-r--r--src/index.cljs.hl45
5 files changed, 92 insertions, 4 deletions
diff --git a/.gitignore b/.gitignore
index d0ac88a..9592e6c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
target/
sdb.db
.nrepl-*
+*.swp
diff --git a/assets/css/main.css b/assets/css/main.css
index bd431a9..420e2ba 100644
--- a/assets/css/main.css
+++ b/assets/css/main.css
@@ -33,3 +33,20 @@ h1,h2,h3 {
table th {
font-family: "Proxima-bold"
}
+
+table {
+ border-collapse: collapse;
+}
+
+td {
+ border: 1px solid black
+}
+
+th {
+ border-left: 1px solid black;
+ border-right: 1px solid black
+}
+
+#error {
+ color: red
+}
diff --git a/src/app/api.clj b/src/app/api.clj
index e83f187..27ed9a4 100644
--- a/src/app/api.clj
+++ b/src/app/api.clj
@@ -4,3 +4,23 @@
(defrpc get-scoreboard []
(db/get :scoreboard))
+
+(defrpc check-token [token]
+ {:rpc/pre (contains? (db/get :tokens) token)}
+ true)
+
+(defrpc set-name! [token name]
+ {:rpc/pre (contains? (db/get :tokens) token)}
+ (db/update! :scoreboard
+ assoc-in
+ [(first (.split token "-")) :name]
+ (apply str (take 32 name))))
+
+(defrpc submit-flag! [token flag]
+ {:rpc/pre (and (contains? (db/get :tokens) token)
+ (contains? (db/get :flags) flag))}
+ (let [problem (db/get-in :flags [flag])]
+ (db/update! :scoreboard
+ assoc-in
+ [(first (.split token "-")) :scores problem]
+ :solved)))
diff --git a/src/app/rpc.cljs b/src/app/rpc.cljs
index 464809c..3698ae2 100644
--- a/src/app/rpc.cljs
+++ b/src/app/rpc.cljs
@@ -6,11 +6,22 @@
[castra.core :refer [mkremote]]))
(defc scoreboard nil)
+(defc scoreboard-error nil)
(defc error nil)
(defc loading [])
+(defc token-ok false)
(def get-scoreboard
- (mkremote 'app.api/get-scoreboard scoreboard error loading))
+ (mkremote 'app.api/get-scoreboard scoreboard scoreboard-error loading))
+
+(def check-token
+ (mkremote 'app.api/check-token token-ok error loading))
+
+(def set-name!
+ (mkremote 'app.api/set-name! scoreboard error loading))
+
+(def submit-flag!
+ (mkremote 'app.api/submit-flag! scoreboard error loading))
(defn init []
(get-scoreboard)
diff --git a/src/index.cljs.hl b/src/index.cljs.hl
index 8ecbc8c..82980cc 100644
--- a/src/index.cljs.hl
+++ b/src/index.cljs.hl
@@ -33,6 +33,11 @@
id])
scoreboard))))
+(defc token nil)
+(defc= logged-in? rpc/token-ok)
+(defc= error rpc/error)
+(defc= error-message (when error (.-message error)))
+
(rpc/init)
(html
@@ -41,13 +46,47 @@
(title "Potluck CTF"))
(body
(h1 "Potluck CTF")
- (text "Login/Register?")
+ (div
+ :id "error"
+ :click #(reset! rpc/error nil)
+ :toggle (cell= (not (nil? rpc/error)))
+ (text "Error: ~{error-message}"))
+ (let [token-input (input :name "token")]
+ (form
+ :toggle (cell= (not logged-in?))
+ :submit #(do (reset! token (.-value token-input))
+ (rpc/check-token @token)
+ (set! (.-value token-input) nil))
+ (text "Registration Token:")
+ token-input
+ (input :type "submit")))
+ (let [name-input (input :name "name")]
+ (form
+ :toggle logged-in?
+ :submit #(do (rpc/set-name! @token (.-value name-input))
+ (set! (.-value name-input) nil))
+ (text "Change Name:")
+ name-input
+ (input :type "submit")))
+ (let [flag-input (input :name "flag")]
+ (form
+ :toggle logged-in?
+ :submit #(do (rpc/submit-flag! @token (.-value flag-input))
+ (set! (.-value flag-input) nil))
+ (text "Flag:")
+ flag-input
+ (input :type "submit")))
+ (form
+ :toggle logged-in?
+ :submit #(do (reset! token nil)
+ (reset! rpc/token-ok false))
+ (input :type "submit" :value "Logout"))
(h2 "Scoreboard")
(table
(thead
(tr
- (th)
- (th)
+ (th :colspan 2
+ :style "border:none")
(loop-tpl :bindings [probs (cell= (partition-by first problems))]
(th :text (cell= (:name (get scoreboard
(first (first probs)))))