2014-03-27 12:31:42 -07:00
|
|
|
'use strict';
|
|
|
|
|
2014-03-28 11:08:14 -07:00
|
|
|
angular.module('copay.signin').controller('SigninController',
|
2014-05-01 10:21:55 -07:00
|
|
|
function($scope, $rootScope, $location, walletFactory, controllerUtils, Passphrase) {
|
2014-03-31 08:48:35 -07:00
|
|
|
$scope.loading = false;
|
2014-04-24 12:35:52 -07:00
|
|
|
$scope.wallets = walletFactory.getWallets();
|
|
|
|
$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-05-01 10:21:55 -07:00
|
|
|
$scope.create = function() {
|
2014-04-24 18:43:19 -07:00
|
|
|
$scope.loading = true;
|
2014-05-01 10:21:55 -07:00
|
|
|
|
|
|
|
$rootScope.walletName = $scope.walletName;
|
|
|
|
$rootScope.walletPassword = $scope.createPassword;
|
2014-04-16 15:45:22 -07:00
|
|
|
$location.path('setup');
|
2014-04-16 13:50:10 -07:00
|
|
|
};
|
2014-04-15 11:25:55 -07:00
|
|
|
|
2014-05-01 10:21:55 -07:00
|
|
|
$scope.open = function() {
|
|
|
|
if ($scope.openPassword != '') {
|
|
|
|
$scope.loading = true;
|
2014-05-01 05:59:43 -07:00
|
|
|
|
2014-05-01 10:21:55 -07:00
|
|
|
var passphrase = Passphrase.getBase64($scope.openPassword);
|
|
|
|
var w = walletFactory.open($scope.selectedWalletId, { passphrase: passphrase});
|
|
|
|
controllerUtils.startNetwork(w);
|
|
|
|
}
|
2014-04-08 22:20:28 -07:00
|
|
|
};
|
|
|
|
|
2014-05-01 10:21:55 -07:00
|
|
|
$scope.join = function() {
|
2014-03-31 08:48:35 -07:00
|
|
|
$scope.loading = true;
|
2014-04-20 08:41:28 -07:00
|
|
|
|
2014-04-30 08:58:40 -07:00
|
|
|
walletFactory.network.on('badSecret', function() {
|
2014-04-17 12:27:15 -07:00
|
|
|
});
|
2014-04-20 08:41:28 -07:00
|
|
|
|
2014-05-01 10:21:55 -07:00
|
|
|
walletFactory.joinCreateSession($scope.connectionId, $scope.nickname, function(err,w) {
|
2014-04-30 08:58:40 -07:00
|
|
|
$scope.loading = false;
|
|
|
|
|
2014-05-01 12:28:07 -07:00
|
|
|
if (err || !w || !$scope.joinPassword) {
|
2014-04-30 08:58:40 -07:00
|
|
|
if (err === 'joinError')
|
|
|
|
$rootScope.flashMessage = { message: 'Can not find peer'};
|
|
|
|
else if (err === 'badSecret')
|
|
|
|
$rootScope.flashMessage = { message: 'Bad secret secret string', type: 'error'};
|
2014-05-01 12:28:07 -07:00
|
|
|
else if (!$scope.joinPassword)
|
|
|
|
$rootScope.flashMessage = { message: 'Enter your wallet password', type: 'error' };
|
2014-04-30 08:58:40 -07:00
|
|
|
else
|
|
|
|
$rootScope.flashMessage = { message: 'Unknown error', type: 'error'};
|
|
|
|
controllerUtils.onErrorDigest();
|
2014-05-01 10:21:55 -07:00
|
|
|
} else {
|
|
|
|
var passphrase = Passphrase.getBase64($scope.joinPassword);
|
|
|
|
w.storage._setPassphrase(passphrase);
|
2014-04-30 08:58:40 -07:00
|
|
|
controllerUtils.startNetwork(w);
|
2014-05-01 10:21:55 -07:00
|
|
|
}
|
2014-04-16 16:58:57 -07:00
|
|
|
});
|
|
|
|
};
|
2014-03-27 12:31:42 -07:00
|
|
|
});
|