diff --git a/src/background.js b/src/background.js index 05164b54..bb4c7a44 100644 --- a/src/background.js +++ b/src/background.js @@ -6,6 +6,7 @@ var siteService = new SiteService(cryptoService, userService, apiService); var folderService = new FolderService(cryptoService, userService, apiService); var syncService = new SyncService(siteService, folderService, userService, apiService); var autofillService = new AutofillService(); +var passwordGenerationService = new PasswordGenerationService(); function buildContextMenu() { chrome.contextMenus.removeAll(); diff --git a/src/popup/app/config.js b/src/popup/app/config.js index d7dfe4f5..ad28d712 100644 --- a/src/popup/app/config.js +++ b/src/popup/app/config.js @@ -89,7 +89,7 @@ templateUrl: 'app/vault/views/vaultAddSite.html', controller: 'vaultAddSiteController', data: { authorize: true }, - params: { animation: null, returnScrollY: 0, returnSearchText: null, name: null, uri: null } + params: { animation: null, returnScrollY: 0, returnSearchText: null, name: null, uri: null, site: null } }) .state('editSite', { url: '/edit-site?siteId', @@ -104,7 +104,7 @@ templateUrl: 'app/tools/views/toolsPasswordGenerator.html', controller: 'toolsPasswordGeneratorController', data: { authorize: true }, - params: { animation: null, fromAdd: false, fromEdit: null } + params: { animation: null, addState: null, editState: null } }); }) .run(function ($rootScope, userService, loginService, tokenService, $state) { diff --git a/src/popup/app/tools/toolsModule.js b/src/popup/app/tools/toolsModule.js index 510df975..8b592b43 100644 --- a/src/popup/app/tools/toolsModule.js +++ b/src/popup/app/tools/toolsModule.js @@ -1,2 +1,2 @@ angular - .module('bit.tools', []); + .module('bit.tools', ['ngAnimate', 'ngclipboard', 'toastr']); diff --git a/src/popup/app/tools/toolsPasswordGeneratorController.js b/src/popup/app/tools/toolsPasswordGeneratorController.js index 6f618f3c..1d110f69 100644 --- a/src/popup/app/tools/toolsPasswordGeneratorController.js +++ b/src/popup/app/tools/toolsPasswordGeneratorController.js @@ -1,6 +1,63 @@ angular .module('bit.tools') - .controller('toolsPasswordGeneratorController', function ($scope, $state, $stateParams) { + .controller('toolsPasswordGeneratorController', function ($scope, $state, $stateParams, passwordGenerationService, toastr, $q) { + var addState = $stateParams.addState, + editState = $stateParams.editState; + popupUtils.initListSectionItemListeners(); + $scope.password = '-'; + + $q.when(passwordGenerationService.getOptions()).then(function (options) { + $scope.options = options; + $scope.regenerate(); + }); + + $scope.regenerate = function () { + $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); + $scope.regenerate(); + }; + + $scope.clipboardError = function (e, password) { + toastr.info('Your web browser does not support easy clipboard copying. Copy it manually instead.'); + }; + + $scope.clipboardSuccess = function (e) { + e.clearSelection(); + toastr.info('Password copied!'); + }; + + $scope.close = function () { + if (addState) { + $state.go('addSite', { + animation: 'out-slide-down', + site: addState + }); + } + else if (editState) { + $state.go('editSite', { + animation: 'out-slide-down', + siteId: editState + }); + } + else { + $state.go('tabs.tools', { + animation: 'out-slide-down' + }); + } + }; }); diff --git a/src/popup/app/tools/views/toolsPasswordGenerator.html b/src/popup/app/tools/views/toolsPasswordGenerator.html index 8c995711..603bd3c7 100644 --- a/src/popup/app/tools/views/toolsPasswordGenerator.html +++ b/src/popup/app/tools/views/toolsPasswordGenerator.html @@ -9,15 +9,16 @@