add makePinInput

This commit is contained in:
Matias Alejo Garcia 2014-12-03 13:44:55 -03:00 committed by Gustavo Maximiliano Cortez
parent d3128137ce
commit 3627671307
3 changed files with 46 additions and 64 deletions

View File

@ -3,7 +3,7 @@
angular.module('copayApp.controllers').controller('HomeController', function($scope, $rootScope, $location, $timeout, notification, identityService, Compatibility, pinService, applicationService, isMobile) { angular.module('copayApp.controllers').controller('HomeController', function($scope, $rootScope, $location, $timeout, notification, identityService, Compatibility, pinService, applicationService, isMobile) {
var _credentials; var _credentials, _firstpin;
$scope.init = function() { $scope.init = function() {
// This is only for backwards compat, insight api should link to #!/confirmed directly // This is only for backwards compat, insight api should link to #!/confirmed directly
@ -28,62 +28,24 @@ angular.module('copayApp.controllers').controller('HomeController', function($sc
}); });
}; };
Object.defineProperty($scope, pinService.makePinInput($scope, 'pin', function(newValue) {
"pin", { $scope.openPin(newValue);
get: function() { });
return this._pin;
},
set: function(newValue) {
this._pin = newValue;
if (newValue && newValue.length == 4) {
$scope.openPin(newValue);
}
if (!newValue) {
$scope.error = null;
}
},
enumerable: true,
configurable: true
});
Object.defineProperty($scope, pinService.makePinInput($scope, 'newpin', function(newValue) {
"newpin", { _firstpin = newValue;
get: function() { $scope.askForPin = 2;
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, pinService.makePinInput($scope, 'repeatpin', function(newValue) {
"repeatpin", { if (newValue === _firstpin) {
get: function() { _firstpin = null;
return this._repeatpin; $scope.createPin(newValue);
}, } else {
set: function(newValue) { _firstpin = null;
this._repeatpin = newValue; $scope.error = 'Entered PINs were not equal. Try again';
if (newValue && newValue.length == 4) { }
if ($scope.$$childTail._newpin === newValue) { });
// save and submit
$scope.createPin($scope.$$childTail.setPinForm);
} else {
$scope.error = 'Entered PINs were not equal. Try again';
}
}
if (!newValue) {
$scope.error = null;
}
},
enumerable: true,
configurable: true
});
$scope.done = function() { $scope.done = function() {
$rootScope.starting = false; $rootScope.starting = false;
@ -131,14 +93,15 @@ angular.module('copayApp.controllers').controller('HomeController', function($sc
iden.openWallets(); iden.openWallets();
}; };
$scope.createPin = function(form) { $scope.createPin = function(pin) {
if (!form) return; preconditions.checkArgument(pin);
preconditions.checkState($rootScope.iden); preconditions.checkState($rootScope.iden);
preconditions.checkState(_credentials && _credentials.email); preconditions.checkState(_credentials && _credentials.email);
pinService.save(form.repeatpin.$modelValue, _credentials.email, _credentials.password, function(err) { pinService.save(pin, _credentials.email, _credentials.password, function(err) {
_credentials.password = ''; _credentials.password = '';
_credentials = null; _credentials = null;
$scope.askForPin = 0;
$rootScope.hasPin = true; $rootScope.hasPin = true;
$scope.openWallets(); $scope.openWallets();
}); });
@ -197,7 +160,7 @@ angular.module('copayApp.controllers').controller('HomeController', function($sc
email: email, email: email,
password: password, password: password,
}; };
$scope.askForPin = true; $scope.askForPin = 1;
$rootScope.starting = false; $rootScope.starting = false;
$rootScope.hideNavigation = true; $rootScope.hideNavigation = true;
$rootScope.$digest(); $rootScope.$digest();

View File

@ -48,5 +48,24 @@ angular.module('copayApp.services')
ls.removeItem(KEY, cb); ls.removeItem(KEY, cb);
}; };
root.makePinInput = function(scope, name, cb) {
Object.defineProperty(scope, name, {
get: function() {
return this['_' + name];
},
set: function(newValue) {
this['_' + name] = newValue;
scope.error = null;
if (newValue && newValue.length == 4) {
return cb(newValue);
}
},
enumerable: true,
configurable: true
});
};
return root; return root;
}); });

View File

@ -47,7 +47,7 @@
<a class="text-white" href="#!/createProfile">creating your profile</a> <a class="text-white" href="#!/createProfile">creating your profile</a>
</div> </div>
<div class="box-setup" ng-if="askForPin" ng-init="secondPin = false"> <div class="box-setup" ng-if="askForPin">
<h1><span translate>Set up a </span> <b> PIN </b>?</h1> <h1><span translate>Set up a </span> <b> PIN </b>?</h1>
<p class="size-14"> Enter a 4-digit number for easier access from this device <p class="size-14"> Enter a 4-digit number for easier access from this device
@ -61,18 +61,18 @@
</div> </div>
<form name="setPinForm" ng-submit="createPin(setPinForm)" novalidate> <form name="setPinForm" ng-submit="createPin(setPinForm)" novalidate>
<div class="input" ng-show="!secondPin"> <div class="input" ng-show="askForPin == 1">
<input id="newpin" type="tel" ng-model="newpin" class="form-control" <input id="newpin" type="tel" ng-model="newpin" class="form-control"
ng-maxlength="4" ng-minlength="4" maxlength="4" ng-maxlength="4" ng-minlength="4" maxlength="4"
ng-pattern="/^[0-9]{1,4}$/" ng-pattern="/^[0-9]{1,4}$/"
placeholder="PIN" name="newpin" required show-focus="!secondPin"> placeholder="PIN" name="newpin" required show-focus="askForPin == 1">
<i class="icon-locked"></i> <i class="icon-locked"></i>
</div> </div>
<div class="input" ng-show="secondPin"> <div class="input" ng-show="askForPin == 2">
<input id="repeatpin" type="tel" ng-model="repeatpin" class="form-control" <input id="repeatpin" type="tel" ng-model="repeatpin" class="form-control"
ng-maxlength="4" ng-minlength="4" maxlength="4" ng-maxlength="4" ng-minlength="4" maxlength="4"
ng-pattern="/^[0-9]{1,4}$/" ng-pattern="/^[0-9]{1,4}$/"
placeholder="Confirm your PIN" name="repeatpin" required show-focus="secondPin"> placeholder="Confirm your PIN" name="repeatpin" required show-focus="askForPin == 2">
<i class="icon-locked"></i> <i class="icon-locked"></i>
</div> </div>