add crypto to pinService and tests

This commit is contained in:
Matias Alejo Garcia 2014-12-02 22:38:33 -03:00 committed by Gustavo Maximiliano Cortez
commit 65512bf1c2
4 changed files with 129 additions and 62 deletions

View file

@ -15,7 +15,9 @@ angular.module('copayApp.controllers').controller('HomeController', function($sc
$rootScope.fromEmailConfirmation = false;
}
Compatibility.check($scope);
$scope.hasPin = pinService.check();
pinService.check(function(err, value) {
$scope.hasPin = value;
});
};
Object.defineProperty($scope,
@ -23,24 +25,21 @@ angular.module('copayApp.controllers').controller('HomeController', function($sc
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
set: function(newValue) {
this._pin = newValue;
if (newValue && newValue.length == 4) {
$scope.openPin(newValue);
}
if (!newValue) {
$scope.error = null;
}
},
enumerable: true,
configurable: true
});
$scope.done = function() {
$scope.hasPin = pinService.check();
$rootScope.starting = false;
$rootScope.$digest();
};
@ -49,8 +48,8 @@ angular.module('copayApp.controllers').controller('HomeController', function($sc
$scope.$on("$destroy", function() {
var iden = $rootScope.iden;
if (iden) {
iden.removeListener('newWallet', $scope.done );
iden.removeListener('noWallets', $scope.done );
iden.removeListener('newWallet', $scope.done);
iden.removeListener('noWallets', $scope.done);
}
});
@ -60,25 +59,26 @@ angular.module('copayApp.controllers').controller('HomeController', function($sc
$scope.error = 'Please enter the required fields';
return;
}
$scope.openPin(pin);
$scope.openPin(pin);
};
$scope.openPin = function(pin) {
var credentials = pinService.get(parseInt(pin));
if (!credentials) {
$scope.error = 'Wrong PIN';
return;
}
$rootScope.starting = true;
$scope.open(credentials.email, credentials.password);
var credentials = pinService.get(pin, function(err, credentials) {
if (err || !credentials) {
$scope.error = 'Wrong PIN';
return;
}
$rootScope.starting = true;
$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);
if (!form) return;
pinService.save(form.repeatpin.$modelValue, $scope.email, $scope.password, function(err) {
$scope.open($scope.email, $scope.password);
});
};
$scope.openWithCredentials = function(form) {
@ -96,6 +96,15 @@ angular.module('copayApp.controllers').controller('HomeController', function($sc
$scope.open(form.email.$modelValue, form.password.$modelValue);
};
$scope.pinLogout = function() {
pinService.clear(function() {
copay.logger.debug('PIN erased');
$scope.hasPin = null;
$scope.$digest();
});
};
$scope.open = function(email, password) {
$rootScope.starting = true;
identityService.open(email, password, function(err, iden) {
@ -104,7 +113,9 @@ angular.module('copayApp.controllers').controller('HomeController', function($sc
copay.logger.warn(err);
if ((err.toString() || '').match('PNOTFOUND')) {
$scope.error = 'Invalid email or password';
pinService.clear();
pinService.clear(function() {
copay.logger.debug('PIN erased');
});
} else if ((err.toString() || '').match('Connection')) {
$scope.error = 'Could not connect to Insight Server';
} else if ((err.toString() || '').match('Unable')) {