diff --git a/js/controllers/home.js b/js/controllers/home.js index 29e736589..64580f85f 100644 --- a/js/controllers/home.js +++ b/js/controllers/home.js @@ -1,12 +1,12 @@ 'use strict'; -angular.module('copayApp.controllers').controller('HomeController', function($scope, $rootScope, $location, identity, notification, controllerUtils) { +angular.module('copayApp.controllers').controller('HomeController', function($scope, $rootScope, $location, notification, controllerUtils) { controllerUtils.redirIfLogged(); - $scope.retreiving = true; - identity.getWallets(function(err,ret) { - $scope.retreiving = false; - $scope.hasWallets = (ret && ret.length > 0) ? true : false; - }); + //$scope.retreiving = true; + // identity.getWallets(function(err,ret) { + // $scope.retreiving = false; + // $scope.hasWallets = (ret && ret.length > 0) ? true : false; + // }); }); diff --git a/js/models/Identity.js b/js/models/Identity.js index 04f00410f..f64923079 100644 --- a/js/models/Identity.js +++ b/js/models/Identity.js @@ -57,15 +57,12 @@ function Identity(email, password, opts) { // open wallets this.wallets = []; - this.profile = Identity._newProfile({ - email: email, - }, password, this.storage); }; /* for stubbing */ -Identity._newProfile = function(info, password, storage) { - return new Profile(info, password, storage); +Identity._createProfile = function(email, password, storage, cb) { + Profile.create(email, password, storage, cb); }; Identity._newInsight = function(opts) { @@ -93,7 +90,7 @@ Identity._walletDelete = function(id, cb) { }; Identity._profileOpen = function(e, p, s, cb) { - return Profile.open(e, p, s, cb); + Profile.create(e, p, s, cb); }; @@ -109,11 +106,13 @@ Identity._profileOpen = function(e, p, s, cb) { * @return {undefined} */ Identity.create = function(email, password, opts, cb) { + var iden = new Identity(email, password, opts); - iden.store({ - overwrite: false, - }, function(err) { - return cb(err, iden); + Identity._createProfile(email, password, iden.storage, function(err, profile) { + if (err) return cb(err); + + iden.profile = profile; + return cb(null, iden); }); }; @@ -144,7 +143,7 @@ Identity.prototype.validate = function(authcode, cb) { Identity.open = function(email, password, opts, cb) { var iden = new Identity(email, password, opts); - Identity._profileOpen(email, password, iden.storage, function(err, profile){ + Identity._profileOpen(email, password, iden.storage, function(err, profile) { if (err) return cb(err); iden.profile = profile; @@ -174,6 +173,8 @@ Identity.isAvailable = function(email, opts, cb) { * @return {undefined} */ Identity.prototype.store = function(opts, cb) { + preconditions.checkState(this.profile); + var self = this; self.profile.store(opts, function(err) { if (err) return cb(err); diff --git a/js/models/PluginManager.js b/js/models/PluginManager.js index 6a58b6eb6..e13de65d4 100644 --- a/js/models/PluginManager.js +++ b/js/models/PluginManager.js @@ -31,8 +31,8 @@ PluginManager.prototype._register = function(obj, name) { var type = obj.type; var kind = PluginManager.TYPE[type]; - preconditions.checkArgument(kind, 'Plugin has unknown type' + name); - preconditions.checkState(kind !== PluginManager.KIND_UNIQUE || !this.registered[type], 'Plugin kind already registered: ' + name); + preconditions.checkArgument(kind, 'Unknown plugin type:' + name); + preconditions.checkState(kind !== PluginManager.KIND_UNIQUE || !this.registered[type], 'Plugin kind already registered:' + name); if (kind === PluginManager.KIND_UNIQUE) { this.registered[type] = obj; diff --git a/js/models/Profile.js b/js/models/Profile.js index dd8ee7f0d..8e20437ac 100644 --- a/js/models/Profile.js +++ b/js/models/Profile.js @@ -24,7 +24,18 @@ Profile.hash = function(email, password) { }; Profile.key = function(hash) { - return 'identity::' + hash; + return 'profile::' + hash; +}; + + +Profile.create = function(email, password, storage, cb) { + preconditions.checkArgument(cb); + var p = new Profile({ + email: email, + hash: Profile.hash(email,password), + }, storage); + + p.store(cb); }; Profile.open = function(email, password, storage, cb) { diff --git a/js/routes.js b/js/routes.js index 6f01ffc23..f0c5e9204 100644 --- a/js/routes.js +++ b/js/routes.js @@ -10,6 +10,10 @@ angular templateUrl: 'views/home.html', validate: false }) + .when('/createProfile', { + templateUrl: 'views/createProfile.html', + validate: false + }) .when('/open', { templateUrl: 'views/open.html', validate: false diff --git a/js/services/identity.js b/js/services/identity.js index 8cd37725e..e69de29bb 100644 --- a/js/services/identity.js +++ b/js/services/identity.js @@ -1,5 +0,0 @@ -'use strict'; -angular.module('copayApp.services').factory('identity', function(pluginManager){ - return new copay.Identity(config, copay.version, pluginManager); -}); - diff --git a/plugins/GoogleDrive.js b/plugins/GoogleDrive.js index 4c8783ac6..00417cdd6 100644 --- a/plugins/GoogleDrive.js +++ b/plugins/GoogleDrive.js @@ -12,7 +12,7 @@ function GoogleDrive(config) { this.home = config.home || 'copay'; this.idCache = {}; - this.type = 'STORAGE'; + this.type = 'DB'; this.scripts = [{ then: this.initLoaded.bind(this), diff --git a/plugins/LocalStorage.js b/plugins/LocalStorage.js index 0035fc12b..edad56006 100644 --- a/plugins/LocalStorage.js +++ b/plugins/LocalStorage.js @@ -1,7 +1,7 @@ 'use strict'; function LocalStorage() { - this.type = 'STORAGE'; + this.type = 'DB'; }; LocalStorage.prototype.init = function() { diff --git a/test/test.Identity.js b/test/test.Identity.js index 8009bd85b..0e08da85d 100644 --- a/test/test.Identity.js +++ b/test/test.Identity.js @@ -30,7 +30,7 @@ function assertObjectEqual(a, b) { describe('Identity model', function() { var iden, storage, wallet, profile; - beforeEach(function() { + beforeEach(function(done) { storage = sinon.stub(); storage.getItem = sinon.stub(); storage.setPassphrase = sinon.spy(); @@ -52,11 +52,14 @@ describe('Identity model', function() { profile.listWallets = sinon.stub().returns([]); profile.setLastOpenedTs = sinon.stub().yields(null);; profile.store = sinon.stub().yields(null);; - Identity._newProfile = sinon.stub().returns(profile); + Identity._createProfile = sinon.stub().callsArgWith(3,null,profile); - iden = new Identity(email, password, config); + Identity.create(email, password, config, function(err,i){ + iden = i; + done(); + }); }); @@ -105,25 +108,18 @@ describe('Identity model', function() { var iden = new Identity(email, password, config); should.exist(iden); iden.walletDefaults.should.deep.equal(config.wallet); - iden.version.should.equal('0.0.1'); - should.exist(iden.profile.addWallet); - - Identity._newProfile.getCall(0).args[0].should.deep.equal({ - email: email - }); - Identity._newProfile.getCall(0).args[1].should.equal(password); - Identity._newProfile.getCall(0).args[2].should.equal(iden.storage); }); }); describe('#create', function(done) { it('should call .store', function(done) { Identity.create(email, password, config, function(err, iden) { + should.not.exist(err); should.exist(iden.profile.addWallet); - iden.profile.store.getCall(0).args[0].should.deep.equal({ - overwrite: false - }); + + Identity._createProfile.getCall(0).args[0].should.deep.equal(email); + Identity._createProfile.getCall(0).args[1].should.deep.equal(password); done(); }); }); diff --git a/views/home.html b/views/home.html index 3c7f58533..3570e6b9d 100644 --- a/views/home.html +++ b/views/home.html @@ -1,4 +1,7 @@
+ +

( TODO1: only this form if there is any profile:: key) +

( TODO2: if user has wallets (wallet::) show message: Copay now needs a profile to ... , you can import your wallets after creating your profile )

Retreiving information from storage... @@ -8,25 +11,33 @@ Copay
-
- - +
-
- Create a wallet +

Login

+
+
+ + + + +
+
+ +
+
+ + + +