pin in create

This commit is contained in:
Matias Alejo Garcia 2014-12-03 16:01:22 -03:00 committed by Gustavo Maximiliano Cortez
parent 2f6e28f5e7
commit 1d7e9dda93
5 changed files with 201 additions and 58 deletions

View File

@ -1,23 +1,80 @@
'use strict';
angular.module('copayApp.controllers').controller('CreateProfileController', function($scope, $rootScope, $location, $timeout, notification, pluginManager, identityService) {
identityService.goWalletHome();
angular.module('copayApp.controllers').controller('CreateProfileController', function($scope, $rootScope, $location, $timeout, notification, pluginManager, identityService, pinService) {
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) {
$rootScope.hideNavigation = false;
if (form && form.$invalid) {
$scope.error('Error', 'Please enter the required fields');
$scope.error = 'Please enter the required fields';
return;
}
$rootScope.starting = true;
identityService.create(
form.email.$modelValue, form.password.$modelValue, function(err) {
$rootScope.starting = false;
if (err) {
var msg = err.toString();
if (msg.indexOf('EEXIST')>=0 || msg.indexOf('BADC')>=0 ) {
msg = 'This profile already exists'
}
$timeout(function() {
$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() {
form.email.$setViewValue('');
form.email.$render();
form.password.$setViewValue('');
@ -27,7 +84,28 @@ 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();
}
}
});
}
});

View File

@ -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) {
@ -39,11 +39,18 @@ angular.module('copayApp.controllers').controller('HomeController', function($sc
pinService.makePinInput($scope, 'repeatpin', function(newValue) {
if (newValue === _firstpin) {
_firstpin = null;
_firstpin = null;
$scope.createPin(newValue);
} else {
_firstpin = null;
_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) {

View File

@ -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,23 +55,30 @@ 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);
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);
});
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,
requiredCopayers: 1,
totalCopayers: 1,
password: iden.password,
name: 'My wallet',
};
iden.createWallet(walletOptions, function(err, wallet) {
return cb(err);
});
};
root.setServerStatus = function(headers) {

View File

@ -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 class="spinner">
<div class="contener_general">
<div class="contener_mixte"><div class="ballcolor ball_1">&nbsp;</div></div>
<div class="contener_mixte"><div class="ballcolor ball_2">&nbsp;</div></div>
<div class="contener_mixte"><div class="ballcolor ball_3">&nbsp;</div></div>
<div class="contener_mixte"><div class="ballcolor ball_4">&nbsp;</div></div>
<div class="contener_mixte">
<div class="ballcolor ball_1">&nbsp;</div>
</div>
<div class="contener_mixte">
<div class="ballcolor ball_2">&nbsp;</div>
</div>
<div class="contener_mixte">
<div class="ballcolor ball_3">&nbsp;</div>
</div>
<div class="contener_mixte">
<div class="ballcolor ball_4">&nbsp;</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>
</div>
</div>
<div class="box-setup">
<h1>Create Profile</h1>
<div class="box-notification" ng-show="error">
<div class="box-icon error">
<i class="fi-x size-24"></i>
</div>
</div>
<span class="text-warning size-14">
{{error|translate}}
</span>
@ -32,19 +40,18 @@
<span translate class="has-error size-12" ng-show="profileForm.email.$invalid &&
!profileForm.email.$pristine">
<span class="icon-input"><i class="fi-x"></i></span>
Not valid
Not valid
</span>
<span class="icon-input" ng-show="!profileForm.email.$invalid &&
!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>
<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"
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>
@ -54,23 +61,19 @@
<span translate class="has-error size-12" ng-show="profileForm.repeatpassword.$dirty &&
profileForm.repeatpassword.$invalid">
<span class="icon-input"><i class="fi-x"></i></span>
{{'Passwords must match'|translate}}
{{'Passwords must match'|translate}}
</span>
<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 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">
Create
<button translate type="submit" class="button primary radius expand m0" ng-disabled="profileForm.$invalid || loading">
Create
</button>
</form>
<div class="box-setup-footer">
@ -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>

View File

@ -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>