From 876a0b0302e6a4538fe9606dc07767c675bf3c52 Mon Sep 17 00:00:00 2001 From: Tankred Hase Date: Mon, 1 Dec 2014 11:53:45 +0100 Subject: [PATCH] Integrate wo-input-code directive --- src/js/app.js | 1 - src/js/controller/app/privatekey-upload.js | 50 ++----------------- .../login/login-privatekey-download.js | 24 +-------- src/js/directive/common.js | 6 +++ src/tpl/login-privatekey-download.html | 12 +---- src/tpl/privatekey-upload.html | 12 +---- 6 files changed, 14 insertions(+), 91 deletions(-) diff --git a/src/js/app.js b/src/js/app.js index 44050be..d54d92f 100644 --- a/src/js/app.js +++ b/src/js/app.js @@ -63,7 +63,6 @@ var app = angular.module('mail', [ 'read', 'contacts', 'login-new-device', - 'privatekey-upload', 'infinite-scroll' ]); diff --git a/src/js/controller/app/privatekey-upload.js b/src/js/controller/app/privatekey-upload.js index 779a101..eb70450 100644 --- a/src/js/controller/app/privatekey-upload.js +++ b/src/js/controller/app/privatekey-upload.js @@ -33,26 +33,6 @@ var PrivateKeyUploadCtrl = function($scope, keychain, pgp, dialog, auth) { } }; - $scope.handlePaste = function(event) { - var evt = event; - if (evt.originalEvent) { - evt = evt.originalEvent; - } - - var value = evt.clipboardData.getData('text/plain'); - if (!value) { - return; - } - - value = value.replace(/-/g, ''); - $scope.code0 = value.slice(0, 4); - $scope.code1 = value.slice(4, 8); - $scope.code2 = value.slice(8, 12); - $scope.code3 = value.slice(12, 16); - $scope.code4 = value.slice(16, 20); - $scope.code5 = value.slice(20, 24); - }; - $scope.checkServerForKey = function(callback) { var keyParams = pgp.getKeyParams(); keychain.hasPrivateKey({ @@ -80,14 +60,12 @@ var PrivateKeyUploadCtrl = function($scope, keychain, pgp, dialog, auth) { $scope.code = util.randomString(24); $scope.displayedCode = $scope.code.slice(0, 4) + '-' + $scope.code.slice(4, 8) + '-' + $scope.code.slice(8, 12) + '-' + $scope.code.slice(12, 16) + '-' + $scope.code.slice(16, 20) + '-' + $scope.code.slice(20, 24); - // clear input fields of any previous artifacts - $scope.code0 = $scope.code1 = $scope.code2 = $scope.code3 = $scope.code4 = $scope.code5 = ''; + // clear input field of any previous artifacts + $scope.inputCode = ''; }; $scope.verifyCode = function() { - var inputCode = '' + $scope.code0 + $scope.code1 + $scope.code2 + $scope.code3 + $scope.code4 + $scope.code5; - - if (inputCode.toUpperCase() !== $scope.code) { + if ($scope.inputCode.toUpperCase() !== $scope.code) { var err = new Error('The code does not match. Please go back and check the generated code.'); dialog.error(err); return false; @@ -171,26 +149,4 @@ var PrivateKeyUploadCtrl = function($scope, keychain, pgp, dialog, auth) { }; -// -// Directives -// - -var ngModule = angular.module('privatekey-upload', []); -ngModule.directive('focusNext', function() { - return { - link: function(scope, element, attr) { - var maxLen = element[0].maxLength; - - scope.$watch(attr.ngModel, function(val) { - if (val && val.length === maxLen) { - var nextinput = element.next('input'); - if (nextinput.length) { - nextinput[0].focus(); - } - } - }); - } - }; -}); - module.exports = PrivateKeyUploadCtrl; \ No newline at end of file diff --git a/src/js/controller/login/login-privatekey-download.js b/src/js/controller/login/login-privatekey-download.js index 2d9715b..5c3a58c 100644 --- a/src/js/controller/login/login-privatekey-download.js +++ b/src/js/controller/login/login-privatekey-download.js @@ -70,10 +70,8 @@ var LoginPrivateKeyDownloadCtrl = function($scope, $location, $routeParams, auth }; $scope.decryptAndStorePrivateKeyLocally = function() { - var inputCode = '' + $scope.code0 + $scope.code1 + $scope.code2 + $scope.code3 + $scope.code4 + $scope.code5; - var options = $scope.encryptedPrivateKey; - options.code = inputCode.toUpperCase(); + options.code = $scope.code.toUpperCase(); keychain.decryptAndStorePrivateKeyLocally(options, function(err, privateKey) { if (err) { @@ -108,26 +106,6 @@ var LoginPrivateKeyDownloadCtrl = function($scope, $location, $routeParams, auth }); }; - $scope.handlePaste = function(event) { - var evt = event; - if (evt.originalEvent) { - evt = evt.originalEvent; - } - - var value = evt.clipboardData.getData('text/plain'); - if (!value) { - return; - } - - value = value.replace(/-/g, ''); - $scope.code0 = value.slice(0, 4); - $scope.code1 = value.slice(4, 8); - $scope.code2 = value.slice(8, 12); - $scope.code3 = value.slice(12, 16); - $scope.code4 = value.slice(16, 20); - $scope.code5 = value.slice(20, 24); - }; - // // helper functions // diff --git a/src/js/directive/common.js b/src/js/directive/common.js index 1bdbdef..fac43ce 100644 --- a/src/js/directive/common.js +++ b/src/js/directive/common.js @@ -222,6 +222,12 @@ ngModule.directive('woInputCode', function() { link: function(scope, elm, attrs, ngModelCtrl) { function format(val) { var str = ''; + + // check if value exists + if (!val) { + return str; + } + for(var i = 0; i < val.length; i++) { if(i > 0 && i % BLOCK_SIZE === 0) { str += BLOCK_DIVIDER; diff --git a/src/tpl/login-privatekey-download.html b/src/tpl/login-privatekey-download.html index c778d22..af4601e 100644 --- a/src/tpl/login-privatekey-download.html +++ b/src/tpl/login-privatekey-download.html @@ -43,16 +43,8 @@

{{errMsg}}

- -
- - - - - - - - - - - -
- +
diff --git a/src/tpl/privatekey-upload.html b/src/tpl/privatekey-upload.html index 9ba48c7..986960b 100644 --- a/src/tpl/privatekey-upload.html +++ b/src/tpl/privatekey-upload.html @@ -25,16 +25,8 @@

Please confirm the keychain code you have written down.

- -
- - - - - - - - - - - -
- +