New PIN page
This commit is contained in:
parent
77f8faaae6
commit
36bd87f729
9 changed files with 233 additions and 184 deletions
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
angular.module('copayApp.controllers').controller('CreateProfileController', function($scope, $rootScope, $location, $timeout, $window, notification, pluginManager, identityService, pinService, isMobile, isCordova, configService, go) {
|
||||
|
||||
var _credentials, _firstpin;
|
||||
var _credentials;
|
||||
|
||||
$scope.init = function() {
|
||||
|
||||
|
|
@ -12,41 +12,27 @@ angular.module('copayApp.controllers').controller('CreateProfileController', fun
|
|||
$scope.isMobile = isMobile.any();
|
||||
$scope.isWindowsPhoneApp = isMobile.Windows() && isCordova;
|
||||
$scope.hideForWP = 0;
|
||||
|
||||
$scope.digits = [];
|
||||
$scope.defined = [];
|
||||
$rootScope.askForPin = 0;
|
||||
|
||||
$scope.createStep = 'storage';
|
||||
$scope.useLocalstorage = false;
|
||||
$scope.minPasswordStrength = _.isUndefined(config.minPasswordStrength) ?
|
||||
4 : config.minPasswordStrength;
|
||||
|
||||
};
|
||||
|
||||
pinService.makePinInput($scope, 'newpin', function(newValue) {
|
||||
_firstpin = newValue;
|
||||
$scope.hideForWP = 0;
|
||||
$scope.askForPin = 2;
|
||||
$timeout(function() {
|
||||
$scope.$digest();
|
||||
}, 1);
|
||||
$scope.clear = function() {
|
||||
pinService.clearPin($scope);
|
||||
};
|
||||
|
||||
$scope.press = function(digit) {
|
||||
pinService.pressPin($scope, digit, true);
|
||||
};
|
||||
|
||||
});
|
||||
|
||||
pinService.makePinInput($scope, 'repeatpin', function(newValue) {
|
||||
if (newValue === _firstpin) {
|
||||
_firstpin = null;
|
||||
$scope.createPin(newValue);
|
||||
} else {
|
||||
$scope.askForPin = 1;
|
||||
$scope.hideForWP = 0;
|
||||
$scope.passwordStrength = null;
|
||||
|
||||
_firstpin = null;
|
||||
$scope.error = 'Entered PINs were not equal. Try again';
|
||||
$timeout(function() {
|
||||
$scope.$digest();
|
||||
}, 1);
|
||||
}
|
||||
});
|
||||
$scope.skip = function () {
|
||||
pinService.skipPin($scope, true);
|
||||
};
|
||||
|
||||
$scope.formFocus = function() {
|
||||
|
|
@ -63,14 +49,11 @@ angular.module('copayApp.controllers').controller('CreateProfileController', fun
|
|||
preconditions.checkState(_credentials && _credentials.email);
|
||||
$rootScope.starting = true;
|
||||
|
||||
// hide Keyboard after submit form
|
||||
$window.document.querySelector('#repeatpin').blur();
|
||||
|
||||
$timeout(function() {
|
||||
pinService.save(pin, _credentials.email, _credentials.password, function(err) {
|
||||
_credentials.password = '';
|
||||
_credentials = null;
|
||||
$scope.askForPin = 0;
|
||||
$rootScope.askForPin = 0;
|
||||
$rootScope.hasPin = true;
|
||||
$scope.createDefaultWallet();
|
||||
});
|
||||
|
|
@ -117,7 +100,7 @@ angular.module('copayApp.controllers').controller('CreateProfileController', fun
|
|||
$rootScope.hideNavigation = false;
|
||||
$rootScope.starting = true;
|
||||
identityService.createDefaultWallet(function(err) {
|
||||
$scope.askForPin = 0;
|
||||
$rootScope.askForPin = 0;
|
||||
$rootScope.starting = null;
|
||||
|
||||
if (err) {
|
||||
|
|
@ -157,7 +140,7 @@ angular.module('copayApp.controllers').controller('CreateProfileController', fun
|
|||
email: emailOrUsername,
|
||||
password: password,
|
||||
};
|
||||
$scope.askForPin = 1;
|
||||
$rootScope.askForPin = 1;
|
||||
$scope.hideForWP = 0;
|
||||
|
||||
$rootScope.hideNavigation = true;
|
||||
|
|
|
|||
|
|
@ -1,15 +1,19 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('HomeController', function($scope, $rootScope, $timeout, $window, go, notification, identityService, Compatibility, pinService, applicationService, isMobile, isCordova, localstorageService) {
|
||||
angular.module('copayApp.controllers').controller('HomeController', function($scope, $rootScope, $timeout, $window, go, notification, identityService, Compatibility, pinService, applicationService, isMobile, isCordova, localstorageService) {
|
||||
|
||||
var KEY = 'CopayDisclaimer';
|
||||
var ls = localstorageService;
|
||||
var _credentials, _firstpin;
|
||||
var _credentials;
|
||||
|
||||
$scope.init = function() {
|
||||
$scope.isMobile = isMobile.any();
|
||||
$scope.isWindowsPhoneApp = isMobile.Windows() && isCordova;
|
||||
$scope.hideForWP = 0;
|
||||
$scope.attempt = 0;
|
||||
$scope.attempt = 0;
|
||||
$scope.digits = [];
|
||||
$scope.defined = [];
|
||||
$rootScope.askForPin = 0;
|
||||
|
||||
// This is only for backwards compat, insight api should link to #!/confirmed directly
|
||||
if (getParam('confirmed')) {
|
||||
|
|
@ -40,6 +44,18 @@ angular.module('copayApp.controllers').controller('HomeController', function($sc
|
|||
}
|
||||
};
|
||||
|
||||
$scope.clear = function() {
|
||||
pinService.clearPin($scope);
|
||||
};
|
||||
|
||||
$scope.press = function(digit) {
|
||||
pinService.pressPin($scope, digit);
|
||||
};
|
||||
|
||||
$scope.skip = function () {
|
||||
pinService.skipPin($scope);
|
||||
};
|
||||
|
||||
$scope.agreeDisclaimer = function() {
|
||||
ls.setItem(KEY, true, function(err) {
|
||||
$scope.showDisclaimer = null;
|
||||
|
|
@ -55,31 +71,6 @@ angular.module('copayApp.controllers').controller('HomeController', function($sc
|
|||
}
|
||||
};
|
||||
|
||||
pinService.makePinInput($scope, 'pin', function(newValue) {
|
||||
$scope.openWithPin(newValue);
|
||||
});
|
||||
|
||||
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.$$childTail.setPinForm.newpin.$setViewValue('');
|
||||
$scope.$$childTail.setPinForm.newpin.$render();
|
||||
$scope.$$childTail.setPinForm.repeatpin.$setViewValue('');
|
||||
$scope.$$childTail.setPinForm.repeatpin.$render();
|
||||
|
||||
_firstpin = null;
|
||||
$scope.askForPin = 1;
|
||||
$scope.error = 'Entered PINs were not equal. Try again';
|
||||
}
|
||||
});
|
||||
|
||||
$scope.openWithPin = function(pin) {
|
||||
|
||||
if (!pin) {
|
||||
|
|
@ -88,14 +79,15 @@ angular.module('copayApp.controllers').controller('HomeController', function($sc
|
|||
}
|
||||
$rootScope.starting = true;
|
||||
|
||||
// hide Keyboard after submit form
|
||||
$window.document.querySelector('#pin').blur();
|
||||
|
||||
$timeout(function() {
|
||||
var credentials = pinService.get(pin, function(err, credentials) {
|
||||
if (err || !credentials) {
|
||||
$rootScope.starting = null;
|
||||
$scope.error = 'Wrong PIN';
|
||||
$scope.clear();
|
||||
$timeout(function() {
|
||||
$scope.error = null;
|
||||
}, 2000);
|
||||
return;
|
||||
}
|
||||
$scope.open(credentials.email, credentials.password);
|
||||
|
|
@ -117,14 +109,11 @@ angular.module('copayApp.controllers').controller('HomeController', function($sc
|
|||
preconditions.checkState(_credentials && _credentials.email);
|
||||
$rootScope.starting = true;
|
||||
|
||||
// hide Keyboard after submit form
|
||||
$window.document.querySelector('#repeatpin').blur();
|
||||
|
||||
$timeout(function() {
|
||||
pinService.save(pin, _credentials.email, _credentials.password, function(err) {
|
||||
_credentials.password = '';
|
||||
_credentials = null;
|
||||
$scope.askForPin = 0;
|
||||
$rootScope.askForPin = 0;
|
||||
$rootScope.hasPin = true;
|
||||
$rootScope.starting = null;
|
||||
$scope.openWallets();
|
||||
|
|
@ -194,7 +183,7 @@ angular.module('copayApp.controllers').controller('HomeController', function($sc
|
|||
email: email,
|
||||
password: password,
|
||||
};
|
||||
$scope.askForPin = 1;
|
||||
$rootScope.askForPin = 1;
|
||||
$rootScope.starting = false;
|
||||
$rootScope.hideNavigation = true;
|
||||
$timeout(function() {
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@ angular.module('copayApp.services')
|
|||
var ls = localstorageService;
|
||||
var root = {};
|
||||
|
||||
var _firstpin;
|
||||
|
||||
root.check = function(cb) {
|
||||
ls.getItem(KEY, function(err, value) {
|
||||
return cb(err, value ? true : false);
|
||||
|
|
@ -48,27 +50,61 @@ 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;
|
||||
scope.loading = null;
|
||||
if (newValue && newValue.length == 4) {
|
||||
$timeout(function() {
|
||||
return cb(newValue);
|
||||
}, 30);
|
||||
}
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
root.clearPin = function(scope) {
|
||||
scope.digits = [];
|
||||
scope.defined = [];
|
||||
};
|
||||
|
||||
root.pressPin = function(scope, digit, skipOpenWithPin) {
|
||||
scope.error = null;
|
||||
scope.digits.push(digit);
|
||||
scope.defined.push(true);
|
||||
if (scope.digits.length == 4) {
|
||||
var pin = scope.digits.join('');
|
||||
if (!$rootScope.hasPin) {
|
||||
if (!_firstpin) {
|
||||
_firstpin = pin;
|
||||
$timeout(function() {
|
||||
scope.clear();
|
||||
}, 100);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
if (pin === _firstpin) {
|
||||
scope.createPin(pin);
|
||||
}
|
||||
else {
|
||||
_firstpin = null;
|
||||
$timeout(function() {
|
||||
scope.clear();
|
||||
scope.error = 'Entered PINs were not equal. Try again';
|
||||
$timeout(function() {
|
||||
scope.error = null;
|
||||
}, 2000);
|
||||
}, 100);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!skipOpenWithPin) {
|
||||
scope.openWithPin(pin);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
root.skipPin = function(scope, creatingProfile) {
|
||||
if (!$rootScope.hasPin) {
|
||||
if (!creatingProfile) {
|
||||
scope.openWallets();
|
||||
}
|
||||
else {
|
||||
scope.createDefaultWallet()
|
||||
}
|
||||
}
|
||||
else {
|
||||
scope.pinLogout();
|
||||
}
|
||||
};
|
||||
|
||||
return root;
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue