From 2a9ff8e1e3ac293b6da4566785236183b0fba6e0 Mon Sep 17 00:00:00 2001 From: Nanne Baars Date: Sat, 9 Nov 2019 13:19:45 +0100 Subject: [PATCH] Add button to menu to reset lesson database (through reset lesson it was a bit implicit, adding a button makes it more clear. Resetting a lesson will still clean the lesson database as well --- .../webgoat/service/RestartLessonService.java | 8 ++++++++ .../src/main/resources/i18n/messages.properties | 1 + .../static/js/goatApp/view/GoatRouter.js | 10 +++++++++- .../src/main/resources/templates/main_new.html | 15 ++++++++------- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/service/RestartLessonService.java b/webgoat-container/src/main/java/org/owasp/webgoat/service/RestartLessonService.java index 4c17cbe0ac..73624dfda4 100644 --- a/webgoat-container/src/main/java/org/owasp/webgoat/service/RestartLessonService.java +++ b/webgoat-container/src/main/java/org/owasp/webgoat/service/RestartLessonService.java @@ -33,6 +33,7 @@ import org.owasp.webgoat.users.UserTrackerRepository; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseStatus; @@ -58,4 +59,11 @@ public void restartLesson() { flywayLessons.clean(); flywayLessons.migrate(); } + + @PostMapping("/service/resetLessonDatabase.mvc") + @ResponseStatus(value = HttpStatus.OK) + public void resetLessonDatabase() { + flywayLessons.clean(); + flywayLessons.migrate(); + } } diff --git a/webgoat-container/src/main/resources/i18n/messages.properties b/webgoat-container/src/main/resources/i18n/messages.properties index d58990c3e8..9640d0bc85 100644 --- a/webgoat-container/src/main/resources/i18n/messages.properties +++ b/webgoat-container/src/main/resources/i18n/messages.properties @@ -54,6 +54,7 @@ sign.in=Sign in register.new=Register new user sign.up=Sign up register.title=Register +database.reset=Reset lesson database not.empty=This field is required. diff --git a/webgoat-container/src/main/resources/static/js/goatApp/view/GoatRouter.js b/webgoat-container/src/main/resources/static/js/goatApp/view/GoatRouter.js index 84a23334fb..0e684bb328 100644 --- a/webgoat-container/src/main/resources/static/js/goatApp/view/GoatRouter.js +++ b/webgoat-container/src/main/resources/static/js/goatApp/view/GoatRouter.js @@ -43,7 +43,8 @@ define(['jquery', 'lesson/:name': 'lessonRoute', 'lesson/:name/:pageNum': 'lessonPageRoute', 'test/:param': 'testRoute', - 'reportCard': 'reportCard' + 'reportCard': 'reportCard', + 'resetLessonDatabase': 'resetLessonDatabase' }, lessonController: null, @@ -121,6 +122,13 @@ define(['jquery', render(new ReportCardView()); }); }, + + resetLessonDatabase: function() { + $.ajax({ + url:'service/resetLessonDatabase.mvc', + method:'POST' + }); + }, }); return GoatAppRouter; diff --git a/webgoat-container/src/main/resources/templates/main_new.html b/webgoat-container/src/main/resources/templates/main_new.html index edde993ab1..668d5718ba 100644 --- a/webgoat-container/src/main/resources/templates/main_new.html +++ b/webgoat-container/src/main/resources/templates/main_new.html @@ -84,20 +84,21 @@ +
+ + + +
- - - - - - -