mirror of https://github.com/BTCPrivate/copay.git
refactor iden #create
This commit is contained in:
parent
d84808f0c7
commit
606ea0668c
|
@ -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;
|
||||
// });
|
||||
});
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
'use strict';
|
||||
angular.module('copayApp.services').factory('identity', function(pluginManager){
|
||||
return new copay.Identity(config, copay.version, pluginManager);
|
||||
});
|
||||
|
|
@ -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),
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
function LocalStorage() {
|
||||
this.type = 'STORAGE';
|
||||
this.type = 'DB';
|
||||
};
|
||||
|
||||
LocalStorage.prototype.init = function() {
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
<div class="home" ng-controller="HomeController">
|
||||
|
||||
<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>
|
||||
Retreiving information from storage...
|
||||
|
@ -8,25 +11,33 @@
|
|||
<img src="img/logo-negative-beta.svg" alt="Copay" width="146" height="59">
|
||||
<div ng-include="'views/includes/version.html'"></div>
|
||||
</div>
|
||||
<div class="large-8 columns">
|
||||
<div class="button-setup" ng-show="hasWallets">
|
||||
<a translate class="text-white" href="#!/open">Open a wallet</a>
|
||||
</div>
|
||||
<div class="button-setup" ng-show="!hasWallets">
|
||||
<a translate class="text-secondary" href="#!/create">Create a new wallet</a>
|
||||
</div>
|
||||
<div class="large-8 columns line-dashed-setup-v">
|
||||
<div class="button-setup">
|
||||
<a translate class="text-primary" href="#!/join">Join a Wallet in Creation</a>
|
||||
</div>
|
||||
<div class="button-setup" ng-show="hasWallets">
|
||||
<a translate class="text-secondary" href="#!/create">Create a wallet</a>
|
||||
<h1 class="text-white line-sidebar-b" translate >Login </h1>
|
||||
<form name="settingsForm">
|
||||
<fieldset>
|
||||
<label for="insight-livenet">Email</label>
|
||||
<input type="text" ng-model="profile.email" class="form-control" name="profile-email">
|
||||
<label for="insight-testnet">Password</label>
|
||||
<input type="text" ng-model="profile.password" class="form-control" name="profile-password">
|
||||
</fieldset>
|
||||
<div class="text-right">
|
||||
<button translate type="submit" class="button primary m0 ng-binding" ng-disabled="setupForm.$invalid || loading" disabled="disabled" ng-click="save()">
|
||||
Login
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="button-setup">
|
||||
<a translate class="text-secondary" href="#!/createProfile">Create a profile</a>
|
||||
</div>
|
||||
<div class="footer-setup">
|
||||
<a class="right size-12 text-gray" href="#!/settings"><i class="m10r
|
||||
size-14 fi-wrench"></i><span translate>Settings</span></a>
|
||||
<a class="left size-12 text-gray" href="#!/import"><i class="m10r
|
||||
size-14 fi-upload"></i><span translate>Import a backup</span></a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue