2014-03-27 12:31:42 -07:00
|
|
|
'use strict';
|
|
|
|
|
2014-06-03 13:42:36 -07:00
|
|
|
angular.module('copayApp.controllers').controller('SigninController',
|
2014-06-26 14:37:30 -07:00
|
|
|
function($scope, $rootScope, $location, walletFactory, controllerUtils, Passphrase, backupService, notification) {
|
2014-06-16 12:46:17 -07:00
|
|
|
var cmp = function(o1, o2) {
|
|
|
|
var v1 = o1.show.toLowerCase(),
|
|
|
|
v2 = o2.show.toLowerCase();
|
|
|
|
return v1 > v2 ? 1 : (v1 < v2) ? -1 : 0;
|
2014-05-15 11:22:53 -07:00
|
|
|
};
|
2014-05-16 14:33:06 -07:00
|
|
|
$rootScope.videoInfo = {};
|
2014-06-07 15:12:24 -07:00
|
|
|
$scope.loading = false;
|
2014-05-15 11:22:53 -07:00
|
|
|
$scope.wallets = walletFactory.getWallets().sort(cmp);
|
2014-04-24 12:35:52 -07:00
|
|
|
$scope.selectedWalletId = $scope.wallets.length ? $scope.wallets[0].id : null;
|
2014-05-01 10:21:55 -07:00
|
|
|
$scope.openPassword = '';
|
2014-04-08 22:20:28 -07:00
|
|
|
|
2014-07-02 13:35:37 -07:00
|
|
|
if ($rootScope.pendingPayment) {
|
|
|
|
notification.info('Login Required', 'Please open wallet to complete payment');
|
|
|
|
}
|
|
|
|
|
2014-05-06 10:39:16 -07:00
|
|
|
$scope.open = function(form) {
|
2014-05-06 10:46:26 -07:00
|
|
|
if (form && form.$invalid) {
|
2014-06-26 13:22:41 -07:00
|
|
|
notification.error('Error', 'Please enter the required fields');
|
2014-05-06 10:39:16 -07:00
|
|
|
return;
|
2014-05-01 10:21:55 -07:00
|
|
|
}
|
2014-06-16 12:46:17 -07:00
|
|
|
|
2014-05-06 10:39:16 -07:00
|
|
|
$scope.loading = true;
|
|
|
|
var password = form.openPassword.$modelValue;
|
2014-05-16 14:33:06 -07:00
|
|
|
|
2014-06-16 12:46:17 -07:00
|
|
|
Passphrase.getBase64Async(password, function(passphrase) {
|
2014-06-03 11:03:14 -07:00
|
|
|
var w, errMsg;
|
2014-06-16 12:46:17 -07:00
|
|
|
try {
|
|
|
|
var w = walletFactory.open($scope.selectedWalletId, {
|
|
|
|
passphrase: passphrase
|
|
|
|
});
|
|
|
|
} catch (e) {
|
2014-06-03 11:03:14 -07:00
|
|
|
errMsg = e.message;
|
|
|
|
};
|
2014-05-07 14:48:56 -07:00
|
|
|
if (!w) {
|
2014-06-07 15:12:24 -07:00
|
|
|
$scope.loading = false;
|
2014-06-26 13:22:41 -07:00
|
|
|
notification.error('Error', errMsg || 'Wrong password');
|
2014-05-08 06:03:32 -07:00
|
|
|
$rootScope.$digest();
|
2014-05-07 14:48:56 -07:00
|
|
|
return;
|
|
|
|
}
|
2014-06-12 07:03:24 -07:00
|
|
|
controllerUtils.startNetwork(w, $scope);
|
2014-05-07 14:48:56 -07:00
|
|
|
});
|
2014-04-08 22:20:28 -07:00
|
|
|
};
|
|
|
|
|
2014-05-06 10:39:16 -07:00
|
|
|
$scope.join = function(form) {
|
2014-05-06 10:46:26 -07:00
|
|
|
if (form && form.$invalid) {
|
2014-06-26 13:22:41 -07:00
|
|
|
notification.error('Error', 'Please enter the required fields');
|
2014-05-06 10:39:16 -07:00
|
|
|
return;
|
|
|
|
}
|
2014-04-20 08:41:28 -07:00
|
|
|
|
2014-05-07 14:48:56 -07:00
|
|
|
$scope.loading = true;
|
2014-06-16 12:46:17 -07:00
|
|
|
walletFactory.network.on('badSecret', function() {});
|
2014-04-20 08:41:28 -07:00
|
|
|
|
2014-06-16 12:46:17 -07:00
|
|
|
Passphrase.getBase64Async($scope.joinPassword, function(passphrase) {
|
|
|
|
walletFactory.joinCreateSession($scope.connectionId, $scope.nickname, passphrase, function(err, w) {
|
2014-05-07 14:48:56 -07:00
|
|
|
$scope.loading = false;
|
|
|
|
if (err || !w) {
|
2014-06-16 12:46:17 -07:00
|
|
|
if (err === 'joinError')
|
2014-06-26 13:22:41 -07:00
|
|
|
notification.error('Can\'t find peer.');
|
2014-05-19 16:47:28 -07:00
|
|
|
else if (err === 'walletFull')
|
2014-06-26 13:22:41 -07:00
|
|
|
notification.error('The wallet is full');
|
2014-06-09 17:00:28 -07:00
|
|
|
else if (err === 'badNetwork')
|
2014-06-26 13:22:41 -07:00
|
|
|
notification.error('Network Error', 'The wallet your are trying to join uses a different Bitcoin Network. Check your settings.');
|
2014-06-16 12:46:17 -07:00
|
|
|
else if (err === 'badSecret')
|
2014-06-26 13:22:41 -07:00
|
|
|
notification.error('Bad secret', 'The secret string you entered is invalid');
|
2014-06-16 12:46:17 -07:00
|
|
|
else
|
2014-06-26 13:22:41 -07:00
|
|
|
notification.error('Unknown error');
|
2014-06-06 08:30:50 -07:00
|
|
|
controllerUtils.onErrorDigest();
|
2014-05-07 14:48:56 -07:00
|
|
|
} else {
|
2014-06-16 12:46:17 -07:00
|
|
|
controllerUtils.startNetwork(w, $scope);
|
2014-05-07 14:48:56 -07:00
|
|
|
}
|
|
|
|
});
|
2014-04-16 16:58:57 -07:00
|
|
|
});
|
2014-05-15 17:16:26 -07:00
|
|
|
}
|
2014-03-27 12:31:42 -07:00
|
|
|
});
|