Merge pull request #9 from matiu/bechi

Bechi
This commit is contained in:
Juan Ignacio Sosa Lopez 2014-12-05 15:24:42 -03:00
commit 508c3e53f1
13 changed files with 222 additions and 164 deletions

View File

@ -21,7 +21,6 @@
"socket.io-client": ">=1.0.0",
"ng-idle": "*",
"inherits": "~0.0.1",
"angular-load": "0.2.0",
"lodash": "~2.4.1",
"angular-gravatar": "*",
"angular-touch": "~1.3.0"

View File

@ -5,19 +5,22 @@ module.exports.TxProposals = require('./js/models/TxProposals');
module.exports.PrivateKey = require('./js/models/PrivateKey');
module.exports.HDPath = require('./js/models/HDPath');
module.exports.HDParams = require('./js/models/HDParams');
module.exports.crypto = require('./js/util/crypto');
module.exports.logger = require('./js/util/log');
module.exports.csv = require('./js/util/csv');
// components
var Async = module.exports.Async = require('./js/models/Async');
var Insight = module.exports.Insight = require('./js/models/Insight');
var RateService = module.exports.RateService = require('./js/models/RateService');
module.exports.Async = require('./js/models/Async');
module.exports.Insight = require('./js/models/Insight');
module.exports.RateService = require('./js/models/RateService');
module.exports.Identity = require('./js/models/Identity');
module.exports.Wallet = require('./js/models/Wallet');
module.exports.Compatibility = require('./js/models/Compatibility');
module.exports.PluginManager = require('./js/models/PluginManager');
module.exports.crypto = require('./js/util/crypto');
module.exports.logger = require('./js/util/log');
module.exports.csv = require('./js/util/csv');
module.exports.version = require('./version').version;
module.exports.commitHash = require('./version').commitHash;
module.exports.defaultConfig = require('./config');

View File

