diff --git a/src/js/controller/privatekey-upload.js b/src/js/controller/privatekey-upload.js index 7ba31fa..c29107d 100644 --- a/src/js/controller/privatekey-upload.js +++ b/src/js/controller/privatekey-upload.js @@ -3,6 +3,7 @@ define(function(require) { var angular = require('angular'), appController = require('js/app-controller'), + util = require('js/crypto/util'), keychain, pgp; var PrivateKeyUploadCtrl = function($scope) { @@ -82,26 +83,13 @@ define(function(require) { // go to step 1 $scope.step = 1; // generate new code for the user - $scope.code = $scope.generateCode(); + $scope.code = util.randomString(24).toUpperCase(); $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 = ''; }; - $scope.generateCode = function() { - function randomString(length, chars) { - var result = ''; - var randomValues = new Uint8Array(length); // get random length number of bytes - window.crypto.getRandomValues(randomValues); - for (var i = 0; i < length; i++) { - result += chars[Math.round(randomValues[i] / 255 * (chars.length - 1))]; - } - return result; - } - return randomString(24, '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'); - }; - $scope.verifyCode = function() { var inputCode = '' + $scope.code0 + $scope.code1 + $scope.code2 + $scope.code3 + $scope.code4 + $scope.code5; diff --git a/src/sass/views/_privatekey-upload.scss b/src/sass/views/_privatekey-upload.scss index 4fa9326..0530544 100644 --- a/src/sass/views/_privatekey-upload.scss +++ b/src/sass/views/_privatekey-upload.scss @@ -18,4 +18,8 @@ } } + button.ng-animate { + transition: none; + } + } \ No newline at end of file diff --git a/test/unit/privatekey-upload-ctrl-test.js b/test/unit/privatekey-upload-ctrl-test.js index 4dc7375..542d798 100644 --- a/test/unit/privatekey-upload-ctrl-test.js +++ b/test/unit/privatekey-upload-ctrl-test.js @@ -109,15 +109,12 @@ define(function(require) { describe('displayUploadUi', function() { it('should work', function() { - var generateCodeStub = sinon.stub(scope, 'generateCode'); - generateCodeStub.returns('asdf'); - // add some artifacts from a previous key input scope.code0 = scope.code1 = scope.code2 = scope.code3 = scope.code4 = scope.code5 = 'asdasd'; scope.displayUploadUi(); expect(scope.step).to.equal(1); - expect(scope.code).to.equal('asdf'); + expect(scope.code.length).to.equal(24); // artifacts should be cleared expect(scope.code0).to.be.empty; @@ -126,14 +123,6 @@ define(function(require) { expect(scope.code3).to.be.empty; expect(scope.code4).to.be.empty; expect(scope.code5).to.be.empty; - - generateCodeStub.restore(); - }); - }); - - describe('generateCode', function() { - it('should work', function() { - expect(scope.generateCode().length).to.equal(24); }); });