copay/js/controllers/signin.js

55 lines
1.9 KiB
JavaScript
Raw Normal View History

'use strict';
angular.module('copay.signin').controller('SigninController',
2014-05-01 10:21:55 -07:00
function($scope, $rootScope, $location, walletFactory, controllerUtils, Passphrase) {
$scope.loading = false;
$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-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 10:21:55 -07:00
var passphrase = Passphrase.getBase64($scope.openPassword);
var w = walletFactory.open($scope.selectedWalletId, { passphrase: passphrase});
controllerUtils.startNetwork(w);
}
};
2014-05-01 10:21:55 -07:00
$scope.join = function() {
$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-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;
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'};
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
});
};
});