mirror of https://github.com/BTCPrivate/copay.git
pin in create
This commit is contained in:
parent
2f6e28f5e7
commit
1d7e9dda93
|
@ -1,23 +1,80 @@
|
||||||
'use strict';
|
'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) {
|
||||||
identityService.goWalletHome();
|
|
||||||
|
var _credentials, _firstpin;
|
||||||
|
|
||||||
|
$scope.init = function() {
|
||||||
|
identityService.goWalletHome();
|
||||||
|
|
||||||
|
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';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
$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();
|
||||||
|
$scope.error = msg;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
$scope.createProfile = function(form) {
|
$scope.createProfile = function(form) {
|
||||||
|
$rootScope.hideNavigation = false;
|
||||||
if (form && form.$invalid) {
|
if (form && form.$invalid) {
|
||||||
$scope.error('Error', 'Please enter the required fields');
|
$scope.error = 'Please enter the required fields';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$rootScope.starting = true;
|
$scope.loading = true;
|
||||||
identityService.create(
|
identityService.create(form.email.$modelValue, form.password.$modelValue, function(err) {
|
||||||
form.email.$modelValue, form.password.$modelValue, function(err) {
|
$scope.loading = false;
|
||||||
$rootScope.starting = false;
|
|
||||||
if (err) {
|
if (err) {
|
||||||
var msg = err.toString();
|
var msg = err.toString();
|
||||||
if (msg.indexOf('EEXIST')>=0 || msg.indexOf('BADC')>=0 ) {
|
if (msg.indexOf('EEXIST') >= 0 || msg.indexOf('BADC') >= 0) {
|
||||||
msg = 'This profile already exists'
|
msg = 'This profile already exists'
|
||||||
}
|
}
|
||||||
$timeout(function() {
|
$timeout(function() {
|
||||||
form.email.$setViewValue('');
|
form.email.$setViewValue('');
|
||||||
form.email.$render();
|
form.email.$render();
|
||||||
form.password.$setViewValue('');
|
form.password.$setViewValue('');
|
||||||
|
@ -27,7 +84,28 @@ angular.module('copayApp.controllers').controller('CreateProfileController', fun
|
||||||
form.$setPristine();
|
form.$setPristine();
|
||||||
$scope.error = msg;
|
$scope.error = msg;
|
||||||
},1);
|
},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) {
|
pinService.makePinInput($scope, 'pin', function(newValue) {
|
||||||
$scope.openPin(newValue);
|
$scope.openWithPin(newValue);
|
||||||
});
|
});
|
||||||
|
|
||||||
pinService.makePinInput($scope, 'newpin', function(newValue) {
|
pinService.makePinInput($scope, 'newpin', function(newValue) {
|
||||||
|
@ -39,11 +39,18 @@ angular.module('copayApp.controllers').controller('HomeController', function($sc
|
||||||
|
|
||||||
pinService.makePinInput($scope, 'repeatpin', function(newValue) {
|
pinService.makePinInput($scope, 'repeatpin', function(newValue) {
|
||||||
if (newValue === _firstpin) {
|
if (newValue === _firstpin) {
|
||||||
_firstpin = null;
|
_firstpin = null;
|
||||||
$scope.createPin(newValue);
|
$scope.createPin(newValue);
|
||||||
} else {
|
} else {
|
||||||
_firstpin = null;
|
_firstpin = null;
|
||||||
$scope.error = 'Entered PINs were not equal. Try again';
|
$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;
|
$scope.openWithPin = function(pin) {
|
||||||
if (form && form.$invalid) {
|
|
||||||
|
if (!pin) {
|
||||||
$scope.error = 'Please enter the required fields';
|
$scope.error = 'Please enter the required fields';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$scope.openPin(pin);
|
|
||||||
};
|
|
||||||
|
|
||||||
$scope.openPin = function(pin) {
|
|
||||||
var credentials = pinService.get(pin, function(err, credentials) {
|
var credentials = pinService.get(pin, function(err, credentials) {
|
||||||
if (err || !credentials) {
|
if (err || !credentials) {
|
||||||
$scope.error = 'Wrong PIN';
|
$scope.error = 'Wrong PIN';
|
||||||
|
@ -108,7 +113,6 @@ angular.module('copayApp.controllers').controller('HomeController', function($sc
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.openWithCredentials = function(form) {
|
$scope.openWithCredentials = function(form) {
|
||||||
$scope.confirmedEmail = false;
|
|
||||||
if (form && form.$invalid) {
|
if (form && form.$invalid) {
|
||||||
$scope.error = 'Please enter the required fields';
|
$scope.error = 'Please enter the required fields';
|
||||||
return;
|
return;
|
||||||
|
@ -151,6 +155,7 @@ angular.module('copayApp.controllers').controller('HomeController', function($sc
|
||||||
|
|
||||||
// Open successfully?
|
// Open successfully?
|
||||||
if (iden) {
|
if (iden) {
|
||||||
|
$scope.confirmedEmail = false;
|
||||||
|
|
||||||
// mobile
|
// mobile
|
||||||
//if (isMobile.any() && !$rootScope.hasPin) {
|
//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) {
|
.factory('identityService', function($rootScope, $location, $timeout, $filter, pluginManager, notification, pendingTxsService, balanceService, applicationService) {
|
||||||
notification.enableHtml5Mode(); // for chrome: if support, enable it
|
notification.enableHtml5Mode(); // for chrome: if support, enable it
|
||||||
|
|
||||||
|
// TODO:
|
||||||
|
// * remove iden from rootScope
|
||||||
|
// * remove wallet from rootScope
|
||||||
|
// * create walletService
|
||||||
|
|
||||||
var root = {};
|
var root = {};
|
||||||
root.check = function(scope) {
|
root.check = function(scope) {
|
||||||
copay.Identity.checkIfExistsAny({
|
copay.Identity.checkIfExistsAny({
|
||||||
|
@ -22,6 +27,7 @@ angular.module('copayApp.services')
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// TODO should be on 'walletService'
|
||||||
root.goWalletHome = function() {
|
root.goWalletHome = function() {
|
||||||
var w = $rootScope.wallet;
|
var w = $rootScope.wallet;
|
||||||
if (w) {
|
if (w) {
|
||||||
|
@ -49,23 +55,30 @@ angular.module('copayApp.services')
|
||||||
failIfExists: true,
|
failIfExists: true,
|
||||||
}, function(err, iden) {
|
}, function(err, iden) {
|
||||||
|
|
||||||
|
console.log('[identityService.js.57]'); //TODO
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
preconditions.checkState(iden);
|
preconditions.checkState(iden);
|
||||||
root.bind(iden);
|
root.bind(iden);
|
||||||
|
|
||||||
var walletOptions = {
|
console.log('[identityService.js.62]'); //TODO
|
||||||
nickname: iden.fullName,
|
return cb(null);
|
||||||
networkName: config.networkName,
|
|
||||||
requiredCopayers: 1,
|
|
||||||
totalCopayers: 1,
|
|
||||||
password: iden.password,
|
|
||||||
name: 'My wallet',
|
|
||||||
};
|
|
||||||
iden.createWallet(walletOptions, function(err, wallet) {
|
|
||||||
return cb(err);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
root.createDefaultWallet = function(cb) {
|
||||||
|
var iden = $rootScope.iden;
|
||||||
|
|
||||||
|
var walletOptions = {
|
||||||
|
nickname: iden.fullName,
|
||||||
|
networkName: config.networkName,
|
||||||
|
requiredCopayers: 1,
|
||||||
|
totalCopayers: 1,
|
||||||
|
password: iden.password,
|
||||||
|
name: 'My wallet',
|
||||||
|
};
|
||||||
|
iden.createWallet(walletOptions, function(err, wallet) {
|
||||||
|
return cb(err);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
root.setServerStatus = function(headers) {
|
root.setServerStatus = function(headers) {
|
||||||
|
|
|
@ -1,28 +1,36 @@
|
||||||
<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 data-alert class="loading-screen" ng-show="loading">
|
||||||
<div class="spinner">
|
<div class="spinner">
|
||||||
<div class="contener_general">
|
<div class="contener_general">
|
||||||
<div class="contener_mixte"><div class="ballcolor ball_1"> </div></div>
|
<div class="contener_mixte">
|
||||||
<div class="contener_mixte"><div class="ballcolor ball_2"> </div></div>
|
<div class="ballcolor ball_1"> </div>
|
||||||
<div class="contener_mixte"><div class="ballcolor ball_3"> </div></div>
|
</div>
|
||||||
<div class="contener_mixte"><div class="ballcolor ball_4"> </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>
|
</div>
|
||||||
<span class="text-gray size-12" translate>Creating profile...</span>
|
<span class="text-gray size-12" translate>Creating profile...</span>
|
||||||
</div>
|
</div>
|
||||||
</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">
|
<div class="logo-setup">
|
||||||
<img src="img/logo-negative-beta.svg" alt="Copay" width="146" height="59">
|
<img src="img/logo-negative-beta.svg" alt="Copay" width="146" height="59">
|
||||||
<div ng-include="'views/includes/version.html'"></div>
|
<div ng-include="'views/includes/version.html'"></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="box-setup">
|
<div class="box-setup">
|
||||||
<h1>Create Profile</h1>
|
<h1>Create Profile</h1>
|
||||||
<div class="box-notification" ng-show="error">
|
<div class="box-notification" ng-show="error">
|
||||||
<div class="box-icon error">
|
<div class="box-icon error">
|
||||||
<i class="fi-x size-24"></i>
|
<i class="fi-x size-24"></i>
|
||||||
</div>
|
</div>
|
||||||
<span class="text-warning size-14">
|
<span class="text-warning size-14">
|
||||||
{{error|translate}}
|
{{error|translate}}
|
||||||
</span>
|
</span>
|
||||||
|
@ -32,19 +40,18 @@
|
||||||
<span translate class="has-error size-12" ng-show="profileForm.email.$invalid &&
|
<span translate class="has-error size-12" ng-show="profileForm.email.$invalid &&
|
||||||
!profileForm.email.$pristine">
|
!profileForm.email.$pristine">
|
||||||
<span class="icon-input"><i class="fi-x"></i></span>
|
<span class="icon-input"><i class="fi-x"></i></span>
|
||||||
Not valid
|
Not valid
|
||||||
</span>
|
</span>
|
||||||
<span class="icon-input" ng-show="!profileForm.email.$invalid &&
|
<span class="icon-input" ng-show="!profileForm.email.$invalid &&
|
||||||
!profileForm.email.$pristine"><i class="fi-check"></i></span>
|
!profileForm.email.$pristine"><i class="fi-check"></i></span>
|
||||||
</div>
|
</div>
|
||||||
<div class="input">
|
<div class="input">
|
||||||
<input type="email" ng-model="email" class="form-control fi-email"
|
<input type="email" ng-model="email" class="form-control fi-email" name="email" placeholder="Email" required auto-focus>
|
||||||
name="email" placeholder="Email" required auto-focus>
|
|
||||||
<i class="icon-email"></i>
|
<i class="icon-email"></i>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="input">
|
<div class="input">
|
||||||
<input id="password" type="password" ng-model="$parent.password"
|
<input id="password" type="password" ng-model="$parent.password"
|
||||||
class="form-control" name="password" placeholder="{{'Choose a password'|translate}}" check-strength="passwordStrength"
|
class="form-control" name="password" placeholder="{{'Choose a password'|translate}}" check-strength="passwordStrength"
|
||||||
tooltip-html-unsafe="Password strength: <b>{{passwordStrength}}</b><br/><span class='size-12'>Tip: Use lower and uppercase, numbers and symbols</span>" tooltip-trigger="focus" required tooltip-placement="top">
|
tooltip-html-unsafe="Password strength: <b>{{passwordStrength}}</b><br/><span class='size-12'>Tip: Use lower and uppercase, numbers and symbols</span>" tooltip-trigger="focus" required tooltip-placement="top">
|
||||||
<i class="icon-locked"></i>
|
<i class="icon-locked"></i>
|
||||||
|
@ -54,23 +61,19 @@
|
||||||
<span translate class="has-error size-12" ng-show="profileForm.repeatpassword.$dirty &&
|
<span translate class="has-error size-12" ng-show="profileForm.repeatpassword.$dirty &&
|
||||||
profileForm.repeatpassword.$invalid">
|
profileForm.repeatpassword.$invalid">
|
||||||
<span class="icon-input"><i class="fi-x"></i></span>
|
<span class="icon-input"><i class="fi-x"></i></span>
|
||||||
{{'Passwords must match'|translate}}
|
{{'Passwords must match'|translate}}
|
||||||
</span>
|
</span>
|
||||||
<span class="icon-input" ng-show="profileForm.repeatpassword.$dirty &&
|
<span class="icon-input" ng-show="profileForm.repeatpassword.$dirty &&
|
||||||
!profileForm.repeatpassword.$invalid"><i class="fi-check"></i></span>
|
!profileForm.repeatpassword.$invalid"><i class="fi-check"></i></span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="input">
|
<div class="input">
|
||||||
<input type="password" ng-model="repeatpassword"
|
<input type="password" ng-model="repeatpassword" class="input form-control" name="repeatpassword" placeholder="{{'Repeat password'|translate}}" match="password" required>
|
||||||
class="input form-control" name="repeatpassword"
|
|
||||||
placeholder="{{'Repeat password'|translate}}"
|
|
||||||
match="password" required>
|
|
||||||
<i class="icon-locked"></i>
|
<i class="icon-locked"></i>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button translate type="submit" class="button primary radius expand m0"
|
<button translate type="submit" class="button primary radius expand m0" ng-disabled="profileForm.$invalid || loading">
|
||||||
ng-disabled="profileForm.$invalid || loading">
|
Create
|
||||||
Create
|
|
||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
<div class="box-setup-footer">
|
<div class="box-setup-footer">
|
||||||
|
@ -89,6 +92,50 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</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>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -98,7 +98,7 @@
|
||||||
|
|
||||||
<div class="box-setup" ng-if='$root.hasPin'>
|
<div class="box-setup" ng-if='$root.hasPin'>
|
||||||
<h1><span translate>Enter your </span> <b> PIN</b></h1>
|
<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-notification" ng-show="error">
|
||||||
<div class="box-icon error">
|
<div class="box-icon error">
|
||||||
<i class="fi-x size-24"></i>
|
<i class="fi-x size-24"></i>
|
||||||
|
@ -116,7 +116,7 @@
|
||||||
<i class="icon-locked"></i>
|
<i class="icon-locked"></i>
|
||||||
</div>
|
</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">
|
ng-disabled="pinForm.$invalid || error">
|
||||||
Sign in
|
Sign in
|
||||||
</button>
|
</button>
|
||||||
|
|
Loading…
Reference in New Issue