This commit is contained in:
Gustavo Maximiliano Cortez 2014-12-02 16:16:31 -03:00
parent d045fc719e
commit 0c0e11aad3
3 changed files with 183 additions and 20 deletions

View File

@ -1,28 +1,52 @@
'use strict';
angular.module('copayApp.controllers').controller('HomeController', function($scope, $rootScope, $location, $timeout, notification, identityService, Compatibility) {
// This is only for backwards compat, insight api should link to #!/confirmed directly
if (getParam('confirmed')) {
var hashIndex = window.location.href.indexOf('/?');
window.location = window.location.href.substr(0, hashIndex) + '#!/confirmed';
return;
}
angular.module('copayApp.controllers').controller('HomeController', function($scope, $rootScope, $location, $timeout, notification, identityService, Compatibility, pinService) {
$scope.init = function() {
// This is only for backwards compat, insight api should link to #!/confirmed directly
if (getParam('confirmed')) {
var hashIndex = window.location.href.indexOf('/?');
window.location = window.location.href.substr(0, hashIndex) + '#!/confirmed';
return;
}
if ($rootScope.fromEmailConfirmation) {
$scope.confirmedEmail = true;
$rootScope.fromEmailConfirmation = false;
}
if ($rootScope.fromEmailConfirmation) {
$scope.confirmedEmail = true;
$rootScope.fromEmailConfirmation = false;
}
Compatibility.check($scope);
$scope.hasPin = pinService.check();
};
Object.defineProperty($scope,
"pin", {
get: function() {
return this._pin;
},
set: function(newValue) {
console.log('[home.js:26]',newValue, this._pin); //TODO
this._pin = newValue;
if (newValue && newValue.length == 4) {
console.log('[home.js:26] INGRESANDO AUTOMATICAMENTE',newValue); //TODO
$scope.openPin(newValue);
}
if (!newValue) {
$scope.error = null;
}
},
enumerable: true,
configurable: true
});
Compatibility.check($scope);
$scope.done = function() {
$scope.hasPin = pinService.check();
$rootScope.starting = false;
$rootScope.$digest();
};
$scope.$on("$destroy", function(){
$scope.$on("$destroy", function() {
var iden = $rootScope.iden;
if (iden) {
iden.removeListener('newWallet', $scope.done );
@ -30,20 +54,57 @@ angular.module('copayApp.controllers').controller('HomeController', function($sc
}
});
$scope.openProfile = function(form) {
$scope.openWithPin = function(form) {
$scope.confirmedEmail = false;
if (form && form.$invalid) {
$scope.error = 'Please enter the required fields';
return;
}
$scope.openPin(pin);
};
$scope.openPin = function(pin) {
var credentials = pinService.get(parseInt(pin));
if (!credentials) {
$scope.error = 'Wrong PIN';
return;
}
$rootScope.starting = true;
identityService.open(form.email.$modelValue, form.password.$modelValue, function(err, iden) {
if (err) {
$scope.open(credentials.email, credentials.password);
};
$scope.createPin = function(form) {
if (form) {
pinService.save(form.repeatpin.$modelValue, $scope.email, $scope.password);
}
$scope.open($scope.email, $scope.password);
};
$scope.openWithCredentials = function(form) {
$scope.confirmedEmail = false;
if (form && form.$invalid) {
$scope.error = 'Please enter the required fields';
return;
}
if (!$scope.hasPin) {
$scope.email = form.email.$modelValue;
$scope.password = form.password.$modelValue;
$scope.setPin = true;
return;
}
$scope.open(form.email.$modelValue, form.password.$modelValue);
};
$scope.open = function(email, password) {
$rootScope.starting = true;
identityService.open(email, password, function(err, iden) {
if (err) {
$rootScope.starting = false;
copay.logger.warn(err);
if ((err.toString() || '').match('PNOTFOUND')) {
$scope.error = 'Invalid email or password';
pinService.clear();
} else if ((err.toString() || '').match('Connection')) {
$scope.error = 'Could not connect to Insight Server';
} else if ((err.toString() || '').match('Unable')) {

38
js/services/pinService.js Normal file
View File

@ -0,0 +1,38 @@
'use strict';
angular.module('copayApp.services')
.factory('pinService', function($rootScope) {
var root = {};
var storage = {
pinData: {
pin: 1234,
credentials: {
email: '4@queparece',
password: '1',
}
}
};
root.check = function() {
return storage.pinData ? true : false;
};
root.get = function(pin) {
var storedPin = storage.pinData.pin;
if (storedPin !== pin)
return;
return storage.pinData.credentials;
};
root.save = function(pin, email, password) {
storage.pinData = {
pin: pin,
credentials: {
email: email,
password: password
}
};
};
root.clear = function(){
delete storage['pinData'];
};
return root;
});

View File

@ -1,4 +1,4 @@
<div class="home" ng-controller="HomeController">
<div class="home" ng-controller="HomeController" ng-init="init()">
<div class="loading-screen" ng-show="$root.starting">
<div class="spinner">
@ -47,9 +47,72 @@
<a class="text-white" href="#!/createProfile">creating your profile</a>
</div>
<div class="box-setup">
<div class="box-setup" ng-if='setPin'>
<h1><span translate>Set your </span> <b> PIN number</b></h1>
<form name="setPinForm" ng-submit="createPin(setPinForm)" novalidate>
<div class="input">
<input id="setpin" type="tel" ng-model="setpin" class="form-control"
ng-maxlength="4" ng-minlength="4" maxlength="4"
placeholder="Pin number" name="setpin" required auto-focus>
<i class="icon-locked"></i>
</div>
<div class="input">
<input id="repeatpin" type="tel" ng-model="repeatpin" class="form-control"
ng-maxlength="4" ng-minlength="4" maxlength="4"
placeholder="Repeat pin number" name="repeatpin"
match="setpin" required>
<i class="icon-locked"></i>
</div>
<p class="text-warning size-12" ng-show="setPinForm.repeatpin.$dirty && setPinForm.repeatpin.$invalid">
<i class="fi-x"></i>
{{'Pin must match'|translate}}
</p>
<button translate type="submit" class="button primary radius expand m0"
ng-disabled="setPinForm.$invalid || loading">
Set pin
</button>
</form>
<div class="box-setup-footer text-right">
<a class="text-gray" ng-click="createPin()">
<span translate>Skip</span>
<i class="icon-arrow-right3"></i>
</a>
</div>
</div>
<div class="box-setup" ng-if='hasPin'>
<h1><span translate>Enter your </span> <b> PIN number</b></h1>
<form name="pinForm" ng-submit="openWithPin(pinForm)" novalidate>
<p class="text-warning size-12" ng-show="error">
<i class="fi-x"></i>
{{error|translate}}
</p>
<div class="input">
<input id="pin" type="tel" ng-model="pin" class="form-control"
ng-maxlength="4" ng-minlength="4" maxlength="4"
placeholder="Pin number" name="pin" required auto-focus>
<i class="icon-locked"></i>
</div>
<button translate type="submit" class="button primary radius expand m0"
ng-disabled="pinForm.$invalid || loading">
Sign in
</button>
</form>
<div class="box-setup-footer text-right">
<a class="text-gray" ng-click="pinLogout()">
<i class="icon-power"></i>
<span translate>Logout</span>
</a>
</div>
</div>
<div class="box-setup" ng-if='!hasPin && !setPin'>
<h1><span translate>Sign in to</span> <b>Copay</b></h1>
<form name="loginForm" ng-submit="openProfile(loginForm)" novalidate>
<form name="loginForm" ng-submit="openWithCredentials(loginForm)" novalidate>
<p class="text-warning size-12"
ng-show="error">
<i class="fi-x"></i>
@ -71,6 +134,7 @@
Sign in
</button>
</form>
<div class="box-setup-footer">
<div class="left m10r">
<a class="button-setup text-gray" href="#!/createProfile">