diff options
author | maride <maride@darknebu.la> | 2018-08-21 14:57:27 +0200 |
---|---|---|
committer | maride <maride@darknebu.la> | 2018-08-21 14:57:27 +0200 |
commit | f35350d2691007a1b52c3b1e16794ec74702cd0d (patch) | |
tree | 8abebd22ed9521778fd72293fda652d0d726f6ce /hosted | |
parent | 30f637177f06ac15cdd2cd694e874c970f92bd15 (diff) |
Submit flags in background
Diffstat (limited to 'hosted')
-rw-r--r-- | hosted/challenges.html | 46 |
1 files changed, 38 insertions, 8 deletions
diff --git a/hosted/challenges.html b/hosted/challenges.html index 65d6bb3..3c18f2d 100644 --- a/hosted/challenges.html +++ b/hosted/challenges.html @@ -26,7 +26,7 @@ {{#if foundFlag}} <p class="text-success">Flag found!</p> {{else}} - <form class="input-group mb-3" method="POST" action="/api/submitFlag"> + <form class="input-group mb-3" onsubmit="event.preventDefault();submitThis(this);"> <input type="hidden" name="challengeName" value="{{ name }}"> <input type="text" class="form-control" aria-label="Flag" aria-describedby="button-submit" name="flag"> <div class="input-group-append"> @@ -60,17 +60,47 @@ </div> </nav> <main class="container" role="main" id="challenge-list"> + <div class="alert alert-info" role="alert"> + Loading challenges... + </div> </main> </body> <script type="text/javascript"> var template = Handlebars.compile($("#body-template").html()); - $.ajax({ - url: "/api/getChallenges", - success: function(result) { - $("#challenge-list").html( - template(jQuery.parseJSON(result)) - ); - } + + function loadChallengesAndRender() { + $.ajax({ + url: "/api/getChallenges", + success: function(result) { + $("#challenge-list").html( + template(jQuery.parseJSON(result)) + ); + } + }); + } + + function submitThis(t) { + submitFlag($(t).find('[name=challengeName]').val(), $(t).find('[name=flag]')); + } + + function submitFlag(challengeName, flagObject) { + $.post("/api/submitFlag", { + "challengeName": challengeName, + "flag": flagObject.val() + }).done(function(data) { + var result = jQuery.parseJSON(data); + if(result["correctFlag"] == "true") { + // yay! + loadChallengesAndRender(); + } else { + // nay! + flagObject.addClass("alert-danger").blur(); + } + }); + } + + $(document).ready(function() { + loadChallengesAndRender(); }); </script> </html> \ No newline at end of file |