fix login / create form errors and confirmed messages

This commit is contained in:
Matias Alejo Garcia 2014-11-01 21:34:03 -03:00
commit 3360c31a12
10 changed files with 74 additions and 23 deletions

View file

@ -2,11 +2,10 @@
angular.module('copayApp.controllers').controller('CreateProfileController', function($scope, $rootScope, $location, notification, controllerUtils, pluginManager, identityService) {
controllerUtils.redirIfLogged();
$scope.retreiving = false;
$scope.loading = false;
$scope.createProfile = function(form) {
if (form && form.$invalid) {
notification.error('Error', 'Please enter the required fields');
$scope.error('Error', 'Please enter the required fields');
return;
}
$scope.loading = true;

View file

@ -0,0 +1,6 @@
'use strict';
angular.module('copayApp.controllers').controller('EmailConfirmationController', function($scope, $rootScope, $location) {
$rootScope.fromEmailConfirmation = true;
$location.path('/');
});

View file

@ -2,13 +2,27 @@
angular.module('copayApp.controllers').controller('HomeController', function($scope, $rootScope, $location, notification, controllerUtils, pluginManager, identityService, Compatibility) {
controllerUtils.redirIfLogged();
$scope.confirmedEmail = getParam('confirmed');
// 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;
}
$scope.retreiving = false;
Compatibility.check($scope);
$scope.openProfile = function(form) {
$scope.confirmedEmail = false;
if (form && form.$invalid) {
notification.error('Error', 'Please enter the required fields');
$scope.error = 'Please enter the required fields';
return;
}
$scope.loading = true;

View file

@ -5,7 +5,7 @@ var Identity = require('../models/Identity');
function InsightStorage(config) {
this.type = 'DB';
this.storeUrl = config.url || 'https://insight.is/api/email';
this.storeUrl = config.url || 'https://test-insight.bitpay.com:443/api/email';
this.request = config.request || request;
}
@ -65,7 +65,7 @@ InsightStorage.prototype.setItem = function(name, value, callback) {
return callback('Connection error');
}
if (response.statusCode === 409) {
return callback('Invalid username or password');
return callback('BADCREDENTIALS: Invalid username or password');
}
if (response.statusCode !== 200) {
return callback('Unable to store data on insight');

View file

@ -15,6 +15,10 @@ angular
.when('/unsupported', {
templateUrl: 'views/unsupported.html'
})
.when('/confirmed', {
template: " ", // just fire controller
controller: 'EmailConfirmationController',
})
.when('/uri-payment/:data', {
templateUrl: 'views/uri-payment.html'
})

View file

@ -33,8 +33,14 @@ angular.module('copayApp.services')
passphraseConfig: config.passphraseConfig,
failIfExists: true,
}, function(err, iden) {
scope.loading = false;
if (err || !iden) {
controllerUtils.onErrorDigest(scope, 'User already exists!');
copay.logger.debug(err);
if (err && ( err.match('EEXISTS') || err.match('BADCREDENTIALS'))) {
scope.error = 'User already exists!';
} else {
scope.error = 'Unknown error when connecting Insight Server';
}
return;
}
var walletOptions = {
@ -47,10 +53,10 @@ angular.module('copayApp.services')
};
iden.createWallet(walletOptions, function(err, wallet) {
if (err || !wallet) {
controllerUtils.onErrorDigest(scope, 'Could not create default wallet');
copay.logger.debug(err);
scope.error = 'Could not create default wallet';
return;
}
scope.loading = false;
controllerUtils.bindProfile(scope, iden, wallet.id);
});
});
@ -69,8 +75,12 @@ angular.module('copayApp.services')
passphraseConfig: config.passphraseConfig,
}, function(err, iden) {
if (err && !iden) {
controllerUtils.onErrorDigest(
scope, (err.toString() || '').match('PNOTFOUND') ? 'Invalid email or password' : 'Unknown error');
if ((err.toString() || '').match('PNOTFOUND')) {
scope.error = 'Invalid email or password';
}
else {
scope.error = 'Unknown error';
}
} else {
var firstWallet = iden.getLastFocusedWallet();
controllerUtils.bindProfile(scope, iden, firstWallet);