From f3092a2344492aacd6fbb5a4ea58ea6ca3d8857a Mon Sep 17 00:00:00 2001 From: lawson89 <> Date: Mon, 18 Aug 2014 13:18:42 -0400 Subject: [PATCH] render lesson content using jquery --- java/org/owasp/webgoat/session/Screen.java | 2 + .../org/owasp/webgoat/session/WebSession.java | 2 +- webapp/WEB-INF/pages/main_new.jsp | 10 ++-- webapp/js/goat.js | 49 ++++++++++++------- webapp/lessons/GoatHillsFinancial/error.jsp | 2 +- 5 files changed, 41 insertions(+), 24 deletions(-) diff --git a/java/org/owasp/webgoat/session/Screen.java b/java/org/owasp/webgoat/session/Screen.java index 58d9a91c2..fa81c82bd 100644 --- a/java/org/owasp/webgoat/session/Screen.java +++ b/java/org/owasp/webgoat/session/Screen.java @@ -205,6 +205,8 @@ public abstract class Screen { // TODO we could hook all forms here with javascript call to ajax forms plugin public String getContent() { String makeFormsAjax = ""; + // handle this on the page with js + makeFormsAjax = ""; return (content == null) ? "" : content.toString() + makeFormsAjax; } diff --git a/java/org/owasp/webgoat/session/WebSession.java b/java/org/owasp/webgoat/session/WebSession.java index 2cd5e7a91..e5729c252 100644 --- a/java/org/owasp/webgoat/session/WebSession.java +++ b/java/org/owasp/webgoat/session/WebSession.java @@ -129,7 +129,7 @@ public class WebSession { /** * Description of the Field */ - public final static String SESSION = "Session"; + public final static String SESSION = "websession"; public final static String SHOWSOURCE = "ShowSource"; diff --git a/webapp/WEB-INF/pages/main_new.jsp b/webapp/WEB-INF/pages/main_new.jsp index d899ac5d4..c7a72ef4a 100644 --- a/webapp/WEB-INF/pages/main_new.jsp +++ b/webapp/WEB-INF/pages/main_new.jsp @@ -2,7 +2,7 @@ errorPage=""%> <%@page import="org.owasp.webgoat.session.WebSession"%> <% - WebSession webSession = ((WebSession) session.getAttribute("websession")); + WebSession webSession = ((WebSession) session.getAttribute(WebSession.SESSION)); %> @@ -84,9 +84,9 @@
-
-
- +
+
+

{{lessonUrl}}

About WebGoat


Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque volutpat feugiat nunc, non vulputate urna dictum ut. Nam consectetur porttitor diam ut ultricies. Aenean dolor dolor, congue sed ornare non, elementum in mauris. Phasellus orci sem, rhoncus eu laoreet eu, aliquam nec ante. Suspendisse sit amet justo eget eros tempor tincidunt vel quis justo. Sed pulvinar enim id neque pellentesque, eu rhoncus lorem eleifend. Morbi congue tortor sit amet pulvinar posuere.

@@ -184,8 +184,10 @@ alert('status: ' + statusText + '\n\nresponseText: \n' + responseText + '\n\nThe output div should have already been updated with the responseText.'); } + makeFormsAjax(); } function makeFormsAjax() { + //console.log("Hooking any lesson forms to make them ajax"); $("form").ajaxForm(options); } diff --git a/webapp/js/goat.js b/webapp/js/goat.js index 1336734a0..db7d45a59 100644 --- a/webapp/js/goat.js +++ b/webapp/js/goat.js @@ -7,34 +7,47 @@ * prepares and updates menu topic items for the view */ goat.controller('goatMenu', function($scope, $http) { - //TODO: implment via separate promise and use config for menu + //TODO: implement via separate promise and use config for menu $http({method: 'GET', url: 'service/lessonmenu.mvc'}).then( function(menuData) { var menuItems = goat.addMenuClasses(goatConstants.menuPrefix.concat(menuData.data)); $scope.menuTopics = menuItems; - }, function(error) { - var foo = error; - } + }, + function(error) { + // TODO - handle this some way other than an alert + alert("Error rendering menu: " + error); + } ); + $scope.lessonUrl = "hi!"; $scope.renderLesson = function(url) { console.log(url + ' was passed in'); + // use jquery to render lesson content to div + jQuery.get(url, + {}, + function(reply) { + jQuery("#lesson_content").html(reply); + // hook any forms + makeFormsAjax(); + }, + "html"); }; }) -.animation('.slideDown', function() { - var NgHideClassName = 'ng-hide'; - return { - beforeAddClass: function(element, className, done) { - if(className === NgHideClassName) { - jQuery(element).slideUp(done); + .animation('.slideDown', function() { + var NgHideClassName = 'ng-hide'; + return { + beforeAddClass: function(element, className, done) { + if (className === NgHideClassName) { + jQuery(element).slideUp(done); } - }, - removeClass: function(element, className, done) { - if(className === NgHideClassName) { - jQuery(element).hide().slideDown(done); + }, + removeClass: function(element, className, done) { + if (className === NgHideClassName) { + jQuery(element).hide().slideDown(done); } + } } - } -}); + }); + //TODO add recursion to handle arr[i].children objects // ... in case lower-level's need classes as well ... don't right now @@ -42,8 +55,8 @@ goat.addMenuClasses = function(arr) { for (var i = 0; i < arr.length; i++) { var menuItem = arr[i]; //console.log(menuItem); - if (arr[i].type && arr[i].type === 'CATEGORY') { - arr[i].class = 'fa-angle-right pull-right'; + if (menuItem.type && menuItem.type === 'CATEGORY') { + menuItem.class = 'fa-angle-right pull-right'; } } return arr; diff --git a/webapp/lessons/GoatHillsFinancial/error.jsp b/webapp/lessons/GoatHillsFinancial/error.jsp index a3294f134..fdffa05ab 100644 --- a/webapp/lessons/GoatHillsFinancial/error.jsp +++ b/webapp/lessons/GoatHillsFinancial/error.jsp @@ -2,7 +2,7 @@ import="org.owasp.webgoat.session.*, org.owasp.webgoat.lessons.GoatHillsFinancial.GoatHillsFinancial" errorPage="" %> <% - WebSession webSession = ((WebSession)session.getAttribute("websession")); + WebSession webSession = ((WebSession)session.getAttribute(WebSession.SESSION)); // int myUserId = getIntSessionAttribute(webSession, "GoatHillsFinancial." + GoatHillsFinancial.USER_ID); %>


An error has occurred.