Skip to content

Commit

Permalink
Added service for fetching the title of a lesson
Browse files Browse the repository at this point in the history
  • Loading branch information
nbaars committed Sep 9, 2014
1 parent ac46ddd commit f9d14c9
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
/.settings/org.eclipse.wst.jsdt.ui.superType.container
/.settings/org.eclipse.wst.jsdt.ui.superType.name
/.settings/org.eclipse.wst.validation.prefs
/.externalToolBuilders/
40 changes: 40 additions & 0 deletions src/main/java/org/owasp/webgoat/service/LessonTitleService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package org.owasp.webgoat.service;

import javax.servlet.http.HttpSession;

import org.owasp.webgoat.lessons.AbstractLesson;
import org.owasp.webgoat.session.Course;
import org.owasp.webgoat.session.WebSession;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class LessonTitleService extends BaseService {

/**
* Returns the title for the current attack
*
* @param session
* @return
*/
@RequestMapping(value = "/lessontitle.mvc", produces = "application/html")
public @ResponseBody
String showPlan(HttpSession session) {
WebSession ws = getWebSession(session);
return getLessonTitle(ws);
}

private String getLessonTitle(WebSession s) {
String title = "";
int scr = s.getCurrentScreen();
Course course = s.getCourse();

if (s.isUser() || s.isChallenge()) {
AbstractLesson lesson = course.getLesson(s, scr, AbstractLesson.USER_ROLE);
title = lesson != null ? lesson.getTitle() : "";
}
return title;
}

}
1 change: 1 addition & 0 deletions src/main/webapp/js/goatConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var goatConstants = {
solutionService:'service/solution.mvc',
lessonPlanService:'service/lessonplan.mvc',
menuService: 'service/lessonmenu.mvc',
lessonTitleService: 'service/lessontitle.mvc',
// literals
notFound: 'Could not find',
noHints: 'There are no hints defined.'
Expand Down
13 changes: 7 additions & 6 deletions src/main/webapp/js/goatControllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,20 @@ goat.controller('goatLesson', function($scope, $http, $modal, $log, $templateCac
$scope.hintIndex = 0;

var curScope = $scope;



curScope.parameters = goat.utils.scrapeParams(url);
goat.data.loadLessonContent(url).then(
function(reply) {
$("#lesson_content").html(reply);
goat.data.loadLessonTitle().then(
function(reply) {
$("#lessonTitle").text(reply);
}
);

//hook forms
goat.utils.makeFormsAjax();
$('#hintsView').hide();
//render lesson title
$('#lessonTitle').text(goat.utils.extractLessonTitle($(reply)));
//@KLUGE to remove h1 after extracting and moving it to top
$('#lesson_content h1').remove()
// adjust menu to lessonContent size if necssary
//@TODO: this is still clunky ... needs some TLC
if ($('div.panel-body').height() > 400) {
Expand Down
5 changes: 4 additions & 1 deletion src/main/webapp/js/goatData.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ goat.data = {
return $.get(goatConstants.sourceService, {});
},
loadSolution: function () {
return $.get(goatConstants.solutionService, {})
return $.get(goatConstants.solutionService, {});
},
loadPlan: function () {
return $.get(goatConstants.lessonPlanService, {});
Expand All @@ -30,5 +30,8 @@ goat.data = {
loadMenuData: function() {
//TODO use goatConstants var for url
return $http({method: 'GET', url: goatConstants.menuService});
},
loadLessonTitle: function () {
return $.get(goatConstants.lessonTitleService, {});
}
};
9 changes: 0 additions & 9 deletions src/main/webapp/js/goatUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,6 @@ goat.utils = {
//console.log("Hooking any lesson forms to make them ajax");
$("form").ajaxForm(options);
},
/**goatApp.extractLessonTitle
*pulls lesson title from html fragment returned (looks for it in h1 element)
*@param - html rendered to object passed in
*/
extractLessonTitle: function(el) {
var title = $('h1', el).text();
// remove title
return title;
},
displayButton: function(id,show) {
if ($('#'+id)) {
if (show) {
Expand Down

0 comments on commit f9d14c9

Please sign in to comment.