check if there is not profile, to redir

This commit is contained in:
Matias Alejo Garcia 2014-10-11 08:43:51 -03:00
commit b03a3f1391
9 changed files with 52 additions and 28 deletions

View file

@ -41,7 +41,7 @@ var defaultConfig = {
},
// local encryption/security config
passphrase: {
passphraseConfig: {
iterations: 100,
storageSalt: 'mjuBtGybi/4=',
},

View file

@ -1,9 +1,18 @@
'use strict';
angular.module('copayApp.controllers').controller('HomeController', function($scope, $rootScope, $location, notification, controllerUtils, pluginManager) {
controllerUtils.redirIfLogged();
$scope.retreiving =true;
copay.Identity.anyProfile({
pluginManager: pluginManager,
}, function(any) {
$scope.retreiving =false;
if (!any)
$location.path('/createProfile');
});
$scope.openProfile = function(form) {
if (form && form.$invalid) {
notification.error('Error', 'Please enter the required fields');

View file

@ -26,26 +26,8 @@ var Storage = module.exports.Storage = require('./Storage');
function Identity(email, password, 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 = {
'livenet': opts.network.livenet,
'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

View file

@ -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) {
preconditions.checkArgument(cb);
preconditions.checkState(storage.hasPassphrase());

View file

@ -18,12 +18,14 @@ var id = 0;
*/
function Storage(opts) {
preconditions.checkArgument(opts);
preconditions.checkArgument(opts.password);
preconditions.checkArgument(!opts.passphrase);
this.wListCache = {};
this.__uniqueid = ++id;
this.passphraseConfig = opts.passphrase;
this.setPassword(opts.password);
this.passphraseConfig = opts.passphraseConfig;
if (opts.password)
this.setPassword(opts.password);
try {
this.db = opts.db || localStorage;

View file

@ -128,7 +128,7 @@ describe('Profile model', function() {
p.addWallet('345', {}, function(err) {
_.pluck(p.listWallets(), 'id').sort().should.deep.equal(['123', '234', '345']);
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();
});
})

View file

@ -1,6 +1,5 @@
<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 )
<div data-alert class="loading-screen" ng-show="retreiving">
<i class="size-60 fi-bitcoin-circle icon-rotate spinner"></i>

View file

@ -1,7 +1,5 @@
<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 )
<div data-alert class="loading-screen" ng-show="retreiving">
<i class="size-60 fi-bitcoin-circle icon-rotate spinner"></i>