From 27a61f0f70df91519100158583154e9e6403c27b Mon Sep 17 00:00:00 2001 From: Benedikt - Desktop Date: Tue, 22 Jan 2019 17:28:23 +0100 Subject: [PATCH] Reworked and styled quiz --- .../src/main/resources/static/css/quiz.css | 60 +++++++++++++++++-- .../src/main/resources/static/js/quiz.js | 25 +++++++- .../plugin/advanced/SqlInjectionQuiz.java | 14 +++-- .../resources/html/SqlInjectionAdvanced.html | 2 +- 4 files changed, 88 insertions(+), 13 deletions(-) diff --git a/webgoat-container/src/main/resources/static/css/quiz.css b/webgoat-container/src/main/resources/static/css/quiz.css index 0995d4897..6f20d09ad 100644 --- a/webgoat-container/src/main/resources/static/css/quiz.css +++ b/webgoat-container/src/main/resources/static/css/quiz.css @@ -1,19 +1,67 @@ +.attack-container.quiz { + background: none; + border: none; +} + +#q_container p { + font-weight: bold; +} + #q_container .quiz_question { - border: solid 1px; + border: solid 2px white; padding: 4px; - margin: 5px 2px 5px 2px; + margin: 5px 2px 20px 2px; + box-shadow: 0px 1px 3px 1px #e4e4e4; } #q_container .quiz_question label { font-weight: normal; + position: relative; + top: -2px; +} + +#q_container .quiz_question input { + -webkit-appearance: none; + -moz-appearance: none; + appearance: none; + border: 2px solid #dadada; + background: white; + width: 15px; + height: 15px; + margin-right: 6px; +} + +#q_container .quiz_question input:checked { + background: #51b7ff; +} + +#q_container .quiz_question input:hover, +#q_container .quiz_question label:hover { + cursor: pointer; } #q_container .quiz_question.correct { - border: solid 3px green; - background: #b0dcb0; + border: solid 2px #ddf7dd; + background: #ddf7dd; + transition: all 300ms ease-in-out; } #q_container .quiz_question.incorrect { - border: solid 3px red; - background: #e8b6b6; + border: solid 2px #f5d3d3; + background: #f5d3d3; + transition: all 300ms ease-in-out; +} + +input[name='Quiz_solutions'] { + background: white; + border: 1px solid gray; + padding: 7px 10px; + transition: 300ms all ease-in-out; +} + +input[name='Quiz_solutions']:hover { + background: #51b7ff; + color: white; + border-color: white; + transition: 300ms all ease-in-out; } \ No newline at end of file diff --git a/webgoat-container/src/main/resources/static/js/quiz.js b/webgoat-container/src/main/resources/static/js/quiz.js index 69a257c7f..01551504b 100644 --- a/webgoat-container/src/main/resources/static/js/quiz.js +++ b/webgoat-container/src/main/resources/static/js/quiz.js @@ -26,7 +26,7 @@ $(function () { html += "
"; jQuery.each(quest.solutions, function(k, solution) { solution = "Solution " + k + ": " + solution; - html += '
'; + html += '
'; }); html += "
"; }); @@ -35,4 +35,25 @@ $(function () { } } client.send(); -}); \ No newline at end of file +}); + +$(document).ready( () => { + $("#q_container").closest(".attack-container").addClass("quiz"); + $("#q_container").closest("form").on("submit", function(e) { + setTimeout(getFeedback, 200, this); + }); // end listener +}); // end ready + +function getFeedback(context) { + $.ajax({ + url: $(context).attr("action") + }).done( (result) => { + if (!result) return; + for(let i=0; icorrect):
"; correctAnswers++; + guesses[i] = true; } else { // answer incorrect - feedbackMessage += "Question " + (i + 1) + " ():
"; + guesses[i] = false; } } if(correctAnswers == solutions.length) { return trackProgress(success().build()); } else { - return trackProgress(failed().output(feedbackMessage).build()); + return trackProgress(failed().build()); } } + @RequestMapping(method = RequestMethod.GET) + @ResponseBody + public boolean[] getResults() { + return this.guesses; + } + } diff --git a/webgoat-lessons/sql-injection/src/main/resources/html/SqlInjectionAdvanced.html b/webgoat-lessons/sql-injection/src/main/resources/html/SqlInjectionAdvanced.html index 4d6d4a10a..896dcf48f 100644 --- a/webgoat-lessons/sql-injection/src/main/resources/html/SqlInjectionAdvanced.html +++ b/webgoat-lessons/sql-injection/src/main/resources/html/SqlInjectionAdvanced.html @@ -2,7 +2,6 @@ -
@@ -164,6 +163,7 @@
+