This commit is contained in:
Matias Alejo Garcia 2015-01-03 18:34:07 -03:00
parent 6055164412
commit 237a707719
3 changed files with 225 additions and 214 deletions

View File

@ -23,4 +23,9 @@ android: cordova-base
release-android: cordova-base
make -C cordova release-android
wp8:
cordova/build.sh WP8
cordova/wp/fix-svg.sh
echo -e "\a"

View File

@ -1,214 +1,222 @@
'use strict';
angular.module('copayApp.controllers').controller('CreateProfileController', function($scope, $rootScope, $location, $timeout, $window, notification, pluginManager, identityService, pinService, isMobile, isCordova, configService, go) {
angular.module('copayApp.controllers').controller('CreateProfileController', function ($scope, $rootScope, $location, $timeout, $window, notification, pluginManager, identityService, pinService, isMobile, isCordova, configService, go) {
var _credentials, _firstpin;
var _credentials, _firstpin;
$scope.init = function() {
$scope.init = function () {
if ($rootScope.wallet)
go.walletHome();
if ($rootScope.wallet)
go.walletHome();
$scope.isMobile = isMobile.any();
$scope.isWindowsPhoneApp = isMobile.Windows() && isCordova;
$scope.hideForWP = 0;
$scope.createStep = 'storage';
$scope.useLocalstorage = false;
$scope.minPasswordStrength = _.isUndefined(config.minPasswordStrength) ?
4 : config.minPasswordStrength;
pinService.makePinInput($scope, 'newpin', function(newValue) {
_firstpin = newValue;
$scope.askForPin = 2;
$scope.hideForWP = 0;
});
pinService.makePinInput($scope, 'repeatpin', function(newValue) {
if (newValue === _firstpin) {
_firstpin = null;
$scope.createPin(newValue);
} else {
$scope.askForPin = 1;
$scope.hideForWP = 0;
_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.isMobile = isMobile.any();
$scope.isWindowsPhoneApp = isMobile.Windows() && isCordova;
$scope.hideForWP = 0;
$scope.formFocus = function() {
if ($scope.isWindowsPhoneApp) {
$scope.hideForWP = true;
$timeout(function() {
$scope.$digest();
}, 1);
}
};
$scope.createPin = function(pin) {
preconditions.checkArgument(pin);
preconditions.checkState($rootScope.iden);
preconditions.checkState(_credentials && _credentials.email);
$rootScope.starting = true;
$scope.createStep = 'storage';
$scope.useLocalstorage = false;
$scope.minPasswordStrength = _.isUndefined(config.minPasswordStrength) ?
4 : config.minPasswordStrength;
// hide Keyboard after submit form
$window.document.querySelector('#repeatpin').blur();
$timeout(function() {
pinService.save(pin, _credentials.email, _credentials.password, function(err) {
_credentials.password = '';
_credentials = null;
$scope.askForPin = 0;
$rootScope.hasPin = true;
$rootScope.starting = null;
$scope.createDefaultWallet();
});
}, 100);
};
pinService.makePinInput($scope, 'newpin', function (newValue) {
_firstpin = newValue;
$scope.hideForWP = 0;
$scope.askForPin = 2;
$timeout(function () {
$scope.$digest();
}, 1);
$scope.setStep = function(step) {
$scope.error = null;
$scope.createStep = step;
$scope.hideForWP = false;
$timeout(function() {
$scope.$digest();
}, 1);
};
});
$scope.selectStorage = function(storage) {
$scope.useLocalstorage = storage == 'local';
$scope.hideForWP = false;
$timeout(function() {
$scope.$digest();
}, 1);
};
pinService.makePinInput($scope, 'repeatpin', function (newValue) {
if (newValue === _firstpin) {
_firstpin = null;
$scope.createPin(newValue);
} else {
$scope.askForPin = 1;
$scope.hideForWP = 0;
$scope.passwordStrength = null;
$scope.goToEmail = function() {
$scope.createStep = 'email';
$scope.useEmail = !$scope.useLocalstorage;
};
_firstpin = null;
$scope.setEmailOrUsername = function(form) {
$scope.userOrEmail = $scope.useLocalstorage ? form.username.$modelValue : form.email.$modelValue;
preconditions.checkState($scope.userOrEmail);
$scope.setPinForm.newpin.$setViewValue('');
$scope.setPinForm.newpin.$render();
$scope.setPinForm.repeatpin.$setViewValue('');
$scope.setPinForm.repeatpin.$render();
$scope.setPinForm.$setPristine();
$scope.error = null;
$scope.hideForWP = false;
$scope.createStep = 'pass';
$timeout(function() {
$scope.$digest();
}, 1);
};
$scope.error = 'Entered PINs were not equal. Try again';
$timeout(function () {
$scope.$digest();
}, 1);
}
});
};
/* Last step. Will emit after creation so the UX gets updated */
$scope.createDefaultWallet = function() {
$rootScope.hideNavigation = false;
identityService.createDefaultWallet(function(err) {
$scope.askForPin = 0;
if (err) {
var msg = err.toString();
$scope.error = msg;
} else {
if (!$scope.useLocalstorage) {
$rootScope.pleaseConfirmEmail = true;
$scope.formFocus = function () {
if ($scope.isWindowsPhoneApp) {
$scope.hideForWP = true;
$timeout(function () {
$scope.$digest();
}, 1);
}
}
};
$scope.createPin = function (pin) {
preconditions.checkArgument(pin);
preconditions.checkState($rootScope.iden);
preconditions.checkState(_credentials && _credentials.email);
$rootScope.starting = true;
});
};
// hide Keyboard after submit form
$window.document.querySelector('#repeatpin').blur();
$scope._doCreateProfile = function(emailOrUsername, password, cb) {
preconditions.checkArgument(_.isString(emailOrUsername));
preconditions.checkArgument(_.isString(password));
$rootScope.hideNavigation = false;
$rootScope.starting = true;
identityService.create(emailOrUsername, password, function(err) {
$rootScope.starting = null;
$scope.error = null;
if (err) {
var msg = err.toString();
if (msg.indexOf('EEXIST') >= 0 || msg.indexOf('BADC') >= 0) {
msg = 'This profile already exists'
$scope.createStep = 'email';
}
if (msg.indexOf('EMAILERROR') >= 0) {
msg = 'Could not send verification email. Please check your email address.';
$scope.createStep = 'email';
}
$scope.error = msg;
$scope.passwordStrength = null;
} else {
// mobile
if ($scope.isMobile) {
_credentials = {
email: emailOrUsername,
password: password,
};
$scope.askForPin = 1;
$scope.hideForWP = 0;
$rootScope.hideNavigation = true;
$timeout(function() {
$rootScope.$digest();
}, 1);
return;
} else {
$scope.createDefaultWallet();
}
}
return cb();
});
};
$timeout(function () {
pinService.save(pin, _credentials.email, _credentials.password, function (err) {
_credentials.password = '';
_credentials = null;
$scope.askForPin = 0;
$rootScope.hasPin = true;
$rootScope.starting = null;
$scope.createDefaultWallet();
});
}, 100);
};
$scope.saveSettings = function(cb) {
var plugins = config.plugins;
plugins.EncryptedLocalStorage = false;
plugins.EncryptedInsightStorage = false;
var pluginName = $scope.useLocalstorage ? 'EncryptedLocalStorage' : 'EncryptedInsightStorage';
plugins[pluginName] = true;
configService.set({
plugins: plugins
}, cb);
};
$scope.createProfile = function(form) {
if (form && form.$invalid) {
$scope.error = 'Please enter the required fields';
return;
}
$scope.saveSettings(function(err) {
preconditions.checkState(!err, err);
$scope._doCreateProfile($scope.userOrEmail, form.password.$modelValue, function(err) {
$timeout(function() {
form.password.$setViewValue('');
form.password.$render();
form.repeatpassword.$setViewValue('');
form.repeatpassword.$render();
form.$setPristine();
$scope.setStep = function (step) {
$scope.error = null;
$scope.createStep = step;
$scope.hideForWP = false;
$timeout(function () {
$scope.$digest();
}, 1);
});
});
};
};
$scope.selectStorage = function (storage) {
$scope.useLocalstorage = storage == 'local';
$scope.hideForWP = false;
$timeout(function () {
$scope.$digest();
}, 1);
};
$scope.goToEmail = function () {
$scope.createStep = 'email';
$scope.useEmail = !$scope.useLocalstorage;
};
$scope.setEmailOrUsername = function (form) {
$scope.userOrEmail = $scope.useLocalstorage ? form.username.$modelValue : form.email.$modelValue;
preconditions.checkState($scope.userOrEmail);
$scope.error = null;
$scope.hideForWP = false;
$scope.createStep = 'pass';
$timeout(function () {
$scope.$digest();
}, 1);
};
/* Last step. Will emit after creation so the UX gets updated */
$scope.createDefaultWallet = function () {
$rootScope.hideNavigation = false;
identityService.createDefaultWallet(function (err) {
$scope.askForPin = 0;
if (err) {
var msg = err.toString();
$scope.error = msg;
} else {
if (!$scope.useLocalstorage) {
$rootScope.pleaseConfirmEmail = true;
}
}
});
};
$scope._doCreateProfile = function (emailOrUsername, password, cb) {
preconditions.checkArgument(_.isString(emailOrUsername));
preconditions.checkArgument(_.isString(password));
$rootScope.hideNavigation = false;
$rootScope.starting = true;
identityService.create(emailOrUsername, password, function (err) {
$rootScope.starting = null;
$scope.error = null;
if (err) {
var msg = err.toString();
if (msg.indexOf('EEXIST') >= 0 || msg.indexOf('BADC') >= 0) {
msg = 'This profile already exists'
$scope.createStep = 'email';
}
if (msg.indexOf('EMAILERROR') >= 0) {
msg = 'Could not send verification email. Please check your email address.';
$scope.createStep = 'email';
}
$scope.error = msg;
$scope.passwordStrength = null;
} else {
// mobile
if ($scope.isMobile) {
_credentials = {
email: emailOrUsername,
password: password,
};
$scope.askForPin = 1;
$scope.hideForWP = 0;
$rootScope.hideNavigation = true;
$timeout(function () {
$rootScope.$digest();
}, 1);
return;
} else {
$scope.createDefaultWallet();
}
}
return cb();
});
};
$scope.saveSettings = function (cb) {
var plugins = config.plugins;
plugins.EncryptedLocalStorage = false;
plugins.EncryptedInsightStorage = false;
var pluginName = $scope.useLocalstorage ? 'EncryptedLocalStorage' : 'EncryptedInsightStorage';
plugins[pluginName] = true;
configService.set({
plugins: plugins
}, cb);
};
$scope.createProfile = function (form) {
if (form && form.$invalid) {
$scope.error = 'Please enter the required fields';
return;
}
$scope.saveSettings(function (err) {
preconditions.checkState(!err, err);
$scope._doCreateProfile($scope.userOrEmail, form.password.$modelValue, function (err) {
$timeout(function () {
form.password.$setViewValue('');
form.password.$render();
form.repeatpassword.$setViewValue('');
form.repeatpassword.$render();
form.$setPristine();
}, 1);
});
});
};
});

View File

@ -149,11 +149,11 @@
<form ng-show="createStep == 'pass'" name="passForm" ng-submit="createProfile(passForm)" novalidate>
<div class="box-notification" ng-show="passwordStrength">
<div class="box-icon" ng-if="passwordStrength.strength< minPasswordStrength" style="background-color:#dd514c">
<i class="fi-x size-24"></i>
</div>
<div class="box-icon" ng-if="passwordStrength.strength >= minPasswordStrength" style="background-color:#16A085">
<i class="fi-check size-24"></i>
<div class="box-icon" ng-if="passwordStrength.strength< minPasswordStrength" style="background-color:#dd514c">
<i class="fi-x size-24"></i>
</div>
<div class="box-icon" ng-if="passwordStrength.strength >= minPasswordStrength" style="background-color:#16A085">
<i class="fi-check size-24"></i>
</div>
<span class="size-14" >
Password Strength: {{passwordStrength.message}}
@ -214,31 +214,29 @@
</div>
<form name="setPinForm" novalidate>
<div class="input" ng-show="askForPin == 1">
<div class="input" ng-if="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 && !isWindowsPhoneApp" ng-focus="formFocus()">
<i class="icon-locked"></i>
<i class="icon-locked" ng-hide="isWindowsPhoneApp"></i>
</div>
<div class="input" ng-show="askForPin == 2">
<div class="input" ng-if="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 && !isWindowsPhoneApp" ng-focus="formFocus()">
<i class="icon-locked"></i>
<i class="icon-locked" ng-hide="isWindowsPhoneApp"></i>
</div>
<div class="box-setup-footer row collapse">
<div class="large-6 medium-6 small-6 columns">
<a class="button secondary radius m0" ng-click="createDefaultWallet()">
<span translate>Skip</span>
</a>
<div class="box-setup-footer row collapse">
<div class="large-6 medium-6 small-6 columns">
<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">
<button translate ng-click="createPin(setPinForm.repeatpin.$modelValue)" class="button primary radius expand m0"
ng-disabled="setPinForm.$invalid || error">
OK
</button>
</div>
</div>
<div class="large-6 medium-6 small-6 columns text-right">
<button translate ng-click="createPin(setPinForm.repeatpin.$modelValue)" class="button primary radius expand m0"
ng-disabled="setPinForm.$invalid || error">
OK
</button>
</div>
</div>
</form>
</form>
</div>
</div>