@ -2,16 +2,17 @@
var copay = require('copay');
var _ = require('lodash');
var config = defaultConfig;
var LS = require('../js/plugins/LocalStorage');
var ls = new LS();
var localConfig;
var defaults = JSON.parse(JSON.stringify(defaultConfig));
// TODO move this to configService !
var config = copay.defaultConfig;
ls.getItem('config', function(err, data) {
var localConfig;
try {
localConfig = JSON.parse(data);
} catch(e) {};
if (localConfig) {
var cmv = copay.version.split('.')[1];
var lmv = localConfig.version ? localConfig.version.split('.')[1] : '-1';
@ -38,12 +39,9 @@ var modules = [
'copayApp.directives',
];
if (Object.keys(config.plugins).length)
modules.push('angularLoad');
var copayApp = window.copayApp = angular.module('copayApp', modules);
var defaults = JSON.parse(JSON.stringify(copay.defaultConfig));
copayApp.value('defaults', defaults);
copayApp.config(function($sceDelegateProvider) {

View File

@ -1,6 +1,6 @@
'use strict';
angular.module('copayApp.controllers').controller('CreateProfileController', function($scope, $rootScope, $location, $timeout, notification, pluginManager, identityService, pinService, isMobile) {
angular.module('copayApp.controllers').controller('CreateProfileController', function($scope, $rootScope, $location, $timeout, notification, pluginManager, identityService, pinService, isMobile, configService) {
var _credentials, _firstpin;
@ -51,28 +51,27 @@ angular.module('copayApp.controllers').controller('CreateProfileController', fun
};
$scope.selectStorage = function (storage) {
$scope.setStep = function(step) {
$scope.error = null;
$scope.createStep = step;
$timeout(function() {
$scope.$digest();
}, 1);
};
$scope.selectStorage = function(storage) {
$scope.useLocalstorage = storage == 'local';
$timeout(function() {
$scope.$digest();
}, 1);
};
$scope.setStorage = function(useLocalstorage) {
console.log('[createProfile.js.53:useLocalstorage:]', useLocalstorage); //TODO
console.log('[createProfile.js.53:useLocalstorage:]', $scope.useLocalstorage); //TODO
//settingsService.save({...})
$scope.goToEmail = function() {
$scope.createStep = 'email';
$scope.useEmail = !useLocalstorage;
$scope.useLocalstorage = useLocalstorage;
$timeout(function() {
$scope.$digest();
}, 1);
$scope.useEmail = !$scope.useLocalstorage;
};
$scope.setEmailOrUsername = function(form) {
console.log('[createProfile.js.53:useLocalstorage:]', $scope.useLocalstorage); //TODO
$scope.userOrEmail = $scope.useLocalstorage ? form.username.$modelValue : form.email.$modelValue;
preconditions.checkState($scope.userOrEmail);
@ -97,32 +96,24 @@ angular.module('copayApp.controllers').controller('CreateProfileController', fun
});
};
$scope.createProfile = function(form) {
$rootScope.hideNavigation = false;
if (form && form.$invalid) {
$scope.error = 'Please enter the required fields';
return;
}
$scope.loading = true;
identityService.create( $scope.userOrEmail, form.password.$modelValue, function(err) {
$scope.loading = false;
$scope._doCreateProfile = function(emailOrUsername, password, cb) {
preconditions.checkArgument(_.isString(emailOrUsername));
preconditions.checkArgument(_.isString(password));
$rootScope.hideNavigation = false;
$scope.loading = true;
identityService.create(emailOrUsername, password, function(err) {
$scope.loading = false;
$scope.error = null;
if (err) {
var msg = err.toString();
if (msg.indexOf('EEXIST') >= 0 || msg.indexOf('BADC') >= 0) {
msg = 'This profile already exists'
}
$timeout(function() {
form.password.$setViewValue('');
form.password.$render();
form.repeatpassword.$setViewValue('');
form.repeatpassword.$render();
form.$setPristine();
$scope.error = msg;
}, 1);
$scope.error = msg;
} else {
$scope.error = null;
// mobile
if ($scope.isMobile) {
_credentials = {
@ -134,12 +125,47 @@ angular.module('copayApp.controllers').controller('CreateProfileController', fun
$timeout(function() {
$rootScope.$digest();
}, 1);
return;
} else {
$scope.createDefaultWallet();
}
}
return cb();
});
}
};
$scope.saveSettings = function(cb) {
var plugins = config.plugins;
plugins.EncryptedLocalStorage = false;
plugins.EncryptedInsightStorage = false;
var pluginName = $scope.useLocalstorage ? 'EncryptedLocalStorage' : 'EncryptedInsightStorage';
plugins[pluginName] = true;
configService.set({
plugins: plugins
}, cb);
};
$scope.createProfile = function(form) {
if (form && form.$invalid) {
$scope.error = 'Please enter the required fields';
return;
}
$scope.saveSettings(function(err) {
$scope._doCreateProfile($scope.userOrEmail, form.password.$modelValue, function(err) {
$timeout(function() {
form.password.$setViewValue('');
form.password.$render();
form.repeatpassword.$setViewValue('');
form.repeatpassword.$render();
form.$setPristine();
}, 1);
});
});
};
});

View File

@ -4,9 +4,9 @@ angular.module('copayApp.controllers').controller('HomeController', function($sc
var _credentials, _firstpin;
$scope.init = function() {
$scope.isMobile = isMobile.any();
$scope.attempt=0;
// This is only for backwards compat, insight api should link to #!/confirmed directly
if (getParam('confirmed')) {
@ -28,6 +28,7 @@ angular.module('copayApp.controllers').controller('HomeController', function($sc
pinService.check(function(err, value) {
$rootScope.hasPin = value;
});
$scope.usingLocalStorage = config.plugins.EncryptedLocalStorage;
};
pinService.makePinInput($scope, 'pin', function(newValue) {
@ -139,8 +140,13 @@ angular.module('copayApp.controllers').controller('HomeController', function($sc
copay.logger.warn(err);
if ((err.toString() || '').match('PNOTFOUND')) {
$scope.error = 'Invalid email or password';
if($scope.attempt++>1) {
var storage = $scope.usingLocalStorage ? 'this device storage' : 'cloud storage';
$scope.error = 'Invalid email or password. You are trying to sign in using ' + storage + '. Change it on settings is necessary.';
};
pinService.clear(function() {
copay.logger.debug('PIN erased');
});
} else if ((err.toString() || '').match('Connection')) {
$scope.error = 'Could not connect to Insight Server';
@ -150,7 +156,9 @@ angular.module('copayApp.controllers').controller('HomeController', function($sc
$scope.error = 'Unknown error';
}
$rootScope.starting = false;
$rootScope.$digest();
$timeout(function(){
$rootScope.$digest();
},1)
return;
}

View File

@ -64,8 +64,10 @@ angular.module('copayApp.controllers').controller('HomeWalletController', functi
$scope.$on("$destroy", function() {
var w = $rootScope.wallet;
removeWatch();
w.removeListener('txProposalEvent', _updateTxs);
if (w) {
removeWatch();
w.removeListener('txProposalEvent', _updateTxs);
};
});
$scope.setAlternativeAmount = function(w, tx, cb) {

View File

@ -1,6 +1,6 @@
'use strict';
angular.module('copayApp.controllers').controller('SettingsController', function($scope, $rootScope, $window, $route, $location, $anchorScroll, notification, applicationService, localstorageService) {
angular.module('copayApp.controllers').controller('SettingsController', function($scope, $rootScope, $window, $route, $location, notification, configService) {
$scope.title = 'Settings';
$scope.defaultLanguage = config.defaultLanguage || 'en';
$scope.insightLivenet = config.network.livenet.url;
@ -18,10 +18,10 @@ angular.module('copayApp.controllers').controller('SettingsController', function
}
$scope.availableStorages = [{
name: 'Insight',
name: 'In the cloud (Insight server)',
pluginName: 'EncryptedInsightStorage',
}, {
name: 'Localstorage',
name: 'In this device (localstorage)',
pluginName: 'EncryptedLocalStorage',
},
// {
@ -57,7 +57,6 @@ angular.module('copayApp.controllers').controller('SettingsController', function
}
}
$scope.save = function() {
$scope.insightLivenet = copay.Insight.setCompleteUrl($scope.insightLivenet);
$scope.insightTestnet = copay.Insight.setCompleteUrl($scope.insightTestnet);
@ -73,33 +72,32 @@ angular.module('copayApp.controllers').controller('SettingsController', function
},
}
var plugins = {};
plugins[$scope.selectedStorage.pluginName] = true;
copay.logger.setLevel($scope.selectedLogLevel.name);
localstorageService.setItem('config', JSON.stringify({
network: insightSettings,
version: copay.version,
defaultLanguage: $scope.selectedLanguage.isoCode,
plugins: plugins,
logLevel: $scope.selectedLogLevel.name,
EncryptedInsightStorage: _.extend(config.EncryptedInsightStorage, {
url: insightSettings.livenet.url + '/api/email'
}),
rates: _.extend(config.rates, {
url: insightSettings.livenet.url + '/api/rates'
}),
}), function() {
applicationService.restart();
});
configService.set({
network: insightSettings,
version: copay.version,
defaultLanguage: $scope.selectedLanguage.isoCode,
plugins: plugins,
logLevel: $scope.selectedLogLevel.name,
EncryptedInsightStorage: _.extend(config.EncryptedInsightStorage, {
url: insightSettings.livenet.url + '/api/email'
}),
rates: _.extend(config.rates, {
url: insightSettings.livenet.url + '/api/rates'
}),
},
function() {
notification.success('Settings saved');
$location.path('/');
});
};
$scope.reset = function() {
localstorageService.removeItem('config', function() {
applicationService.reload();
configService.reset(function() {
notification.success('Settings reseted');
$location.path('/');
});
};

View File

@ -0,0 +1,38 @@
'use strict';
angular.module('copayApp.services').factory('configService', function(localstorageService, gettextCatalog) {
var root = {};
root.set = function(opts, cb) {
if (opts.logLevel)
copay.logger.setLevel(opts.logLevel);
if (opts.defaultLanguage)
gettextCatalog.currentLanguage = opts.defaultLanguage;
localstorageService.getItem('config', function(err, oldOpsStr) {
var oldOpts = {};
try {
oldOpts = JSON.parse(oldOpsStr);
} catch (e) {};
var newOpts = {};
_.extend(newOpts, copay.defaultConfig, oldOpts, opts);
// TODO remove this gloval variable.
config = newOpts;
localstorageService.setItem('config', JSON.stringify(newOpts), cb);
});
};
root.reset = function(cb) {
config = copay.defaultConfig;
localstorageService.removeItem('config', cb);
};
return root;
});

View File

@ -11,10 +11,10 @@ angular.module('copayApp.services')
var root = {};
root.check = function(scope) {
copay.Identity.checkIfExistsAny({
pluginManager: pluginManager,
pluginManager: pluginManager.getInstance(config),
}, function(anyProfile) {
copay.Wallet.checkIfExistsAny({
pluginManager: pluginManager,
pluginManager: pluginManager.getInstance(config),
}, function(anyWallet) {
scope.loading = false;
scope.anyProfile = anyProfile ? true : false;
@ -47,7 +47,7 @@ angular.module('copayApp.services')
copay.Identity.create({
email: email,
password: password,
pluginManager: pluginManager,
pluginManager: pluginManager.getInstance(config),
network: config.network,
networkName: config.networkName,
walletDefaults: config.wallet,
@ -99,7 +99,7 @@ angular.module('copayApp.services')
var opts = {
email: email,
password: password,
pluginManager: pluginManager,
pluginManager: pluginManager.getInstance(config),
network: config.network,
networkName: config.networkName,
walletDefaults: config.wallet,
@ -344,7 +344,7 @@ angular.module('copayApp.services')
root.importProfile = function(str, password, cb) {
copay.Identity.importFromEncryptedFullJson(str, password, {
pluginManager: pluginManager,
pluginManager: pluginManager.getInstance(config),
network: config.network,
networkName: config.networkName,
walletDefaults: config.wallet,

View File

@ -1,18 +1,10 @@
'use strict';
angular.module('copayApp.services').factory('pluginManager', function(angularLoad) {
var pm = new copay.PluginManager(config);
var scripts = pm.scripts;
angular.module('copayApp.services').factory('pluginManager', function() {
var root = {};
root.getInstance = function(config){
return new copay.PluginManager(config);
};
for(var ii in scripts){
var src = scripts[ii].src;
console.log('\tLoading ',src); //TODO
angularLoad.loadScript(src)
.then(scripts[ii].then || null)
.catch(function() {
throw new Error('Loading ' + src);
})
}
return pm;
return root;
});

View File

@ -59,7 +59,6 @@
<span class="text-gray">Email address confirmation needed</span>
</div>
</tab>
<tab style="width: 50%;" select="selectStorage('local')">
<tab-heading>
<div class="m5t text-bold">In this Device </div>
@ -82,17 +81,11 @@
</tab>
</tabset>
<button ng-show="!useLocalstorage" translate class="button primary radius expand m0" ng-click="setStorage(useLocalstorage)">
Create in the cloud
<button translate class="button primary radius expand m0" ng-click="goToEmail()">
<span ng-if="!useLocalstorage"> Create in the cloud</span>
<span ng-if="useLocalstorage"> Create in this device</span>
</button>
<button ng-show="useLocalstorage" translate class="button primary radius expand m0" ng-click="setStorage(useLocalstorage)">
Create in this device
</button>
<div class="box-setup-footer">
<div class="left">
<a class="text-gray" href="#!/">
@ -143,7 +136,7 @@
>
<div class="box-setup-footer">
<div class="left">
<a class="text-gray" ng-click="createStep='storage'">
<a class="text-gray" ng-click="setStep('storage')">
<i class="icon-arrow-left4"></i>
<span translate>Back</span>
</a>
@ -185,7 +178,7 @@
<div class="box-setup-footer">
<div class="left">
<a class="text-gray" ng-click="createStep='email'">
<a class="text-gray" ng-click="setStep('email')">
<i class="icon-arrow-left4"></i>
<span translate>Back</span>
</a>

View File

@ -3,10 +3,18 @@
<div class="loading-screen" ng-show="$root.starting">
<div class="spinner">
<div class="contener_general">
<div class="contener_mixte"><div class="ballcolor ball_1">&nbsp;</div></div>
<div class="contener_mixte"><div class="ballcolor ball_2">&nbsp;</div></div>
<div class="contener_mixte"><div class="ballcolor ball_3">&nbsp;</div></div>
<div class="contener_mixte"><div class="ballcolor ball_4">&nbsp;</div></div>
<div class="contener_mixte">
<div class="ballcolor ball_1">&nbsp;</div>
</div>
<div class="contener_mixte">
<div class="ballcolor ball_2">&nbsp;</div>
</div>
<div class="contener_mixte">
<div class="ballcolor ball_3">&nbsp;</div>
</div>
<div class="contener_mixte">
<div class="ballcolor ball_4">&nbsp;</div>
</div>
</div>
<span class="text-gray size-12" translate>Accessing your profile...</span>
</div>
@ -34,7 +42,6 @@
<h3>
Your email was confimed!
</h3>
Please sign in to access your wallets
</div>
</div>
@ -43,36 +50,30 @@
<i class="size-36 fi-alert m10r"></i>
</div>
<b>Copay now needs a profile to access wallets.</b>
You can import your current wallets after
You can import your current wallets after
<a class="text-white" href="#!/createProfile">creating your profile</a>
</div>
<div class="box-setup" ng-if="askForPin">
<h1><span translate>Set up a </span> <b> PIN </b>?</h1>
<p class="size-14"> Enter a 4-digit number for easier access from this device</p>
<p class="size-14">Enter a 4-digit number for easier access from this device</p>
<div class="box-notification" ng-show="error">
<div class="box-icon error">
<i class="fi-x size-24"></i>
</div>
</div>
<span class="text-warning size-14">
{{error|translate}}
</span>
</div>
<form name="setPinForm" ng-model="setPinForm" ng-submit="createPin(setPinForm)" novalidate>
<form name="setPinForm" ng-model="setPinForm" ng-submit="createPin(setPinForm)" novalidate>
<div class="input" ng-show="askForPin == 1">
<input id="newpin" type="tel" ng-model="newpin" class="form-control"
ng-maxlength="4" ng-minlength="4" maxlength="4"
ng-pattern="/^[0-9]{1,4}$/"
placeholder="PIN" name="newpin" required show-focus="askForPin == 1">
<input id="newpin" type="tel" ng-model="newpin" class="form-control" ng-maxlength="4" ng-minlength="4" maxlength="4" ng-pattern="/^[0-9]{1,4}$/" placeholder="PIN" name="newpin" required show-focus="askForPin == 1">
<i class="icon-locked"></i>
</div>
<div class="input" ng-show="askForPin == 2">
<input id="repeatpin" type="tel" ng-model="repeatpin" class="form-control"
ng-maxlength="4" ng-minlength="4" maxlength="4"
ng-pattern="/^[0-9]{1,4}$/"
placeholder="Confirm your PIN" name="repeatpin" required show-focus="askForPin == 2">
<input id="repeatpin" type="tel" ng-model="repeatpin" class="form-control" ng-maxlength="4" ng-minlength="4" maxlength="4" ng-pattern="/^[0-9]{1,4}$/" placeholder="Confirm your PIN" name="repeatpin" required show-focus="askForPin == 2">
<i class="icon-locked"></i>
</div>
@ -83,15 +84,14 @@
</a>
</div>
<div class="large-6 medium-6 small-6 columns text-right">
<button translate type="submit" class="button primary radius expand m0"
ng-disabled="setPinForm.$invalid || error">
OK
<button translate type="submit" class="button primary radius expand m0" ng-disabled="setPinForm.$invalid || error">
OK
</button>
</div>
</div>
</form>
</form>
</div>
<div class="box-setup" ng-if='$root.hasPin'>
@ -100,17 +100,14 @@
<div class="box-notification" ng-show="error">
<div class="box-icon error">
<i class="fi-x size-24"></i>
</div>
</div>
<span class="text-warning size-14">
{{error|translate}}
</span>
</div>
<div class="input">
<input id="pin" type="tel" ng-model="pin" class="form-control"
ng-maxlength="4" ng-minlength="4" maxlength="4"
ng-pattern="/^[0-9]{1,4}$/"
placeholder="Pin number" name="pin" required>
<input id="pin" type="tel" ng-model="pin" class="form-control" ng-maxlength="4" ng-minlength="4" maxlength="4" ng-pattern="/^[0-9]{1,4}$/" placeholder="Pin number" name="pin" required>
<i class="icon-locked"></i>
</div>
@ -122,41 +119,45 @@
</a>
</div>
<div class="large-6 medium-6 small-6 columns text-right">
<button translate type="submit" class="button primary radius expand m0"
ng-disabled="pinForm.$invalid || error">
Sign in
<button translate type="submit" class="button primary radius expand m0" ng-disabled="pinForm.$invalid || error">
Sign in
</button>
</div>
</div>
</form>
</div>
</form>
</div>
<div class="box-setup" ng-if='!$root.hasPin && !askForPin'>
<h1><span translate>Sign in to</span> <b>Copay</b></h1>
<form name="loginForm" ng-submit="openWithCredentials(loginForm)" novalidate>
<p class="text-warning size-12"
ng-show="error">
<i class="fi-x"></i>
{{error|translate}}
</p>
<div class="input">
<input type="email" ng-model="email" class="form-control"
name="email" placeholder="Email" required show-focus="!isMobile">
<p class="text-warning size-12" ng-show="error">
<i class="fi-x"></i> {{error|translate}}
</p>
<div class="input" ng-if="!usingLocalStorage">
<input type="email" ng-model="email" class="form-control" name="email" placeholder="Email" required show-focus="!isMobile">
<i class="icon-email"></i>
</div>
<div class="input" ng-if="usingLocalStorage">
<input type="text" ng-model="email" class="form-control" name="email" placeholder="Username" required show-focus="!isMobile">
<i class="icon-person"></i>
</div>
<div class="input">
<input type="password" ng-model="password" class="form-control"
name="password" placeholder="Password" required>
<input type="password" ng-model="password" class="form-control" name="password" placeholder="Password" required>
<i class="icon-locked"></i>
</div>
<button translate type="submit" class="button primary radius expand m0"
ng-disabled="loginForm.$invalid || loading">
Sign in
<button translate type="submit" class="button primary radius expand m0" ng-disabled="loginForm.$invalid || loading">
Sign in
</button>
</form>
<div ng-if="usingLocalStorage" class="text-gray size-12">
* Using this device storage. Change to cloud storage on 'settings'.
</div>
<div class="box-setup-footer">
<div class="left m10r">
<a class="button-setup text-gray" href="#!/createProfile">

View File

@ -51,12 +51,12 @@
</div>
</fieldset>
<fieldset>
<legend translate>Wallet and profile storage</legend>
<label for="insightTestnet">Store wallet and profiles on</label>
<legend translate>Storage</legend>
<label for="insightTestnet">Read and Store Profiles:</label>
<select class="form-control" ng-model="selectedStorage" ng-options="o.name for o in availableStorages" required>
</select>
<div translate class="small text-gray">
Wallets and profiles are stored encrypted using your password as a key. You can store the encrypted data locally, on your platform, or remotely on the Insight Server. <a target="_blank" href="https://github.com/bitpay/copay/tree/master/js/plugins">More pluggins are welcomed!</a>
Wallets and profiles are stored encrypted using your password as a key. You can store the encrypted data locally, on this device, or remotely on the cloud (Insight Server). <a target="_blank" href="https://github.com/bitpay/copay/tree/master/js/plugins">More pluggins are welcomed!</a>
</div>
</fieldset>
<fieldset>