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

@ -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;