mirror of https://github.com/BTCPrivate/copay.git
pin in create
This commit is contained in:
parent
2f6e28f5e7
commit
1d7e9dda93
|
@ -1,20 +1,77 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('CreateProfileController', function($scope, $rootScope, $location, $timeout, notification, pluginManager, identityService) {
|
||||
angular.module('copayApp.controllers').controller('CreateProfileController', function($scope, $rootScope, $location, $timeout, notification, pluginManager, identityService, pinService) {
|
||||
|
||||
var _credentials, _firstpin;
|
||||
|
||||
$scope.init = function() {
|
||||
identityService.goWalletHome();
|
||||
|
||||
$scope.createProfile = function(form) {
|
||||
if (form && form.$invalid) {
|
||||
$scope.error('Error', 'Please enter the required fields');
|
||||
return;
|
||||
pinService.makePinInput($scope, 'newpin', function(newValue) {
|
||||
_firstpin = newValue;
|
||||
$scope.askForPin = 2;
|
||||
});
|
||||
|
||||
pinService.makePinInput($scope, 'repeatpin', function(newValue) {
|
||||
if (newValue === _firstpin) {
|
||||
_firstpin = null;
|
||||
$scope.createPin(newValue);
|
||||
} else {
|
||||
$scope.askForPin = 1;
|
||||
_firstpin = null;
|
||||
|
||||
$scope.setPinForm.newpin.$setViewValue('');
|
||||
$scope.setPinForm.newpin.$render();
|
||||
$scope.setPinForm.repeatpin.$setViewValue('');
|
||||
$scope.setPinForm.repeatpin.$render();
|
||||
$scope.setPinForm.$setPristine();
|
||||
|
||||
$scope.error = 'Entered PINs were not equal. Try again';
|
||||
}
|
||||
$rootScope.starting = true;
|
||||
identityService.create(
|
||||
form.email.$modelValue, form.password.$modelValue, function(err) {
|
||||
$rootScope.starting = false;
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
$scope.createPin = function(pin) {
|
||||
preconditions.checkArgument(pin);
|
||||
preconditions.checkState($rootScope.iden);
|
||||
preconditions.checkState(_credentials && _credentials.email);
|
||||
|
||||
pinService.save(pin, _credentials.email, _credentials.password, function(err) {
|
||||
_credentials.password = '';
|
||||
_credentials = null;
|
||||
$scope.askForPin = 0;
|
||||
$rootScope.hasPin = true;
|
||||
$scope.createDefaultWallet();
|
||||
});
|
||||
};
|
||||
|
||||
$scope.createDefaultWallet = function() {
|
||||
$rootScope.hideNavigation = false;
|
||||
identityService.createDefaultWallet(function(err) {
|
||||
$scope.askForPin =0 ;
|
||||
$scope.loading = false;
|
||||
|
||||
if (err) {
|
||||
var msg = err.toString();
|
||||
if (msg.indexOf('EEXIST')>=0 || msg.indexOf('BADC')>=0 ) {
|
||||
$scope.error = msg;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
$scope.createProfile = function(form) {
|
||||
$rootScope.hideNavigation = false;
|
||||
if (form && form.$invalid) {
|
||||
$scope.error = 'Please enter the required fields';
|
||||
return;
|
||||
}
|
||||
$scope.loading = true;
|
||||
identityService.create(form.email.$modelValue, form.password.$modelValue, function(err) {
|
||||
$scope.loading = false;
|
||||
|
||||
if (err) {
|
||||
var msg = err.toString();
|
||||
if (msg.indexOf('EEXIST') >= 0 || msg.indexOf('BADC') >= 0) {
|
||||
msg = 'This profile already exists'
|
||||
}
|
||||
$timeout(function() {
|
||||
|
@ -27,6 +84,27 @@ angular.module('copayApp.controllers').controller('CreateProfileController', fun
|
|||
form.$setPristine();
|
||||
$scope.error = msg;
|
||||
},1);
|
||||
$scope.error = msg;
|
||||
} else {
|
||||
$scope.error = null;
|
||||
// mobile
|
||||
//if (isMobile.any()) {
|
||||
if (true) {
|
||||
_credentials = {
|
||||
email: form.email.$modelValue,
|
||||
password: form.password.$modelValue,
|
||||
};
|
||||
$scope.askForPin = 1;
|
||||
$rootScope.hideNavigation = true;
|
||||
$timeout(function() {
|
||||
$rootScope.$digest();
|
||||
}, 1);
|
||||
|
||||
console.log('[createProfile.js.70]'); //TODO
|
||||
return;
|
||||
} else {
|
||||
$scope.createDefaultWallet();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ angular.module('copayApp.controllers').controller('HomeController', function($sc
|
|||
};
|
||||
|
||||
pinService.makePinInput($scope, 'pin', function(newValue) {
|
||||
$scope.openPin(newValue);
|
||||
$scope.openWithPin(newValue);
|
||||
});
|
||||
|
||||
pinService.makePinInput($scope, 'newpin', function(newValue) {
|
||||
|
@ -44,6 +44,13 @@ angular.module('copayApp.controllers').controller('HomeController', function($sc
|
|||
} else {
|
||||
_firstpin = null;
|
||||
$scope.error = 'Entered PINs were not equal. Try again';
|
||||
$scope.askForPin = 1;
|
||||
|
||||
$scope.setPinForm.newpin.$setViewValue('');
|
||||
$scope.setPinForm.newpin.$render();
|
||||
$scope.setPinForm.repeatpin.$setViewValue('');
|
||||
$scope.setPinForm.repeatpin.$render();
|
||||
$scope.setPinForm.$setPristine();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -61,16 +68,14 @@ angular.module('copayApp.controllers').controller('HomeController', function($sc
|
|||
}
|
||||
});
|
||||
|
||||
$scope.openWithPin = function(form) {
|
||||
$scope.confirmedEmail = false;
|
||||
if (form && form.$invalid) {
|
||||
|
||||
$scope.openWithPin = function(pin) {
|
||||
|
||||
if (!pin) {
|
||||
$scope.error = 'Please enter the required fields';
|
||||
return;
|
||||
}
|
||||
$scope.openPin(pin);
|
||||
};
|
||||
|
||||
$scope.openPin = function(pin) {
|
||||
var credentials = pinService.get(pin, function(err, credentials) {
|
||||
if (err || !credentials) {
|
||||
$scope.error = 'Wrong PIN';
|
||||
|
@ -108,7 +113,6 @@ angular.module('copayApp.controllers').controller('HomeController', function($sc
|
|||
};
|
||||
|
||||
$scope.openWithCredentials = function(form) {
|
||||
$scope.confirmedEmail = false;
|
||||
if (form && form.$invalid) {
|
||||
$scope.error = 'Please enter the required fields';
|
||||
return;
|
||||
|
@ -151,6 +155,7 @@ angular.module('copayApp.controllers').controller('HomeController', function($sc
|
|||
|
||||
// Open successfully?
|
||||
if (iden) {
|
||||
$scope.confirmedEmail = false;
|
||||
|
||||
// mobile
|
||||
//if (isMobile.any() && !$rootScope.hasPin) {
|
||||
|
|
|
@ -3,6 +3,11 @@ angular.module('copayApp.services')
|
|||
.factory('identityService', function($rootScope, $location, $timeout, $filter, pluginManager, notification, pendingTxsService, balanceService, applicationService) {
|
||||
notification.enableHtml5Mode(); // for chrome: if support, enable it
|
||||
|
||||
// TODO:
|
||||
// * remove iden from rootScope
|
||||
// * remove wallet from rootScope
|
||||
// * create walletService
|
||||
|
||||
var root = {};
|
||||
root.check = function(scope) {
|
||||
copay.Identity.checkIfExistsAny({
|
||||
|
@ -22,6 +27,7 @@ angular.module('copayApp.services')
|
|||
});
|
||||
};
|
||||
|
||||
// TODO should be on 'walletService'
|
||||
root.goWalletHome = function() {
|
||||
var w = $rootScope.wallet;
|
||||
if (w) {
|
||||
|
@ -49,10 +55,19 @@ angular.module('copayApp.services')
|
|||
failIfExists: true,
|
||||
}, function(err, iden) {
|
||||
|
||||
console.log('[identityService.js.57]'); //TODO
|
||||
if (err) return cb(err);
|
||||
preconditions.checkState(iden);
|
||||
root.bind(iden);
|
||||
|
||||
console.log('[identityService.js.62]'); //TODO
|
||||
return cb(null);
|
||||
});
|
||||
};
|
||||
|
||||
root.createDefaultWallet = function(cb) {
|
||||
var iden = $rootScope.iden;
|
||||
|
||||
var walletOptions = {
|
||||
nickname: iden.fullName,
|
||||
networkName: config.networkName,
|
||||
|
@ -64,8 +79,6 @@ angular.module('copayApp.services')
|
|||
iden.createWallet(walletOptions, function(err, wallet) {
|
||||
return cb(err);
|
||||
});
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
root.setServerStatus = function(headers) {
|
||||
|
|
|
@ -1,18 +1,26 @@
|
|||
<div class="createProfile" ng-controller="CreateProfileController">
|
||||
<div class="createProfile" ng-controller="CreateProfileController" ng-init="init()">
|
||||
|
||||
<div data-alert class="loading-screen" ng-show="loading">
|
||||
<div class="spinner">
|
||||
<div class="contener_general">
|
||||
<div class="contener_mixte"><div class="ballcolor ball_1"> </div></div>
|
||||
<div class="contener_mixte"><div class="ballcolor ball_2"> </div></div>
|
||||
<div class="contener_mixte"><div class="ballcolor ball_3"> </div></div>
|
||||
<div class="contener_mixte"><div class="ballcolor ball_4"> </div></div>
|
||||
<div class="contener_mixte">
|
||||
<div class="ballcolor ball_1"> </div>
|
||||
</div>
|
||||
<div class="contener_mixte">
|
||||
<div class="ballcolor ball_2"> </div>
|
||||
</div>
|
||||
<div class="contener_mixte">
|
||||
<div class="ballcolor ball_3"> </div>
|
||||
</div>
|
||||
<div class="contener_mixte">
|
||||
<div class="ballcolor ball_4"> </div>
|
||||
</div>
|
||||
</div>
|
||||
<span class="text-gray size-12" translate>Creating profile...</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="large-4 large-centered medium-6 medium-centered columns" ng-show="!loading">
|
||||
<div class="large-4 large-centered medium-6 medium-centered columns" ng-show="!loading && !askForPin">
|
||||
<div class="logo-setup">
|
||||
<img src="img/logo-negative-beta.svg" alt="Copay" width="146" height="59">
|
||||
<div ng-include="'views/includes/version.html'"></div>
|
||||
|
@ -38,8 +46,7 @@
|
|||
!profileForm.email.$pristine"><i class="fi-check"></i></span>
|
||||
</div>
|
||||
<div class="input">
|
||||
<input type="email" ng-model="email" class="form-control fi-email"
|
||||
name="email" placeholder="Email" required auto-focus>
|
||||
<input type="email" ng-model="email" class="form-control fi-email" name="email" placeholder="Email" required auto-focus>
|
||||
<i class="icon-email"></i>
|
||||
</div>
|
||||
|
||||
|
@ -61,15 +68,11 @@
|
|||
</div>
|
||||
|
||||
<div class="input">
|
||||
<input type="password" ng-model="repeatpassword"
|
||||
class="input form-control" name="repeatpassword"
|
||||
placeholder="{{'Repeat password'|translate}}"
|
||||
match="password" required>
|
||||
<input type="password" ng-model="repeatpassword" class="input form-control" name="repeatpassword" placeholder="{{'Repeat password'|translate}}" match="password" required>
|
||||
<i class="icon-locked"></i>
|
||||
</div>
|
||||
|
||||
<button translate type="submit" class="button primary radius expand m0"
|
||||
ng-disabled="profileForm.$invalid || loading">
|
||||
<button translate type="submit" class="button primary radius expand m0" ng-disabled="profileForm.$invalid || loading">
|
||||
Create
|
||||
</button>
|
||||
</form>
|
||||
|
@ -89,6 +92,50 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="large-4 large-centered medium-6 medium-centered columns" ng-show="!loading && askForPin">
|
||||
<div class="box-setup">
|
||||
<h1><span translate>Set up a </span> <b> PIN </b>?</h1>
|
||||
<p class="size-14">Enter a 4-digit number for easier access from this device
|
||||
|
||||
<div class="box-notification" ng-show="error">
|
||||
<div class="box-icon error">
|
||||
<i class="fi-x size-24"></i>
|
||||
</div>
|
||||
<span class="text-warning size-14">
|
||||
{{error|translate}}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<form name="setPinForm" ng-submit="createPin(setPinForm)" novalidate>
|
||||
<div class="input" ng-show="askForPin == 1">
|
||||
<input id="newpin" type="tel" ng-model="newpin" class="form-control" ng-maxlength="4" ng-minlength="4" maxlength="4" ng-pattern="/^[0-9]{1,4}$/" placeholder="PIN" name="newpin" required show-focus="askForPin == 1">
|
||||
<i class="icon-locked"></i>
|
||||
</div>
|
||||
<div class="input" ng-show="askForPin == 2">
|
||||
<input id="repeatpin" type="tel" ng-model="repeatpin" class="form-control" ng-maxlength="4" ng-minlength="4" maxlength="4" ng-pattern="/^[0-9]{1,4}$/" placeholder="Confirm your PIN" name="repeatpin" required show-focus="askForPin == 2">
|
||||
<i class="icon-locked"></i>
|
||||
</div>
|
||||
|
||||
<button translate type="submit" class="dn button primary radius expand m0" ng-disabled="setPinForm.$invalid || error">
|
||||
Set pin
|
||||
</button>
|
||||
</form>
|
||||
<div class="box-setup-footer row collapse">
|
||||
<div class="large-6 medium-6 small-6 columns text-right">
|
||||
<a class="button secondary radius m0" ng-click="createDefaultWallet()">
|
||||
<span translate>Skip</span>
|
||||
</a>
|
||||
</div>
|
||||
<div class="large-6 medium-6 small-6 columns text-right">
|
||||
<a class="button secondary radius m0">
|
||||
<span translate>OK</span>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
|
|
@ -98,7 +98,7 @@
|
|||
|
||||
<div class="box-setup" ng-if='$root.hasPin'>
|
||||
<h1><span translate>Enter your </span> <b> PIN</b></h1>
|
||||
<form name="pinForm" ng-submit="openWithPin(pinForm)" novalidate>
|
||||
<form name="pinForm" novalidate>
|
||||
<div class="box-notification" ng-show="error">
|
||||
<div class="box-icon error">
|
||||
<i class="fi-x size-24"></i>
|
||||
|
@ -116,7 +116,7 @@
|
|||
<i class="icon-locked"></i>
|
||||
</div>
|
||||
|
||||
<button translate type="submit" class="dn button primary radius expand m0"
|
||||
<button translate type="submit" class="button primary radius expand m0"
|
||||
ng-disabled="pinForm.$invalid || error">
|
||||
Sign in
|
||||
</button>
|
||||
|
|
Loading…
Reference in New Issue