Skip to content

Commit 4ff73d0

Browse files
author
Jason White
committed
restart Lesson button implemented and attack link modification for CSRF lesson
1 parent e8a273e commit 4ff73d0

File tree

5 files changed

+34
-3
lines changed

5 files changed

+34
-3
lines changed

src/main/webapp/WEB-INF/pages/main_new.jsp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@
139139
<button type="button" id="showSolutionBtn" class="btn btn-primary btn-xs" ng-click="showLessonSolution()">Solution</button>
140140
<button type="button" id="showPlanBtn" class="btn btn-primary btn-xs" ng-click="showLessonPlan()">Lesson Plan</button>
141141
<button type="button" id="showHintsBtn" class="btn btn-primary btn-xs" ng-click="viewHints()">Hints</button>
142+
<button type="button" id="restartLessonBtn" class="btn btn-xs" ng-click="restartLesson()">Restart Lesson</button>
142143
</div>
143144
</div>
144145
<div class="lessonHelp" id="lesson_hint_row">
@@ -351,6 +352,7 @@
351352
// make any embedded forms ajaxy
352353
goat.utils.showLessonCookiesAndParams();
353354
goat.utils.makeFormsAjax();
355+
goat.utils.ajaxifyAttackHref(); //TODO find some way to hook scope for current menu. Likely needs larger refactor which is already started/stashed
354356
//refresh menu
355357
angular.element($('#leftside-navigation')).scope().renderMenu();
356358
}

src/main/webapp/js/goatConstants.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ var goatConstants = {
2323
lessonPlanService:'service/lessonplan.mvc',
2424
menuService: 'service/lessonmenu.mvc',
2525
lessonTitleService: 'service/lessontitle.mvc',
26+
restartLessonService: 'service/restartlesson.mvc',
2627
// literals
2728
notFound: 'Could not find',
2829
noHints: 'There are no hints defined.'

src/main/webapp/js/goatControllers.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ var goatMenu = function($scope, $http, $modal, $log, $templateCache) {
8585
//TODO encode html or get angular js portion working
8686
$("#lesson_content").html(reply.data);
8787
//hook forms
88-
goat.utils.makeFormsAjax();
88+
goat.utils.makeFormsAjax();// inject form?
89+
goat.utils.ajaxifyAttackHref();
8990
$('#leftside-navigation').height($('#main-content').height()+15)//TODO: get ride of fixed value (15)here
9091
//notifies goatLesson Controller of the less change
9192
$scope.$emit('lessonUpdate',{params:curScope.parameters});
@@ -234,6 +235,14 @@ var goatLesson = function($scope,$http,$log) {
234235
$scope.hideHints = function() {
235236

236237
};
238+
239+
$scope.restartLesson = function () {
240+
goat.data.loadRestart($http).then(
241+
function(resp) {
242+
angular.element($('#leftside-navigation')).scope().renderLesson(null,resp.data);
243+
}
244+
)
245+
}
237246

238247
$scope.showAbout = function() {
239248
$('#aboutModal').modal({

src/main/webapp/js/goatData.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,9 @@ goat.data = {
3636
},
3737
loadLessonTitle: function ($http) {
3838
return $http({method: 'GET', url: goatConstants.lessonTitleService});
39+
},
40+
loadRestart: function ($http) {
41+
return $http({method: 'GET', url:goatConstants.restartLessonService})
3942
}
43+
4044
};

src/main/webapp/js/goatUtil.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,23 @@ goat.utils = {
9191
makeId: function (lessonName) {
9292
return lessonName.replace(/\s|\(|\)|\!|\:|\;|\@|\#|\$|\%|\^|\&|\*/g,'');//TODO move the replace routine into util function
9393
},
94-
ajaxifyAttackHREF: function () {
95-
// stub for dealing with CSRF lesson link issues and other similar issues
94+
ajaxifyAttackHref: function () {
95+
$.each($('a[href^="attack?"]'),
96+
function(i,el) {
97+
var url = $(el).attr('href');
98+
$(el).attr('href','#');
99+
$(el).attr('link',url);
100+
//TODO pull currentMenuId
101+
$(el).click(
102+
function() {
103+
var _url = $(el).attr('link');
104+
$.get(_url, {success:showResponse});
105+
//return $.get(_url, {}, null, "html");
106+
//angular.element($('#leftside-navigation')).scope().renderLesson(curMenuItem,url);
107+
}
108+
)
109+
}
110+
);
96111
}
97112
};
98113

0 commit comments

Comments
 (0)