mirror of https://github.com/BTCPrivate/copay.git
add makePinInput
This commit is contained in:
parent
d3128137ce
commit
3627671307
|
@ -3,7 +3,7 @@
|
|||
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() {
|
||||
// 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,
|
||||
"pin", {
|
||||
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
|
||||
});
|
||||
pinService.makePinInput($scope, 'pin', function(newValue) {
|
||||
$scope.openPin(newValue);
|
||||
});
|
||||
|
||||
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
|
||||
});
|
||||
pinService.makePinInput($scope, 'newpin', function(newValue) {
|
||||
_firstpin = newValue;
|
||||
$scope.askForPin = 2;
|
||||
});
|
||||
|
||||
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 = 'Entered PINs were not equal. Try again';
|
||||
}
|
||||
}
|
||||
if (!newValue) {
|
||||
$scope.error = null;
|
||||
}
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
pinService.makePinInput($scope, 'repeatpin', function(newValue) {
|
||||
if (newValue === _firstpin) {
|
||||
_firstpin = null;
|
||||
$scope.createPin(newValue);
|
||||
} else {
|
||||
_firstpin = null;
|
||||
$scope.error = 'Entered PINs were not equal. Try again';
|
||||
}
|
||||
});
|
||||
|
||||
$scope.done = function() {
|
||||
$rootScope.starting = false;
|
||||
|
@ -131,14 +93,15 @@ angular.module('copayApp.controllers').controller('HomeController', function($sc
|
|||
iden.openWallets();
|
||||
};
|
||||
|
||||
$scope.createPin = function(form) {
|
||||
if (!form) return;
|
||||
$scope.createPin = function(pin) {
|
||||
preconditions.checkArgument(pin);
|
||||
preconditions.checkState($rootScope.iden);
|
||||
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 = null;
|
||||
$scope.askForPin = 0;
|
||||
$rootScope.hasPin = true;
|
||||
$scope.openWallets();
|
||||
});
|
||||
|
@ -197,7 +160,7 @@ angular.module('copayApp.controllers').controller('HomeController', function($sc
|
|||
email: email,
|
||||
password: password,
|
||||
};
|
||||
$scope.askForPin = true;
|
||||
$scope.askForPin = 1;
|
||||
$rootScope.starting = false;
|
||||
$rootScope.hideNavigation = true;
|
||||
$rootScope.$digest();
|
||||
|
|
|
@ -48,5 +48,24 @@ angular.module('copayApp.services')
|
|||
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;
|
||||
});
|
||||
|
|
|
@ -47,7 +47,7 @@
|
|||
<a class="text-white" href="#!/createProfile">creating your profile</a>
|
||||
</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>
|
||||
<p class="size-14"> Enter a 4-digit number for easier access from this device
|
||||
|
||||
|
@ -61,18 +61,18 @@
|
|||
</div>
|
||||
|
||||
<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"
|
||||
ng-maxlength="4" ng-minlength="4" maxlength="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>
|
||||
</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"
|
||||
ng-maxlength="4" ng-minlength="4" maxlength="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>
|
||||
</div>
|
||||
|
||||
|
|
Loading…
Reference in New Issue