2016-09-18 00:27:36 +02:00
|
|
|
|
angular
|
|
|
|
|
.module('bit.tools')
|
|
|
|
|
|
2016-09-22 19:15:42 +02:00
|
|
|
|
.controller('toolsPasswordGeneratorController', function ($scope, $state, $stateParams, passwordGenerationService,
|
2016-09-28 05:19:33 +02:00
|
|
|
|
toastr, $q, utilsService, $analytics) {
|
2016-09-18 04:57:51 +02:00
|
|
|
|
var addState = $stateParams.addState,
|
|
|
|
|
editState = $stateParams.editState;
|
|
|
|
|
|
2016-09-20 04:24:55 +02:00
|
|
|
|
$scope.showSelect = $stateParams.addState || $stateParams.editState;
|
|
|
|
|
|
2016-09-27 00:41:20 +02:00
|
|
|
|
utilsService.initListSectionItemListeners($(document));
|
2016-09-18 04:57:51 +02:00
|
|
|
|
$scope.password = '-';
|
|
|
|
|
|
2016-09-20 03:38:29 +02:00
|
|
|
|
$scope.slider = {
|
|
|
|
|
value: 12,
|
|
|
|
|
options: {
|
|
|
|
|
floor: 5,
|
|
|
|
|
ceil: 64,
|
|
|
|
|
step: 1,
|
|
|
|
|
hideLimitLabels: true,
|
|
|
|
|
hidePointerLabels: true,
|
|
|
|
|
onChange: function () {
|
|
|
|
|
$scope.options.length = $scope.slider.value;
|
2016-09-28 05:19:33 +02:00
|
|
|
|
$scope.regenerate(false);
|
2016-09-20 03:38:29 +02:00
|
|
|
|
},
|
|
|
|
|
onEnd: function () {
|
2016-09-28 05:19:33 +02:00
|
|
|
|
$analytics.eventTrack('Generated Password');
|
2016-09-20 03:38:29 +02:00
|
|
|
|
$scope.saveOptions($scope.options);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2016-09-18 04:57:51 +02:00
|
|
|
|
$q.when(passwordGenerationService.getOptions()).then(function (options) {
|
|
|
|
|
$scope.options = options;
|
2016-09-20 03:38:29 +02:00
|
|
|
|
$scope.slider.value = options.length;
|
2016-09-28 05:19:33 +02:00
|
|
|
|
$scope.regenerate(false);
|
|
|
|
|
$analytics.eventTrack('Generated Password');
|
2016-09-18 04:57:51 +02:00
|
|
|
|
});
|
|
|
|
|
|
2016-09-28 05:19:33 +02:00
|
|
|
|
$scope.regenerate = function (trackRegenerateEvent) {
|
|
|
|
|
if (trackRegenerateEvent) {
|
|
|
|
|
$analytics.eventTrack('Regenerated Password');
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-18 04:57:51 +02:00
|
|
|
|
$scope.password = passwordGenerationService.generatePassword($scope.options);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$scope.saveOptions = function (options) {
|
|
|
|
|
if (!options.uppercase && !options.lowercase && !options.number && !options.special) {
|
|
|
|
|
options.lowercase = $scope.options.lowercase = true;
|
|
|
|
|
}
|
|
|
|
|
if (!options.minNumber) {
|
|
|
|
|
options.minNumber = $scope.options.minNumber = 0;
|
|
|
|
|
}
|
|
|
|
|
if (!options.minSpecial) {
|
|
|
|
|
options.minSpecial = $scope.options.minSpecial = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
passwordGenerationService.saveOptions(options);
|
2016-09-28 05:19:33 +02:00
|
|
|
|
$scope.regenerate(false);
|
2016-09-18 04:57:51 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$scope.clipboardError = function (e, password) {
|
|
|
|
|
toastr.info('Your web browser does not support easy clipboard copying. Copy it manually instead.');
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$scope.clipboardSuccess = function (e) {
|
2016-09-28 05:19:33 +02:00
|
|
|
|
$analytics.eventTrack('Copied Generated Password');
|
2016-09-18 04:57:51 +02:00
|
|
|
|
e.clearSelection();
|
|
|
|
|
toastr.info('Password copied!');
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$scope.close = function () {
|
2016-09-20 04:24:55 +02:00
|
|
|
|
dismiss();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$scope.select = function () {
|
2016-09-28 05:19:33 +02:00
|
|
|
|
$analytics.eventTrack('Selected Generated Password');
|
|
|
|
|
|
2016-09-20 04:24:55 +02:00
|
|
|
|
if (addState) {
|
|
|
|
|
addState.site.password = $scope.password;
|
|
|
|
|
}
|
|
|
|
|
else if (editState) {
|
|
|
|
|
editState.site.password = $scope.password;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dismiss();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function dismiss() {
|
2016-09-18 04:57:51 +02:00
|
|
|
|
if (addState) {
|
|
|
|
|
$state.go('addSite', {
|
|
|
|
|
animation: 'out-slide-down',
|
2016-09-20 04:24:55 +02:00
|
|
|
|
fromCurrent: addState.fromCurrent,
|
|
|
|
|
site: addState.site,
|
|
|
|
|
returnScrollY: addState.returnScrollY,
|
|
|
|
|
returnSearchText: addState.returnSearchText
|
2016-09-18 04:57:51 +02:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else if (editState) {
|
|
|
|
|
$state.go('editSite', {
|
|
|
|
|
animation: 'out-slide-down',
|
2016-09-20 04:24:55 +02:00
|
|
|
|
site: editState.site,
|
|
|
|
|
fromView: editState.fromView,
|
|
|
|
|
siteId: editState.siteId,
|
|
|
|
|
returnScrollY: editState.returnScrollY,
|
|
|
|
|
returnSearchText: editState.returnSearchText
|
2016-09-18 04:57:51 +02:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$state.go('tabs.tools', {
|
|
|
|
|
animation: 'out-slide-down'
|
|
|
|
|
});
|
|
|
|
|
}
|
2016-09-20 04:24:55 +02:00
|
|
|
|
}
|
2016-09-18 00:27:36 +02:00
|
|
|
|
});
|