Skip to content

Commit

Permalink
#430 Extract code from querystring even if it is before the #fragment…
Browse files Browse the repository at this point in the history
… in url
  • Loading branch information
To-om committed Jan 19, 2018
1 parent 11611a5 commit c1012c8
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 16 deletions.
1 change: 1 addition & 0 deletions ui/app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
<script src="bower_components/angular-drag-and-drop-lists/angular-drag-and-drop-lists.js"></script>
<script src="bower_components/angular-bootstrap-colorpicker/js/bootstrap-colorpicker-module.js"></script>
<script src="bower_components/file-saver/FileSaver.js"></script>
<script src="bower_components/js-url/url.js"></script>
<!-- endbower -->

<script type="text/javascript" src="bower_components/ace-builds/src-min-noconflict/ace.js"></script>
Expand Down
3 changes: 2 additions & 1 deletion ui/app/scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,4 +422,5 @@ angular.module('thehive', ['ngAnimate', 'ngMessages', 'ngSanitize', 'ui.bootstra
$rootScope.title = toState.title;
}
});
});
})
.constant('UrlParser', url);
6 changes: 3 additions & 3 deletions ui/app/scripts/controllers/AuthenticationCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
(function() {
'use strict';
angular.module('theHiveControllers')
.controller('AuthenticationCtrl', function($scope, $state, $location, $uibModalStack, $stateParams, AuthenticationSrv, NotificationSrv, appConfig) {
.controller('AuthenticationCtrl', function($scope, $state, $location, $uibModalStack, $stateParams, AuthenticationSrv, NotificationSrv, UtilsSrv, UrlParser, appConfig) {
$scope.params = {};

$uibModalStack.dismissAll();
Expand Down Expand Up @@ -45,8 +45,8 @@
});
};

if(angular.isDefined($location.search().code) || $stateParams.autoLogin) {
var code = angular.isDefined($location.search().code) ? $location.search().code : undefined;
var code = UtilsSrv.extractQueryParam('code', UrlParser('query', $location.absUrl()));
if(angular.isDefined(code) || $stateParams.autoLogin) {
$scope.ssoLogin(code);
}
});
Expand Down
37 changes: 26 additions & 11 deletions ui/app/scripts/services/UtilsSrv.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
(function() {
'use strict';
angular.module('theHiveServices')
.factory('UtilsSrv', function() {
.factory('UtilsSrv', function($location) {
var sensitiveTypes = ['url', 'ip', 'mail', 'domain', 'filename'];

var service = {
guid: function () {
function s4() {
return Math.floor((1 + Math.random()) * 0x10000)
.toString(16)
.substring(1);
}
return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
s4() + '-' + s4() + s4() + s4();
var service = {
guid: function() {
function s4() {
return Math.floor((1 + Math.random()) * 0x10000)
.toString(16)
.substring(1);
}
return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
s4() + '-' + s4() + s4() + s4();
},
objectify: function(arr, property) {
return _.map(arr, function(str){
return _.map(arr, function(str) {
var obj = {};
obj[property] = str;
return obj;
Expand Down Expand Up @@ -101,6 +101,21 @@
scope.value = scope.oldValue;
scope.updatable.updating = false;
};
},

extractQueryParam: function(paramName, queryString) {
if (!queryString || !paramName)
return;
var param = $location.search()[paramName];

if (param) {
return param;
} else {
var parsedQuery = _.find(queryString.split('&'), function(str) {
return str.startsWith(paramName + '=');
});
return parsedQuery ? parsedQuery.substr(paramName.length + 1) : undefined;
}
}
};

Expand Down
3 changes: 2 additions & 1 deletion ui/bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@
"underscore.string": "^3.3.4",
"angular-drag-and-drop-lists": "^2.1.0",
"angular-bootstrap-colorpicker": "^3.0.31",
"file-saver": "^1.3.3"
"file-saver": "^1.3.3",
"js-url": "^2.5.2"
},
"devDependencies": {
"angular-mocks": "1.5.8"
Expand Down
1 change: 1 addition & 0 deletions ui/test/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ module.exports = function(config) {
'bower_components/angular-drag-and-drop-lists/angular-drag-and-drop-lists.js',
'bower_components/angular-bootstrap-colorpicker/js/bootstrap-colorpicker-module.js',
'bower_components/file-saver/FileSaver.js',
'bower_components/js-url/url.js',
'bower_components/angular-mocks/angular-mocks.js',
// endbower
"bower_components/cryptojslib/components/core-min.js",
Expand Down

0 comments on commit c1012c8

Please sign in to comment.