pin in create
This commit is contained in:
parent
2f6e28f5e7
commit
1d7e9dda93
5 changed files with 201 additions and 58 deletions
|
|
@ -1,23 +1,80 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('CreateProfileController', function($scope, $rootScope, $location, $timeout, notification, pluginManager, identityService) {
|
||||
identityService.goWalletHome();
|
||||
angular.module('copayApp.controllers').controller('CreateProfileController', function($scope, $rootScope, $location, $timeout, notification, pluginManager, identityService, pinService) {
|
||||
|
||||
var _credentials, _firstpin;
|
||||
|
||||
$scope.init = function() {
|
||||
identityService.goWalletHome();
|
||||
|
||||
pinService.makePinInput($scope, 'newpin', function(newValue) {
|
||||
_firstpin = newValue;
|
||||
$scope.askForPin = 2;
|
||||
});
|
||||
|
||||
pinService.makePinInput($scope, 'repeatpin', function(newValue) {
|
||||
if (newValue === _firstpin) {
|
||||
_firstpin = null;
|
||||
$scope.createPin(newValue);
|
||||
} else {
|
||||
$scope.askForPin = 1;
|
||||
_firstpin = null;
|
||||
|
||||
$scope.setPinForm.newpin.$setViewValue('');
|
||||
$scope.setPinForm.newpin.$render();
|
||||
$scope.setPinForm.repeatpin.$setViewValue('');
|
||||
$scope.setPinForm.repeatpin.$render();
|
||||
$scope.setPinForm.$setPristine();
|
||||
|
||||
$scope.error = 'Entered PINs were not equal. Try again';
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
$scope.createPin = function(pin) {
|
||||
preconditions.checkArgument(pin);
|
||||
preconditions.checkState($rootScope.iden);
|
||||
preconditions.checkState(_credentials && _credentials.email);
|
||||
|
||||
pinService.save(pin, _credentials.email, _credentials.password, function(err) {
|
||||
_credentials.password = '';
|
||||
_credentials = null;
|
||||
$scope.askForPin = 0;
|
||||
$rootScope.hasPin = true;
|
||||
$scope.createDefaultWallet();
|
||||
});
|
||||
};
|
||||
|
||||
$scope.createDefaultWallet = function() {
|
||||
$rootScope.hideNavigation = false;
|
||||
identityService.createDefaultWallet(function(err) {
|
||||
$scope.askForPin =0 ;
|
||||
$scope.loading = false;
|
||||
|
||||
if (err) {
|
||||
var msg = err.toString();
|
||||
$scope.error = msg;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
$scope.createProfile = function(form) {
|
||||
$rootScope.hideNavigation = false;
|
||||
if (form && form.$invalid) {
|
||||
$scope.error('Error', 'Please enter the required fields');
|
||||
$scope.error = 'Please enter the required fields';
|
||||
return;
|
||||
}
|
||||
$rootScope.starting = true;
|
||||
identityService.create(
|
||||
form.email.$modelValue, form.password.$modelValue, function(err) {
|
||||
$rootScope.starting = false;
|
||||
if (err) {
|
||||
var msg = err.toString();
|
||||
if (msg.indexOf('EEXIST')>=0 || msg.indexOf('BADC')>=0 ) {
|
||||
msg = 'This profile already exists'
|
||||
}
|
||||
$timeout(function() {
|
||||
$scope.loading = true;
|
||||
identityService.create(form.email.$modelValue, form.password.$modelValue, function(err) {
|
||||
$scope.loading = false;
|
||||
|
||||
if (err) {
|
||||
var msg = err.toString();
|
||||
if (msg.indexOf('EEXIST') >= 0 || msg.indexOf('BADC') >= 0) {
|
||||
msg = 'This profile already exists'
|
||||
}
|
||||
$timeout(function() {
|
||||
form.email.$setViewValue('');
|
||||
form.email.$render();
|
||||
form.password.$setViewValue('');
|
||||
|
|
@ -27,7 +84,28 @@ angular.module('copayApp.controllers').controller('CreateProfileController', fun
|
|||
form.$setPristine();
|
||||
$scope.error = msg;
|
||||
},1);
|
||||
}
|
||||
$scope.error = msg;
|
||||
} else {
|
||||
$scope.error = null;
|
||||
// mobile
|
||||
//if (isMobile.any()) {
|
||||
if (true) {
|
||||
_credentials = {
|
||||
email: form.email.$modelValue,
|
||||
password: form.password.$modelValue,
|
||||
};
|
||||
$scope.askForPin = 1;
|
||||
$rootScope.hideNavigation = true;
|
||||
$timeout(function() {
|
||||
$rootScope.$digest();
|
||||
}, 1);
|
||||
|
||||
console.log('[createProfile.js.70]'); //TODO
|
||||
return;
|
||||
} else {
|
||||
$scope.createDefaultWallet();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue