diff --git a/config.js b/config.js index 3ac6bde6e..805ff00d6 100644 --- a/config.js +++ b/config.js @@ -41,7 +41,7 @@ var defaultConfig = { }, // local encryption/security config - passphrase: { + passphraseConfig: { iterations: 100, storageSalt: 'mjuBtGybi/4=', }, diff --git a/js/controllers/home.js b/js/controllers/home.js index 94ebc6d35..3a3797027 100644 --- a/js/controllers/home.js +++ b/js/controllers/home.js @@ -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'); diff --git a/js/models/Identity.js b/js/models/Identity.js index c540f2c97..fc9987cb6 100644 --- a/js/models/Identity.js +++ b/js/models/Identity.js @@ -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 diff --git a/js/models/Profile.js b/js/models/Profile.js index 37d6fe2ca..8f74a3373 100644 --- a/js/models/Profile.js +++ b/js/models/Profile.js @@ -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()); diff --git a/js/models/Storage.js b/js/models/Storage.js index 8c57e3366..936bbdc05 100644 --- a/js/models/Storage.js +++ b/js/models/Storage.js @@ -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; diff --git a/test/models/Identity.js b/test/Identity.js similarity index 100% rename from test/models/Identity.js rename to test/Identity.js diff --git a/test/Profile.js b/test/Profile.js index 4ac4598c1..57bd623d2 100644 --- a/test/Profile.js +++ b/test/Profile.js @@ -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(); }); }) diff --git a/views/createProfile.html b/views/createProfile.html index e39eb8f01..84063cd0c 100644 --- a/views/createProfile.html +++ b/views/createProfile.html @@ -1,6 +1,5 @@
-

( 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 )

diff --git a/views/home.html b/views/home.html index 698c94ad2..100b854f6 100644 --- a/views/home.html +++ b/views/home.html @@ -1,7 +1,5 @@
-

( TODO: only show this login form if there is any profile:: key) -

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