From 0c0e11aad3a47672902b7bb0c5684338cb109313 Mon Sep 17 00:00:00 2001 From: Gustavo Maximiliano Cortez Date: Tue, 2 Dec 2014 16:16:31 -0300 Subject: [PATCH 01/20] Pin flow --- js/controllers/home.js | 95 ++++++++++++++++++++++++++++++++------- js/services/pinService.js | 38 ++++++++++++++++ views/home.html | 70 +++++++++++++++++++++++++++-- 3 files changed, 183 insertions(+), 20 deletions(-) create mode 100644 js/services/pinService.js diff --git a/js/controllers/home.js b/js/controllers/home.js index df4c43ab5..c459cb545 100644 --- a/js/controllers/home.js +++ b/js/controllers/home.js @@ -1,28 +1,52 @@ 'use strict'; -angular.module('copayApp.controllers').controller('HomeController', function($scope, $rootScope, $location, $timeout, notification, identityService, Compatibility) { - // This is only for backwards compat, insight api should link to #!/confirmed directly - if (getParam('confirmed')) { - var hashIndex = window.location.href.indexOf('/?'); - window.location = window.location.href.substr(0, hashIndex) + '#!/confirmed'; - return; - } +angular.module('copayApp.controllers').controller('HomeController', function($scope, $rootScope, $location, $timeout, notification, identityService, Compatibility, pinService) { + $scope.init = function() { + // This is only for backwards compat, insight api should link to #!/confirmed directly + if (getParam('confirmed')) { + var hashIndex = window.location.href.indexOf('/?'); + window.location = window.location.href.substr(0, hashIndex) + '#!/confirmed'; + return; + } - if ($rootScope.fromEmailConfirmation) { - $scope.confirmedEmail = true; - $rootScope.fromEmailConfirmation = false; - } + if ($rootScope.fromEmailConfirmation) { + $scope.confirmedEmail = true; + $rootScope.fromEmailConfirmation = false; + } + Compatibility.check($scope); + $scope.hasPin = pinService.check(); + }; + + Object.defineProperty($scope, + "pin", { + get: function() { + return this._pin; + }, + set: function(newValue) { + console.log('[home.js:26]',newValue, this._pin); //TODO + this._pin = newValue; + if (newValue && newValue.length == 4) { + console.log('[home.js:26] INGRESANDO AUTOMATICAMENTE',newValue); //TODO + $scope.openPin(newValue); + } + if (!newValue) { + $scope.error = null; + } + }, + enumerable: true, + configurable: true + }); - Compatibility.check($scope); $scope.done = function() { + $scope.hasPin = pinService.check(); $rootScope.starting = false; $rootScope.$digest(); }; - $scope.$on("$destroy", function(){ + $scope.$on("$destroy", function() { var iden = $rootScope.iden; if (iden) { iden.removeListener('newWallet', $scope.done ); @@ -30,20 +54,57 @@ angular.module('copayApp.controllers').controller('HomeController', function($sc } }); - - $scope.openProfile = function(form) { + $scope.openWithPin = function(form) { $scope.confirmedEmail = false; if (form && form.$invalid) { $scope.error = 'Please enter the required fields'; return; } + $scope.openPin(pin); + }; + + $scope.openPin = function(pin) { + var credentials = pinService.get(parseInt(pin)); + if (!credentials) { + $scope.error = 'Wrong PIN'; + return; + } + $rootScope.starting = true; - identityService.open(form.email.$modelValue, form.password.$modelValue, function(err, iden) { - if (err) { + $scope.open(credentials.email, credentials.password); + }; + + $scope.createPin = function(form) { + if (form) { + pinService.save(form.repeatpin.$modelValue, $scope.email, $scope.password); + } + $scope.open($scope.email, $scope.password); + }; + + $scope.openWithCredentials = function(form) { + $scope.confirmedEmail = false; + if (form && form.$invalid) { + $scope.error = 'Please enter the required fields'; + return; + } + if (!$scope.hasPin) { + $scope.email = form.email.$modelValue; + $scope.password = form.password.$modelValue; + $scope.setPin = true; + return; + } + $scope.open(form.email.$modelValue, form.password.$modelValue); + }; + + $scope.open = function(email, password) { + $rootScope.starting = true; + identityService.open(email, password, function(err, iden) { + if (err) { $rootScope.starting = false; copay.logger.warn(err); if ((err.toString() || '').match('PNOTFOUND')) { $scope.error = 'Invalid email or password'; + pinService.clear(); } else if ((err.toString() || '').match('Connection')) { $scope.error = 'Could not connect to Insight Server'; } else if ((err.toString() || '').match('Unable')) { diff --git a/js/services/pinService.js b/js/services/pinService.js new file mode 100644 index 000000000..b6d30192c --- /dev/null +++ b/js/services/pinService.js @@ -0,0 +1,38 @@ +'use strict'; + +angular.module('copayApp.services') + .factory('pinService', function($rootScope) { + var root = {}; + var storage = { + pinData: { + pin: 1234, + credentials: { + email: '4@queparece', + password: '1', + } + } + }; + root.check = function() { + return storage.pinData ? true : false; + }; + root.get = function(pin) { + var storedPin = storage.pinData.pin; + if (storedPin !== pin) + return; + + return storage.pinData.credentials; + }; + root.save = function(pin, email, password) { + storage.pinData = { + pin: pin, + credentials: { + email: email, + password: password + } + }; + }; + root.clear = function(){ + delete storage['pinData']; + }; + return root; + }); diff --git a/views/home.html b/views/home.html index 7cae7c3eb..5c7fcff60 100644 --- a/views/home.html +++ b/views/home.html @@ -1,4 +1,4 @@ -
+
@@ -47,9 +47,72 @@ creating your profile
-
+
+

Set your PIN number

+
+
+ + +
+
+ + +
+ +

+ + {{'Pin must match'|translate}} +

+ + +
+ +
+ +
+

Enter your PIN number

+
+

+ + {{error|translate}} +

+
+ + +
+ + +
+ +
+ + +

Sign in to Copay

-
+

@@ -71,6 +134,7 @@ Sign in

+ × diff --git a/views/receive.html b/views/receive.html index a07a964c7..e593d4627 100644 --- a/views/receive.html +++ b/views/receive.html @@ -14,8 +14,8 @@
- - change + + change
@@ -34,8 +34,8 @@
- - change + + change
diff --git a/views/send.html b/views/send.html index 5804b0027..b9552528e 100644 --- a/views/send.html +++ b/views/send.html @@ -217,9 +217,9 @@ ng-repeat="(addr, info) in $root.wallet.addressBook" ng-class="{'addressbook-disabled': info.hidden}"> {{info.label}} - {{addr}} + {{::addr}} {{$root.wallet.publicKeyRing.nicknameForCopayer(info.copayerId)}} - + Date: Wed, 3 Dec 2014 00:30:44 -0300 Subject: [PATCH 06/20] signout/lock text --- index.html | 1 - js/controllers/sidebar.js | 11 ++++++----- js/models/Identity.js | 10 +++++----- views/includes/sidebar-mobile.html | 7 +++++-- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/index.html b/index.html index 4a4911c6a..c49a154fb 100644 --- a/index.html +++ b/index.html @@ -34,7 +34,6 @@
 
 
- Logging Out
diff --git a/js/controllers/sidebar.js b/js/controllers/sidebar.js index 6dadb4057..3485558fd 100644 --- a/js/controllers/sidebar.js +++ b/js/controllers/sidebar.js @@ -1,6 +1,6 @@ 'use strict'; -angular.module('copayApp.controllers').controller('SidebarController', function($scope, $rootScope, $location, $timeout, identityService) { +angular.module('copayApp.controllers').controller('SidebarController', function($scope, $rootScope, $location, $timeout, identityService, pinService) { $scope.menu = [{ 'title': 'Home', @@ -48,7 +48,7 @@ angular.module('copayApp.controllers').controller('SidebarController', function( $scope.init = function() { // This should be called only once. - + // focused wallet change if ($rootScope.wallet) { $rootScope.$watch('wallet', function() { @@ -73,16 +73,17 @@ angular.module('copayApp.controllers').controller('SidebarController', function( if (newWid && $rootScope.iden.getWalletById(newWid)) { identityService.setFocusedWallet(newWid); } else { - copay.logger.debug('No wallets'); + copay.logger.debug('No wallets'); identityService.noFocusedWallet(newWid); } } $scope.walletSelection = false; $scope.setWallets(); }); - + pinService.check(function(err, value) { + $scope.hasPin = value; + }); } - }; $scope.setWallets = function() { diff --git a/js/models/Identity.js b/js/models/Identity.js index 3799e329f..e215412fa 100644 --- a/js/models/Identity.js +++ b/js/models/Identity.js @@ -355,17 +355,17 @@ Identity.prototype.remove = function(opts, cb) { }; Identity.prototype._cleanUp = function() { - // NOP + _.each(this.wallets, function(w){ + w.close(); + }); }; /** * @desc Closes the wallet and disconnects all services */ Identity.prototype.close = function() { - var self = this; - self.store({}, function(err) { - self.emitAndKeepAlive('closed'); - }); + this._cleanUp(); + this.emitAndKeepAlive('closed'); }; diff --git a/views/includes/sidebar-mobile.html b/views/includes/sidebar-mobile.html index 2a89ab52c..fcc61cf56 100644 --- a/views/includes/sidebar-mobile.html +++ b/views/includes/sidebar-mobile.html @@ -1,4 +1,4 @@ -
+
@@ -101,7 +101,10 @@
  • {{'Close'|translate}} + ng-click="signout()"> + {{'Close'|translate}} + {{'Lock'|translate}} +
  • From 33e0bf80a6ceedd58a96533dad5542e67660c07f Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Wed, 3 Dec 2014 00:36:44 -0300 Subject: [PATCH 07/20] lock also in header --- js/controllers/head.js | 8 +++++++- views/includes/head.html | 5 ++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/js/controllers/head.js b/js/controllers/head.js index 899d445b1..375efc91e 100644 --- a/js/controllers/head.js +++ b/js/controllers/head.js @@ -1,6 +1,6 @@ 'use strict'; -angular.module('copayApp.controllers').controller('HeadController', function($scope, $rootScope, $filter, $timeout, notification, identityService, balanceService) { +angular.module('copayApp.controllers').controller('HeadController', function($scope, $rootScope, $filter, $timeout, notification, identityService, balanceService, pinService) { $scope.username = $rootScope.iden.getName(); $scope.hoverMenu = false; @@ -39,7 +39,13 @@ angular.module('copayApp.controllers').controller('HeadController', function($sc window.onbeforeunload = undefined; }); + // TODO put this on init() if ($rootScope.wallet) { + pinService.check(function(err, value) { + $scope.hasPin = value; + }); + + $scope.$on('$idleStart', function() { }); $scope.$on('$idleWarn', function(a, countdown) { diff --git a/views/includes/head.html b/views/includes/head.html index 68736f757..de6fb38d0 100644 --- a/views/includes/head.html +++ b/views/includes/head.html @@ -39,7 +39,10 @@ {{'Profile'|translate}} [ Needs Backup ]
  • - {{'Close'|translate}}
  • + {{'Close'|translate}} + {{'Lock'|translate}} + +
    From 51028178ed5b677e7a0c6f8c17a5cb87e94a209a Mon Sep 17 00:00:00 2001 From: Gustavo Maximiliano Cortez Date: Wed, 3 Dec 2014 03:03:16 -0300 Subject: [PATCH 08/20] Autofocus and show the second PIN input automatically. Hide submit button. Allow only numbers --- js/controllers/home.js | 39 ++++++++++++++++++++++ js/directives.js | 12 ++++++- views/home.html | 73 ++++++++++++++++++++++++++---------------- 3 files changed, 96 insertions(+), 28 deletions(-) diff --git a/js/controllers/home.js b/js/controllers/home.js index 153ee30f1..6a4d3a2f1 100644 --- a/js/controllers/home.js +++ b/js/controllers/home.js @@ -43,6 +43,45 @@ angular.module('copayApp.controllers').controller('HomeController', function($sc configurable: true }); + Object.defineProperty($scope, + "newpin", { + get: function() { + return this._newpin; + }, + set: function(newValue) { + this._newpin = newValue; + if (newValue && newValue.length == 4) { + // next input + $scope.$$childTail.secondPin = true; + } + }, + enumerable: true, + configurable: true + }); + + Object.defineProperty($scope, + "repeatpin", { + get: function() { + return this._repeatpin; + }, + set: function(newValue) { + this._repeatpin = newValue; + if (newValue && newValue.length == 4) { + if ($scope.$$childTail._newpin === newValue) { + // save and submit + $scope.createPin($scope.$$childTail.setPinForm); + } + else { + $scope.error = 'Pin must match!'; + } + } + if (!newValue) { + $scope.error = null; + } + }, + enumerable: true, + configurable: true + }); $scope.done = function() { $rootScope.starting = false; diff --git a/js/directives.js b/js/directives.js index ac823cdb1..993357694 100644 --- a/js/directives.js +++ b/js/directives.js @@ -286,10 +286,20 @@ angular.module('copayApp.directives') link: function(_scope, _element) { $timeout(function() { _element[0].focus(); - }, 0); + }); } }; }) + .directive('showFocus', function($timeout) { + return function(scope, element, attrs) { + scope.$watch(attrs.showFocus, + function (newValue) { + $timeout(function() { + newValue && element[0].focus(); + }); + },true); + }; + }) .directive('match', function() { return { require: 'ngModel', diff --git a/views/home.html b/views/home.html index 5c7fcff60..5d75090da 100644 --- a/views/home.html +++ b/views/home.html @@ -47,62 +47,81 @@ creating your profile
    -
    +

    Set your PIN number

    +
    +
    + +
    + + {{error|translate}} + +
    +
    -
    - + + ng-pattern="/^[0-9]{1,4}$/" + placeholder="Pin number" name="newpin" required show-focus="!secondPin">
    -
    +
    + ng-pattern="/^[0-9]{1,4}$/" + placeholder="Repeat pin number" name="repeatpin" required show-focus="secondPin">
    -

    - - {{'Pin must match'|translate}} -

    - - -

    Enter your PIN number

    -

    - - {{error|translate}} -

    +
    +
    + +
    + + {{error|translate}} + +
    +
    -
    -
    -
    +
    Copay
    @@ -47,8 +47,10 @@ creating your profile
    -
    -

    Set your PIN number

    +
    +

    Set up a PIN ?

    +

    Enter a 4-digit number for easier access from this device +

    @@ -63,14 +65,14 @@ + placeholder="PIN" name="newpin" required show-focus="!secondPin">
    + placeholder="Confirm your PIN" name="repeatpin" required show-focus="secondPin">
    @@ -80,23 +82,22 @@ -
    -

    Enter your PIN number

    +
    +

    Enter your PIN

    @@ -129,7 +130,7 @@
    -
    +

    Sign in to Copay

    {{$root.title}} - + @@ -14,8 +14,7 @@ -