check if there is not profile, to redir
This commit is contained in:
parent
bdaf40de48
commit
b03a3f1391
9 changed files with 52 additions and 28 deletions
|
|
@ -41,7 +41,7 @@ var defaultConfig = {
|
||||||
},
|
},
|
||||||
|
|
||||||
// local encryption/security config
|
// local encryption/security config
|
||||||
passphrase: {
|
passphraseConfig: {
|
||||||
iterations: 100,
|
iterations: 100,
|
||||||
storageSalt: 'mjuBtGybi/4=',
|
storageSalt: 'mjuBtGybi/4=',
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,18 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copayApp.controllers').controller('HomeController', function($scope, $rootScope, $location, notification, controllerUtils, pluginManager) {
|
angular.module('copayApp.controllers').controller('HomeController', function($scope, $rootScope, $location, notification, controllerUtils, pluginManager) {
|
||||||
|
|
||||||
controllerUtils.redirIfLogged();
|
controllerUtils.redirIfLogged();
|
||||||
|
|
||||||
|
$scope.retreiving =true;
|
||||||
|
copay.Identity.anyProfile({
|
||||||
|
pluginManager: pluginManager,
|
||||||
|
}, function(any) {
|
||||||
|
$scope.retreiving =false;
|
||||||
|
if (!any)
|
||||||
|
$location.path('/createProfile');
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
$scope.openProfile = function(form) {
|
$scope.openProfile = function(form) {
|
||||||
if (form && form.$invalid) {
|
if (form && form.$invalid) {
|
||||||
notification.error('Error', 'Please enter the required fields');
|
notification.error('Error', 'Please enter the required fields');
|
||||||
|
|
|
||||||
|
|
@ -26,26 +26,8 @@ var Storage = module.exports.Storage = require('./Storage');
|
||||||
|
|
||||||
function Identity(email, password, opts) {
|
function Identity(email, password, opts) {
|
||||||
preconditions.checkArgument(opts);
|
preconditions.checkArgument(opts);
|
||||||
var storageOpts = {};
|
|
||||||
|
|
||||||
if (opts.pluginManager) {
|
|
||||||
storageOpts = _.clone({
|
|
||||||
db: opts.pluginManager.get('DB'),
|
|
||||||
passphrase: opts.passphrase,
|
|
||||||
});
|
|
||||||
/*
|
|
||||||
* TODO (plugins for other services)
|
|
||||||
*
|
|
||||||
* blockchainOpts = {
|
|
||||||
* provider: Insight...
|
|
||||||
* }
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
storageOpts.password = password;
|
|
||||||
|
|
||||||
this.storage = Identity._newStorage(storageOpts);
|
|
||||||
this.storage.setPassword(password);
|
|
||||||
|
|
||||||
|
this.storage = Identity._getStorage(opts, password);
|
||||||
this.networkOpts = {
|
this.networkOpts = {
|
||||||
'livenet': opts.network.livenet,
|
'livenet': opts.network.livenet,
|
||||||
'testnet': opts.network.testnet,
|
'testnet': opts.network.testnet,
|
||||||
|
|
@ -102,6 +84,33 @@ Identity._newAsync = function(opts) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Identity._getStorage = function(opts, password) {
|
||||||
|
var storageOpts = {};
|
||||||
|
|
||||||
|
if (opts.pluginManager) {
|
||||||
|
storageOpts = _.clone({
|
||||||
|
db: opts.pluginManager.get('DB'),
|
||||||
|
passphraseConfig: opts.passphraseConfig,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (password)
|
||||||
|
storageOpts.password = password;
|
||||||
|
|
||||||
|
return Identity._newStorage(storageOpts);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* check if any profile exists on storage
|
||||||
|
*
|
||||||
|
* @param opts.storageOpts
|
||||||
|
* @param cb
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
Identity.anyProfile = function(opts, cb) {
|
||||||
|
var storage = Identity._getStorage(opts);
|
||||||
|
Profile.any(storage,cb);
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* creates and Identity
|
* creates and Identity
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,13 @@ Profile.create = function(email, password, storage, cb) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Profile.any = function(storage, cb) {
|
||||||
|
storage.getFirst(Profile.key(''), function(err, val) {
|
||||||
|
return cb(val ? true : false);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
Profile.open = function(email, password, storage, cb) {
|
Profile.open = function(email, password, storage, cb) {
|
||||||
preconditions.checkArgument(cb);
|
preconditions.checkArgument(cb);
|
||||||
preconditions.checkState(storage.hasPassphrase());
|
preconditions.checkState(storage.hasPassphrase());
|
||||||
|
|
|
||||||
|
|
@ -18,12 +18,14 @@ var id = 0;
|
||||||
*/
|
*/
|
||||||
function Storage(opts) {
|
function Storage(opts) {
|
||||||
preconditions.checkArgument(opts);
|
preconditions.checkArgument(opts);
|
||||||
preconditions.checkArgument(opts.password);
|
preconditions.checkArgument(!opts.passphrase);
|
||||||
|
|
||||||
this.wListCache = {};
|
this.wListCache = {};
|
||||||
this.__uniqueid = ++id;
|
this.__uniqueid = ++id;
|
||||||
this.passphraseConfig = opts.passphrase;
|
this.passphraseConfig = opts.passphraseConfig;
|
||||||
this.setPassword(opts.password);
|
|
||||||
|
if (opts.password)
|
||||||
|
this.setPassword(opts.password);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.db = opts.db || localStorage;
|
this.db = opts.db || localStorage;
|
||||||
|
|
|
||||||
|
|
@ -128,7 +128,7 @@ describe('Profile model', function() {
|
||||||
p.addWallet('345', {}, function(err) {
|
p.addWallet('345', {}, function(err) {
|
||||||
_.pluck(p.listWallets(), 'id').sort().should.deep.equal(['123', '234', '345']);
|
_.pluck(p.listWallets(), 'id').sort().should.deep.equal(['123', '234', '345']);
|
||||||
p.deleteWallet('234', function(err) {
|
p.deleteWallet('234', function(err) {
|
||||||
_.pluck(p.listWallets(), 'id').should.deep.equal(['123', '345']);
|
_.pluck(p.listWallets(), 'id').sort().should.deep.equal(['123', '345']);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
<div class="createProfile" ng-controller="CreateProfileController">
|
<div class="createProfile" ng-controller="CreateProfileController">
|
||||||
|
|
||||||
<P>( TODO1: only this form if there is any profile:: key)
|
|
||||||
<p>( TODO2: if user has wallets (wallet::) show message: Copay now needs a profile to ... , you can import your wallets after creating your profile )
|
<p>( TODO2: if user has wallets (wallet::) show message: Copay now needs a profile to ... , you can import your wallets after creating your profile )
|
||||||
<div data-alert class="loading-screen" ng-show="retreiving">
|
<div data-alert class="loading-screen" ng-show="retreiving">
|
||||||
<i class="size-60 fi-bitcoin-circle icon-rotate spinner"></i>
|
<i class="size-60 fi-bitcoin-circle icon-rotate spinner"></i>
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
<div class="home" ng-controller="HomeController">
|
<div class="home" ng-controller="HomeController">
|
||||||
|
|
||||||
<P>( TODO: only show this login form if there is any profile:: key)
|
|
||||||
|
|
||||||
<p>( TODO: if user has wallets (wallet::) show message: Copay now needs a profile to ... , you can import your wallets after creating your profile )
|
<p>( TODO: if user has wallets (wallet::) show message: Copay now needs a profile to ... , you can import your wallets after creating your profile )
|
||||||
<div data-alert class="loading-screen" ng-show="retreiving">
|
<div data-alert class="loading-screen" ng-show="retreiving">
|
||||||
<i class="size-60 fi-bitcoin-circle icon-rotate spinner"></i>
|
<i class="size-60 fi-bitcoin-circle icon-rotate spinner"></i>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue