Added service for fetching the title of a lesson
This commit is contained in:
parent
ac46ddd4d9
commit
f9d14c9b79
1
.gitignore
vendored
1
.gitignore
vendored
@ -12,3 +12,4 @@
|
|||||||
/.settings/org.eclipse.wst.jsdt.ui.superType.container
|
/.settings/org.eclipse.wst.jsdt.ui.superType.container
|
||||||
/.settings/org.eclipse.wst.jsdt.ui.superType.name
|
/.settings/org.eclipse.wst.jsdt.ui.superType.name
|
||||||
/.settings/org.eclipse.wst.validation.prefs
|
/.settings/org.eclipse.wst.validation.prefs
|
||||||
|
/.externalToolBuilders/
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -19,6 +19,7 @@ var goatConstants = {
|
|||||||
solutionService:'service/solution.mvc',
|
solutionService:'service/solution.mvc',
|
||||||
lessonPlanService:'service/lessonplan.mvc',
|
lessonPlanService:'service/lessonplan.mvc',
|
||||||
menuService: 'service/lessonmenu.mvc',
|
menuService: 'service/lessonmenu.mvc',
|
||||||
|
lessonTitleService: 'service/lessontitle.mvc',
|
||||||
// literals
|
// literals
|
||||||
notFound: 'Could not find',
|
notFound: 'Could not find',
|
||||||
noHints: 'There are no hints defined.'
|
noHints: 'There are no hints defined.'
|
||||||
|
@ -28,18 +28,19 @@ goat.controller('goatLesson', function($scope, $http, $modal, $log, $templateCac
|
|||||||
|
|
||||||
var curScope = $scope;
|
var curScope = $scope;
|
||||||
|
|
||||||
|
|
||||||
curScope.parameters = goat.utils.scrapeParams(url);
|
curScope.parameters = goat.utils.scrapeParams(url);
|
||||||
goat.data.loadLessonContent(url).then(
|
goat.data.loadLessonContent(url).then(
|
||||||
function(reply) {
|
function(reply) {
|
||||||
$("#lesson_content").html(reply);
|
$("#lesson_content").html(reply);
|
||||||
|
goat.data.loadLessonTitle().then(
|
||||||
|
function(reply) {
|
||||||
|
$("#lessonTitle").text(reply);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
//hook forms
|
//hook forms
|
||||||
goat.utils.makeFormsAjax();
|
goat.utils.makeFormsAjax();
|
||||||
$('#hintsView').hide();
|
$('#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
|
// adjust menu to lessonContent size if necssary
|
||||||
//@TODO: this is still clunky ... needs some TLC
|
//@TODO: this is still clunky ... needs some TLC
|
||||||
if ($('div.panel-body').height() > 400) {
|
if ($('div.panel-body').height() > 400) {
|
||||||
|
@ -18,7 +18,7 @@ goat.data = {
|
|||||||
return $.get(goatConstants.sourceService, {});
|
return $.get(goatConstants.sourceService, {});
|
||||||
},
|
},
|
||||||
loadSolution: function () {
|
loadSolution: function () {
|
||||||
return $.get(goatConstants.solutionService, {})
|
return $.get(goatConstants.solutionService, {});
|
||||||
},
|
},
|
||||||
loadPlan: function () {
|
loadPlan: function () {
|
||||||
return $.get(goatConstants.lessonPlanService, {});
|
return $.get(goatConstants.lessonPlanService, {});
|
||||||
@ -30,5 +30,8 @@ goat.data = {
|
|||||||
loadMenuData: function() {
|
loadMenuData: function() {
|
||||||
//TODO use goatConstants var for url
|
//TODO use goatConstants var for url
|
||||||
return $http({method: 'GET', url: goatConstants.menuService});
|
return $http({method: 'GET', url: goatConstants.menuService});
|
||||||
|
},
|
||||||
|
loadLessonTitle: function () {
|
||||||
|
return $.get(goatConstants.lessonTitleService, {});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -15,15 +15,6 @@ goat.utils = {
|
|||||||
//console.log("Hooking any lesson forms to make them ajax");
|
//console.log("Hooking any lesson forms to make them ajax");
|
||||||
$("form").ajaxForm(options);
|
$("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) {
|
displayButton: function(id,show) {
|
||||||
if ($('#'+id)) {
|
if ($('#'+id)) {
|
||||||
if (show) {
|
if (show) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user