Added service for fetching the title of a lesson

This commit is contained in:
nbaars 2014-09-09 18:18:45 +02:00
parent ac46ddd4d9
commit f9d14c9b79
6 changed files with 53 additions and 16 deletions

1
.gitignore vendored
View File

@ -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/

View File

@ -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;
}
}

View File

@ -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.'

View File

@ -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) {

View File

@ -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, {});
@ -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, {});
}
};

View File

@ -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) {