| Conditions | 1 |
| Paths | 2 |
| Total Lines | 72 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | /** |
||
| 23 | (function () { |
||
| 24 | 'use strict'; |
||
| 25 | /** |
||
| 26 | * Created by wolfi on 25/09/16. |
||
| 27 | */ |
||
| 28 | angular.module('passmanApp') |
||
| 29 | .controller('SharingSettingsCtrl', ['$scope', 'VaultService', 'CredentialService', 'SettingsService', '$location', '$routeParams', 'ShareService', 'EncryptService', |
||
| 30 | function ($scope, VaultService, CredentialService, SettingsService, $location, $routeParams, ShareService, EncryptService) { |
||
| 31 | $scope.active_vault = VaultService.getActiveVault(); |
||
| 32 | $scope.sharing_keys = angular.copy(ShareService.getSharingKeys()); |
||
| 33 | |||
| 34 | $scope.progress = 1; |
||
| 35 | $scope.generating = false; |
||
| 36 | |||
| 37 | |||
| 38 | $scope.available_sizes = [ |
||
| 39 | { |
||
| 40 | size: 1024, |
||
| 41 | name: 1024 |
||
| 42 | }, |
||
| 43 | { |
||
| 44 | size: 2048, |
||
| 45 | name: 2048 |
||
| 46 | }, |
||
| 47 | { |
||
| 48 | size: 4096, |
||
| 49 | name: 4096 |
||
| 50 | } |
||
| 51 | ]; |
||
| 52 | |||
| 53 | $scope.setKeySize = function (size) { |
||
| 54 | for (var i = 0; i < $scope.available_sizes.length; i++) { |
||
| 55 | if ($scope.available_sizes[i].size === size) { |
||
| 56 | $scope.key_size = $scope.available_sizes[i]; |
||
| 57 | return; |
||
| 58 | } |
||
| 59 | } |
||
| 60 | }; |
||
| 61 | |||
| 62 | $scope.setKeySize(2048); |
||
| 63 | |||
| 64 | $scope.generateKeys = function (length) { |
||
| 65 | $scope.progress = 1; |
||
| 66 | $scope.generating = true; |
||
| 67 | |||
| 68 | ShareService.generateRSAKeys(length).progress(function (progress) { |
||
| 69 | $scope.progress = progress > 0 ? 2 : 1; |
||
| 70 | $scope.$digest(); |
||
| 71 | }).then(function (kp) { |
||
| 72 | $scope.generating = false; |
||
| 73 | |||
| 74 | var pem = ShareService.rsaKeyPairToPEM(kp); |
||
| 75 | |||
| 76 | $scope.active_vault.private_sharing_key = EncryptService.encryptString(pem.privateKey); |
||
| 77 | $scope.active_vault.public_sharing_key = pem.publicKey; |
||
| 78 | |||
| 79 | VaultService.updateSharingKeys($scope.active_vault).then(function () { |
||
| 80 | $scope.sharing_keys = ShareService.getSharingKeys(); |
||
| 81 | }); |
||
| 82 | }); |
||
| 83 | }; |
||
| 84 | |||
| 85 | $scope.updateSharingKeys = function () { |
||
| 86 | $scope.active_vault.private_sharing_key = EncryptService.encryptString(angular.copy($scope.sharing_keys.private_sharing_key)); |
||
| 87 | $scope.active_vault.public_sharing_key = angular.copy($scope.sharing_keys.public_sharing_key); |
||
| 88 | VaultService.updateSharingKeys($scope.active_vault).then(function () { |
||
| 89 | $scope.sharing_keys = ShareService.getSharingKeys(); |
||
| 90 | }); |
||
| 91 | }; |
||
| 92 | |||
| 93 | }]); |
||
| 94 | }()); |