Skip to content

Commit f9d14c9

Browse files
committed
Added service for fetching the title of a lesson
1 parent ac46ddd commit f9d14c9

File tree

6 files changed

+53
-16
lines changed

6 files changed

+53
-16
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@
1212
/.settings/org.eclipse.wst.jsdt.ui.superType.container
1313
/.settings/org.eclipse.wst.jsdt.ui.superType.name
1414
/.settings/org.eclipse.wst.validation.prefs
15+
/.externalToolBuilders/
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package org.owasp.webgoat.service;
2+
3+
import javax.servlet.http.HttpSession;
4+
5+
import org.owasp.webgoat.lessons.AbstractLesson;
6+
import org.owasp.webgoat.session.Course;
7+
import org.owasp.webgoat.session.WebSession;
8+
import org.springframework.stereotype.Controller;
9+
import org.springframework.web.bind.annotation.RequestMapping;
10+
import org.springframework.web.bind.annotation.ResponseBody;
11+
12+
@Controller
13+
public class LessonTitleService extends BaseService {
14+
15+
/**
16+
* Returns the title for the current attack
17+
*
18+
* @param session
19+
* @return
20+
*/
21+
@RequestMapping(value = "/lessontitle.mvc", produces = "application/html")
22+
public @ResponseBody
23+
String showPlan(HttpSession session) {
24+
WebSession ws = getWebSession(session);
25+
return getLessonTitle(ws);
26+
}
27+
28+
private String getLessonTitle(WebSession s) {
29+
String title = "";
30+
int scr = s.getCurrentScreen();
31+
Course course = s.getCourse();
32+
33+
if (s.isUser() || s.isChallenge()) {
34+
AbstractLesson lesson = course.getLesson(s, scr, AbstractLesson.USER_ROLE);
35+
title = lesson != null ? lesson.getTitle() : "";
36+
}
37+
return title;
38+
}
39+
40+
}

src/main/webapp/js/goatConstants.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ var goatConstants = {
1919
solutionService:'service/solution.mvc',
2020
lessonPlanService:'service/lessonplan.mvc',
2121
menuService: 'service/lessonmenu.mvc',
22+
lessonTitleService: 'service/lessontitle.mvc',
2223
// literals
2324
notFound: 'Could not find',
2425
noHints: 'There are no hints defined.'

src/main/webapp/js/goatControllers.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,20 @@ goat.controller('goatLesson', function($scope, $http, $modal, $log, $templateCac
2727
$scope.hintIndex = 0;
2828

2929
var curScope = $scope;
30-
31-
30+
3231
curScope.parameters = goat.utils.scrapeParams(url);
3332
goat.data.loadLessonContent(url).then(
3433
function(reply) {
3534
$("#lesson_content").html(reply);
35+
goat.data.loadLessonTitle().then(
36+
function(reply) {
37+
$("#lessonTitle").text(reply);
38+
}
39+
);
40+
3641
//hook forms
3742
goat.utils.makeFormsAjax();
3843
$('#hintsView').hide();
39-
//render lesson title
40-
$('#lessonTitle').text(goat.utils.extractLessonTitle($(reply)));
41-
//@KLUGE to remove h1 after extracting and moving it to top
42-
$('#lesson_content h1').remove()
4344
// adjust menu to lessonContent size if necssary
4445
//@TODO: this is still clunky ... needs some TLC
4546
if ($('div.panel-body').height() > 400) {

src/main/webapp/js/goatData.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ goat.data = {
1818
return $.get(goatConstants.sourceService, {});
1919
},
2020
loadSolution: function () {
21-
return $.get(goatConstants.solutionService, {})
21+
return $.get(goatConstants.solutionService, {});
2222
},
2323
loadPlan: function () {
2424
return $.get(goatConstants.lessonPlanService, {});
@@ -30,5 +30,8 @@ goat.data = {
3030
loadMenuData: function() {
3131
//TODO use goatConstants var for url
3232
return $http({method: 'GET', url: goatConstants.menuService});
33+
},
34+
loadLessonTitle: function () {
35+
return $.get(goatConstants.lessonTitleService, {});
3336
}
3437
};

src/main/webapp/js/goatUtil.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,6 @@ goat.utils = {
1515
//console.log("Hooking any lesson forms to make them ajax");
1616
$("form").ajaxForm(options);
1717
},
18-
/**goatApp.extractLessonTitle
19-
*pulls lesson title from html fragment returned (looks for it in h1 element)
20-
*@param - html rendered to object passed in
21-
*/
22-
extractLessonTitle: function(el) {
23-
var title = $('h1', el).text();
24-
// remove title
25-
return title;
26-
},
2718
displayButton: function(id,show) {
2819
if ($('#'+id)) {
2920
if (show) {

0 commit comments

Comments
 (0)