From 0cb4faf15f93454d8a4baf4ba16c7a7a49bd453b Mon Sep 17 00:00:00 2001 From: Jason White Date: Tue, 18 Jul 2017 17:39:58 -0400 Subject: [PATCH] refactor to support cleaner scoping && success and failure callbacks --- .../js/goatApp/view/LessonContentView.js | 18 +++++++++---- .../src/main/resources/html/AuthBypass.html | 25 +++++++++++++++++-- .../src/main/resources/js/bypass.js | 5 ++-- .../xxe/src/main/resources/html/XXE.html | 6 ++--- 4 files changed, 42 insertions(+), 12 deletions(-) diff --git a/webgoat-container/src/main/resources/static/js/goatApp/view/LessonContentView.js b/webgoat-container/src/main/resources/static/js/goatApp/view/LessonContentView.js index fbc2abf94..0ef51ad2d 100644 --- a/webgoat-container/src/main/resources/static/js/goatApp/view/LessonContentView.js +++ b/webgoat-container/src/main/resources/static/js/goatApp/view/LessonContentView.js @@ -91,6 +91,7 @@ define(['jquery', this.curForm = curForm; this.$curFeedback = $(curForm).closest('.attack-container').find('.attack-feedback'); this.$curOutput = $(curForm).closest('.attack-container').find('.attack-output'); + var formUrl = $(curForm).attr('action'); var formMethod = $(curForm).attr('method'); var contentType = ($(curForm).attr('contentType')) ? $(curForm).attr('contentType') : 'application/x-www-form-urlencoded; charset=UTF-8'; @@ -100,9 +101,9 @@ define(['jquery', method:formMethod, contentType:contentType, data: submitData, - complete: function (data) { - callbackFunction(); - } + //complete: function (data) { + //callbackFunction(data); + //} }).then(self.onSuccessResponse.bind(self), self.onErrorResponse.bind(self)); return false; }, @@ -110,13 +111,20 @@ define(['jquery', onSuccessResponse: function(data) { this.renderFeedback(data.feedback); this.renderOutput(data.output || ""); + + var successCallBackFunctionName = this.$form.attr('successCallback'); + var failureCallbackFunctionName = this.$form.attr('failureCallback'); + //var submitData = (typeof webgoat.customjs[prepareDataFunctionName] === 'function') ? webgoat.customjs[prepareDataFunctionName]() : $(curForm).serialize(); + successCallbackFunction = (typeof webgoat.customjs[successCallBackFunctionName] === 'function') ? webgoat.customjs[successCallBackFunctionName] : function() {}; + failureCallbackFunction = (typeof webgoat.customjs[failureCallbackFunctionName] === 'function') ? webgoat.customjs[failureCallbackFunctionName] : function() {}; //TODO: refactor back assignmentCompleted in Java if (data.lessonCompleted || data.assignmentCompleted) { - this.markAssignmentComplete(); + successCallbackFunction(data); //data is likely not useful, except maybe the output ... this.trigger('assignment:complete'); } else { - this.markAssignmentIncomplete(); + this.markAssignmentIncomplete(data); //again, data might be useful, especially the output + failureCallbackFunction(); } return false; }, diff --git a/webgoat-lessons/auth-bypass/src/main/resources/html/AuthBypass.html b/webgoat-lessons/auth-bypass/src/main/resources/html/AuthBypass.html index e5d8f7f93..88a7c908b 100644 --- a/webgoat-lessons/auth-bypass/src/main/resources/html/AuthBypass.html +++ b/webgoat-lessons/auth-bypass/src/main/resources/html/AuthBypass.html @@ -20,9 +20,9 @@