refactor to support cleaner scoping && success and failure callbacks
This commit is contained in:
parent
ce7c271bb5
commit
0cb4faf15f
@ -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;
|
||||
},
|
||||
|
@ -20,9 +20,9 @@
|
||||
|
||||
<!-- modify the action to point to the intended endpoint and set other attributes as desired -->
|
||||
<script th:src="@{/lesson_js/bypass.js}" />
|
||||
<form class="attack-form" accept-charset="UNKNOWN"
|
||||
<form class="attack-form" accept-charset="UNKNOWN" id="verify-account-form"
|
||||
method="POST" name="form"
|
||||
callback="onBypassResponse"
|
||||
successCallback="onBypassResponse"
|
||||
action="/WebGoat/auth-bypass/verify-account"
|
||||
enctype="application/json;charset=UTF-8">
|
||||
<p>Verify Your Account by answering the questions below:</p>
|
||||
@ -40,6 +40,27 @@
|
||||
<input name="submit" value="Submit" type="submit"/>
|
||||
|
||||
</form>
|
||||
|
||||
<form class="attack-form" accept-charset="UNKNOWN" id="change-password-form"
|
||||
method="POST" name="form"
|
||||
successCallback="onBypassResponse"
|
||||
action="/WebGoat/auth-bypass/verify-account"
|
||||
enctype="application/json;charset=UTF-8"
|
||||
style="display:none"><!-- start off hidden -->
|
||||
<p>Please provide a new password for your account</p>
|
||||
|
||||
<p>Password:</p>
|
||||
<input name="newPassword" value="" type="password" /><br/>
|
||||
|
||||
<p>Confirm Password:</p>
|
||||
<input name="newPasswordConfirm" value="" type="password" /><br/><br />
|
||||
|
||||
<input type="hidden" name="userId" value="12309746" />
|
||||
|
||||
<input name="submit" value="Submit" type="submit"/>
|
||||
|
||||
</form>
|
||||
|
||||
<!-- do not remove the two following div's, this is where your feedback/output will land -->
|
||||
<!-- the attack response will include a 'feedback' and that will automatically go here -->
|
||||
<div class="attack-feedback"></div>
|
||||
|
@ -1,7 +1,8 @@
|
||||
// need custom js for this?
|
||||
|
||||
webgoat.customjs.onBypassResponse = function(e) {
|
||||
console.warn("showPasswordChange fired - "+ data)
|
||||
webgoat.customjs.onBypassResponse = function(data) {
|
||||
webgoat.customjs.jquery('#verify-account-form').hide();
|
||||
webgoat.customjs.jquery('#change-password-form').show();
|
||||
}
|
||||
|
||||
var onViewProfile = function () {
|
||||
|
@ -25,7 +25,7 @@
|
||||
<form class="attack-form" accept-charset="UNKNOWN"
|
||||
method="POST" name="form"
|
||||
prepareData="simpleXXE"
|
||||
callback="simpleXXECallback"
|
||||
successCallback="simpleXXECallback"
|
||||
contentType="application/xml"
|
||||
action="/WebGoat/xxe/simple">
|
||||
<div class="container-fluid">
|
||||
@ -81,7 +81,7 @@
|
||||
<form class="attack-form" accept-charset="UNKNOWN"
|
||||
method="POST" name="form"
|
||||
prepareData="contentTypeXXE"
|
||||
callback="contentTypeXXECallback"
|
||||
successCallback="contentTypeXXECallback"
|
||||
action="xxe/content-type"
|
||||
contentType="application/json">
|
||||
<div class="container-fluid">
|
||||
@ -146,7 +146,7 @@
|
||||
<form class="attack-form" accept-charset="UNKNOWN"
|
||||
method="POST" name="form"
|
||||
prepareData="blindXXE"
|
||||
callback="blindXXECallback"
|
||||
successCallback="blindXXECallback"
|
||||
action="/WebGoat/xxe/blind"
|
||||
contentType="application/xml">
|
||||
<div class="container-fluid">
|
||||
|
Loading…
x
Reference in New Issue
Block a user