Skip to content

Commit 37aed7f

Browse files
show lesson solution
1 parent 5f378a7 commit 37aed7f

File tree

3 files changed

+60
-41
lines changed

3 files changed

+60
-41
lines changed

src/main/java/org/owasp/webgoat/service/SolutionService.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,7 @@
3131
package org.owasp.webgoat.service;
3232

3333
import javax.servlet.http.HttpSession;
34-
import static org.owasp.webgoat.LessonSource.END_SOURCE_SKIP;
35-
import static org.owasp.webgoat.LessonSource.START_SOURCE_SKIP;
3634
import org.owasp.webgoat.lessons.AbstractLesson;
37-
import org.owasp.webgoat.lessons.model.SourceListing;
3835
import org.owasp.webgoat.session.Course;
3936
import org.owasp.webgoat.session.WebSession;
4037
import org.springframework.stereotype.Controller;

src/main/webapp/WEB-INF/pages/main_new.jsp

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
<button type="button" class="btn btn-primary btn-sm">Hints</button>
7777
<button type="button" class="btn btn-primary btn-sm">Lesson Plan</button>
7878
<button type="button" class="btn btn-primary btn-sm" ng-click="showSource('lg')">Java [Source]</button>
79-
<button type="button" class="btn btn-primary btn-sm">Solution</button>
79+
<button type="button" class="btn btn-primary btn-sm" ng-click="showSolution('lg')">Solution</button>
8080
</div><!--toggle navigation end-->
8181
</header>
8282

@@ -114,34 +114,15 @@
114114

115115
</div>
116116
</div>
117-
</div>
118-
119-
<!--
120-
<div class="row">
121-
<div class="col-md-12">
122-
<h4>Lesson Source Code</h4>
123-
<div class="panel" >
124-
<div class="panel-body">
125-
<pre>{{lessonSource}}</pre>
126-
</div>
127-
</div>
128-
</div>
129-
</div>
130-
-->
117+
</div>
131118
</section>
132119
</section>
133120

134121
<!--main content end-->
135122

136123
</section>
137124

138-
<!-- <script src="plugins/waypoints/waypoints.min.js"></script> -->
139-
<!-- <script src="js/application.js"></script> -->
140-
141-
<!-- Bootstrap core JavaScript
142-
================================================== -->
143-
<!-- Placed at the end of the document so the pages load faster -->
144-
<!-- <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> -->
125+
<!-- TODO pull source into project instead of loading from external -->
145126
<script src="http://malsup.github.com/jquery.form.js"></script>
146127
<script>
147128
//Load global functions
@@ -231,6 +212,20 @@
231212
<button class="btn btn-primary" ng-click="ok()">Close</button>
232213
</div>
233214
</script>
215+
216+
<script type="text/ng-template" id="showSolution.html">
217+
<div class="modal-header">
218+
<button class="btn btn-primary pull-right" ng-click="ok()">Close</button>
219+
<h3 class="modal-title">Lesson Solution</h3>
220+
221+
</div>
222+
<div class="modal-body" ng-include="lessonSolutionUrl">
223+
224+
</div>
225+
<div class="modal-footer">
226+
<button class="btn btn-primary" ng-click="ok()">Close</button>
227+
</div>
228+
</script>
234229

235230

236231

src/main/webapp/js/goatControllers.js

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/** Menu Controller
77
* prepares and updates menu topic items for the view
88
*/
9-
goat.controller('goatLesson', function($scope, $http, $modal, $log) {
9+
goat.controller('goatLesson', function($scope, $http, $modal, $log, $templateCache) {
1010
//TODO: implement via separate promise and use config for menu (goat.data.loadMenuData())
1111
$http({method: 'GET', url: goatConstants.lessonService}).then(
1212
function(menuData) {
@@ -33,15 +33,6 @@ goat.controller('goatLesson', function($scope, $http, $modal, $log) {
3333
}
3434
}
3535
);
36-
/*
37-
console.log("Updating Lesson Source...");
38-
$http.get('service/source.mvc').success(function(data) {
39-
$scope.lessonSource = data.source;
40-
}).error(function(data) {
41-
$scope.lessonSource = data.message;
42-
console.log("LessonSource = '" + data.message + "'");
43-
});
44-
*/
4536
};
4637
//TODO: Move show Source into it's own angular controller
4738
/*
@@ -56,10 +47,9 @@ goat.controller('goatLesson', function($scope, $http, $modal, $log) {
5647
}).error(function(data) {
5748
$scope.lessonSource = data.message;
5849
console.log("LessonSource = '" + data.message + "'");
59-
$scope.openSourceModal(size);
60-
})
61-
62-
}
50+
$scope.openSourceModal(size);
51+
});
52+
};
6353

6454
$scope.openSourceModal = function(size) {
6555
var modalInstance = $modal.open({
@@ -75,7 +65,30 @@ goat.controller('goatLesson', function($scope, $http, $modal, $log) {
7565
modalInstance.result.then(function() {
7666
$log.info('Modal dismissed at: ' + new Date());
7767
});
78-
}
68+
};
69+
70+
/*
71+
* Function to load lesson solution
72+
* @returns {undefined}
73+
*/
74+
$scope.showSolution = function(size) {
75+
$scope.lessonSolutionUrl = "service/solution.mvc";
76+
// clear the template cache otherwise we display stale lesson solutions
77+
$templateCache.remove($scope.lessonSolutionUrl);
78+
var modalInstance = $modal.open({
79+
templateUrl: 'showSolution.html',
80+
controller: showSolutionController,
81+
size: size,
82+
resolve: {
83+
lessonSolutionUrl: function() {
84+
return $scope.lessonSolutionUrl;
85+
}
86+
}
87+
});
88+
modalInstance.result.then(function() {
89+
$log.info('Modal dismissed at: ' + new Date());
90+
});
91+
};
7992

8093
}).animation('.slideDown', function() {
8194
var NgHideClassName = 'ng-hide';
@@ -90,7 +103,7 @@ goat.controller('goatLesson', function($scope, $http, $modal, $log) {
90103
$(element).hide().slideDown(done);
91104
}
92105
}
93-
}
106+
};
94107
});
95108

96109

@@ -108,5 +121,19 @@ var showSourceController = function($scope, $modalInstance, lessonSource) {
108121
};
109122
};
110123

124+
var showSolutionController = function($scope, $modalInstance, lessonSolutionUrl) {
125+
126+
$scope.lessonSolutionUrl = lessonSolutionUrl;
127+
128+
$scope.ok = function() {
129+
$modalInstance.close();
130+
};
131+
132+
$scope.cancel = function() {
133+
$modalInstance.dismiss('cancel');
134+
};
135+
};
136+
137+
111138

112139

0 commit comments

Comments
 (0)