Skip to content

Commit b68f849

Browse files
committed
Add client-side for challenge push notifications
(resolves juice-shop#206)
1 parent ef00fc2 commit b68f849

File tree

6 files changed

+37
-1
lines changed

6 files changed

+37
-1
lines changed

app/i18n/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,5 +80,6 @@
8080
"LABEL_STATUS":"Status",
8181
"STATUS_UNSOLVED":"unsolved",
8282
"STATUS_SOLVED":"solved",
83-
"CALL_FOR_CONTRIBUTIONS":"Got an idea for a new challenge? Found a vulnerability that is not tracked here? Let us know via {{gitter}} community chat or by opening a {{github}} issue!"
83+
"CALL_FOR_CONTRIBUTIONS":"Got an idea for a new challenge? Found a vulnerability that is not tracked here? Let us know via {{gitter}} community chat or by opening a {{github}} issue!",
84+
"CHALLENGE_SOLVED": "You successfully solved a challenge: {{challenge}}"
8485
}

app/index.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
<script src="bower_components/angular-cookies/angular-cookies.min.js"></script>
4444
<script src="bower_components/angular-touch/angular-touch.min.js"></script>
4545
<script src="bower_components/angular-animate/angular-animate.min.js"></script>
46+
<script src="bower_components/angular-bootstrap/ui-bootstrap.min.js"></script>
4647
<script src="bower_components/angular-bootstrap/ui-bootstrap-tpls.min.js"></script>
4748
<script src="bower_components/ng-file-upload/ng-file-upload-shim.min.js"></script> <!-- for no html5 browsers support -->
4849
<script src="bower_components/ng-file-upload/ng-file-upload.min.js"></script>
@@ -121,6 +122,10 @@
121122

122123
<h1 class="hidden">OWASP Juice Shop</h1><!-- for SEO -->
123124

125+
<div class="container" ng-controller="ChallengeSolvedNotificationController">
126+
<div uib-alert ng-repeat="notification in notifications" ng-class="'alert alert-success'" close="closeNotification($index)" dismiss-on-timeout="10000">{{notification.message}}</div>
127+
</div>
128+
124129
<!-- CONTENT -->
125130
<div class="container-fluid" ng-view></div>
126131

app/js/app.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ angular.module('juiceShop').factory('authInterceptor', ['$rootScope', '$q', '$co
2525
}
2626
}])
2727

28+
angular.module('juiceShop').factory('socket', ['socketFactory', function (socketFactory) {
29+
return socketFactory()
30+
}])
31+
2832
angular.module('juiceShop').config(['$httpProvider', function ($httpProvider) {
2933
'use strict'
3034
$httpProvider.interceptors.push('authInterceptor')
@@ -46,3 +50,4 @@ angular.module('juiceShop').config(['$translateProvider', function ($translatePr
4650
$translateProvider.determinePreferredLanguage()
4751
$translateProvider.fallbackLanguage('en')
4852
}])
53+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
angular.module('juiceShop').controller('ChallengeSolvedNotificationController', [
2+
'$scope',
3+
'$translate',
4+
'socket',
5+
function ($scope, $translate, socket) {
6+
'use strict'
7+
8+
$scope.notifications = []
9+
10+
$scope.closeNotification = function (index) {
11+
$scope.notifications.splice(index, 1)
12+
}
13+
14+
socket.on('challenge solved', function (data) {
15+
if (data && data.challenge) {
16+
$translate('CHALLENGE_SOLVED', { challenge: data.challenge.description }).then(function (challengeSolved) {
17+
$scope.notifications.push({message: challengeSolved})
18+
}, function (translationId) {
19+
$scope.notifications.push({message: translationId})
20+
})
21+
}
22+
})
23+
} ])

karma.conf-ci.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ module.exports = function (config) {
5454
'app/bower_components/angular-touch/angular-touch.js',
5555
'app/bower_components/angular-animate/angular-animate.js',
5656
'app/bower_components/angular-bootstrap/ui-bootstrap.js',
57+
'app/bower_components/angular-bootstrap/ui-bootstrap-tpls.js',
5758
'app/bower_components/underscore/underscore.js',
5859
'app/bower_components/jquery/dist/jquery.js',
5960
'app/bower_components/ng-file-upload/ng-file-upload.js',

karma.conf.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ module.exports = function (config) {
1515
'app/bower_components/angular-touch/angular-touch.js',
1616
'app/bower_components/angular-animate/angular-animate.js',
1717
'app/bower_components/angular-bootstrap/ui-bootstrap.js',
18+
'app/bower_components/angular-bootstrap/ui-bootstrap-tpls.js',
1819
'app/bower_components/underscore/underscore.js',
1920
'app/bower_components/jquery/dist/jquery.js',
2021
'app/bower_components/ng-file-upload/ng-file-upload.js',

0 commit comments

Comments
 (0)