diff --git a/src/main/java/org/owasp/webgoat/service/SolutionService.java b/src/main/java/org/owasp/webgoat/service/SolutionService.java index 53a72baa0..ac0fda234 100644 --- a/src/main/java/org/owasp/webgoat/service/SolutionService.java +++ b/src/main/java/org/owasp/webgoat/service/SolutionService.java @@ -31,10 +31,7 @@ package org.owasp.webgoat.service; import javax.servlet.http.HttpSession; -import static org.owasp.webgoat.LessonSource.END_SOURCE_SKIP; -import static org.owasp.webgoat.LessonSource.START_SOURCE_SKIP; import org.owasp.webgoat.lessons.AbstractLesson; -import org.owasp.webgoat.lessons.model.SourceListing; import org.owasp.webgoat.session.Course; import org.owasp.webgoat.session.WebSession; import org.springframework.stereotype.Controller; diff --git a/src/main/webapp/WEB-INF/pages/main_new.jsp b/src/main/webapp/WEB-INF/pages/main_new.jsp index 98da7e0c2..55b93ce73 100644 --- a/src/main/webapp/WEB-INF/pages/main_new.jsp +++ b/src/main/webapp/WEB-INF/pages/main_new.jsp @@ -76,7 +76,7 @@ - + @@ -114,20 +114,7 @@ - - - + @@ -135,13 +122,7 @@ - - - - - - + + + diff --git a/src/main/webapp/js/goatControllers.js b/src/main/webapp/js/goatControllers.js index c6bacc381..6bdf03860 100644 --- a/src/main/webapp/js/goatControllers.js +++ b/src/main/webapp/js/goatControllers.js @@ -6,7 +6,7 @@ /** Menu Controller * prepares and updates menu topic items for the view */ -goat.controller('goatLesson', function($scope, $http, $modal, $log) { +goat.controller('goatLesson', function($scope, $http, $modal, $log, $templateCache) { //TODO: implement via separate promise and use config for menu (goat.data.loadMenuData()) $http({method: 'GET', url: goatConstants.lessonService}).then( function(menuData) { @@ -33,15 +33,6 @@ goat.controller('goatLesson', function($scope, $http, $modal, $log) { } } ); - /* - console.log("Updating Lesson Source..."); - $http.get('service/source.mvc').success(function(data) { - $scope.lessonSource = data.source; - }).error(function(data) { - $scope.lessonSource = data.message; - console.log("LessonSource = '" + data.message + "'"); - }); - */ }; //TODO: Move show Source into it's own angular controller /* @@ -56,10 +47,9 @@ goat.controller('goatLesson', function($scope, $http, $modal, $log) { }).error(function(data) { $scope.lessonSource = data.message; console.log("LessonSource = '" + data.message + "'"); - $scope.openSourceModal(size); - }) - - } + $scope.openSourceModal(size); + }); + }; $scope.openSourceModal = function(size) { var modalInstance = $modal.open({ @@ -75,7 +65,30 @@ goat.controller('goatLesson', function($scope, $http, $modal, $log) { modalInstance.result.then(function() { $log.info('Modal dismissed at: ' + new Date()); }); - } + }; + + /* + * Function to load lesson solution + * @returns {undefined} + */ + $scope.showSolution = function(size) { + $scope.lessonSolutionUrl = "service/solution.mvc"; + // clear the template cache otherwise we display stale lesson solutions + $templateCache.remove($scope.lessonSolutionUrl); + var modalInstance = $modal.open({ + templateUrl: 'showSolution.html', + controller: showSolutionController, + size: size, + resolve: { + lessonSolutionUrl: function() { + return $scope.lessonSolutionUrl; + } + } + }); + modalInstance.result.then(function() { + $log.info('Modal dismissed at: ' + new Date()); + }); + }; }).animation('.slideDown', function() { var NgHideClassName = 'ng-hide'; @@ -90,7 +103,7 @@ goat.controller('goatLesson', function($scope, $http, $modal, $log) { $(element).hide().slideDown(done); } } - } + }; }); @@ -108,5 +121,19 @@ var showSourceController = function($scope, $modalInstance, lessonSource) { }; }; +var showSolutionController = function($scope, $modalInstance, lessonSolutionUrl) { + + $scope.lessonSolutionUrl = lessonSolutionUrl; + + $scope.ok = function() { + $modalInstance.close(); + }; + + $scope.cancel = function() { + $modalInstance.dismiss('cancel'); + }; +}; + +