From ece8c4234832999fb614221b2290f0134bf0fd16 Mon Sep 17 00:00:00 2001 From: blavenie <benoit.lavenier@e-is.pro> Date: Fri, 7 Jul 2017 22:26:23 +0200 Subject: [PATCH] [fix] Login: Restore previous scrypt params, if changed --- www/js/controllers/login-controllers.js | 54 +++++++++++++------ www/js/services/wallet-services.js | 2 +- www/templates/login/form_file_import.html | 2 +- www/templates/login/form_scrypt_advanced.html | 18 +++++-- 4 files changed, 55 insertions(+), 21 deletions(-) diff --git a/www/js/controllers/login-controllers.js b/www/js/controllers/login-controllers.js index 42a00b976..3b3e3a6fd 100644 --- a/www/js/controllers/login-controllers.js +++ b/www/js/controllers/login-controllers.js @@ -24,12 +24,10 @@ function LoginModalController($scope, $timeout, $q, $ionicPopover, CryptoUtils, $scope.scryptParamsValues = _.keys(CryptoUtils.constants.SCRYPT_PARAMS) .reduce(function(res, key) { return res.concat({id: key, label: 'LOGIN.SCRYPT.' + key, params: CryptoUtils.constants.SCRYPT_PARAMS[key]}); - }, [{id: 'user', label: 'LOGIN.SCRYPT.USER', params: {}}]); - - // modal enter - $scope.enter = function() { - UIUtils.loading.hide(); + }, [{id: 'USER', label: 'LOGIN.SCRYPT.USER', params: {}}]); + // modal init + $scope.init = function() { // Should auto-compute pubkey ? $scope.autoComputePubkey = ionic.Platform.grade.toLowerCase()==='a' && !UIUtils.screen.isSmall(); @@ -42,15 +40,17 @@ function LoginModalController($scope, $timeout, $q, $ionicPopover, CryptoUtils, $scope.formData.keepAuth = ($scope.formData.keepAuthIdle == csSettings.constants.KEEP_AUTH_IDLE_SESSION); // Init method - $scope.formData.method = csSettings.data.login && csSettings.data.login.method || 'SCRYPT_DEFAULT'; + var method = csSettings.data.login && csSettings.data.login.method || 'SCRYPT_DEFAULT'; var params = csSettings.data.login && csSettings.data.login.params; - if ($scope.isAuth && $scope.formData.method == 'PUBKEY') { + if ($scope.isAuth && method == 'PUBKEY') { $scope.formData.method = 'SCRYPT_DEFAULT'; - params = undefined; // will use default - } - $scope.changeMethod($scope.formData.method, params); + $scope.changeMethod(method, params); + }; + // modal enter + $scope.enter = function() { + UIUtils.loading.hide(); // Ink effect UIUtils.ink({selector: '.modal-login .ink'}); }; @@ -176,7 +176,7 @@ function LoginModalController($scope, $timeout, $q, $ionicPopover, CryptoUtils, }); }; - $scope.scryptFormDataChanged = function() { + $scope.onScryptFormChanged = function() { if ($scope.computing) return; // avoid multiple call $scope.pubkey = null; $scope.pubkeyError = false; @@ -189,7 +189,7 @@ function LoginModalController($scope, $timeout, $q, $ionicPopover, CryptoUtils, $scope.showComputePubkeyButton = !$scope.autoComputePubkey && $scope.showPubkey; } }; - $scope.$watch('formData.username + formData.password', $scope.scryptFormDataChanged, true); + $scope.$watch('formData.username + formData.password', $scope.onScryptFormChanged, true); $scope.computePubkey = function() { $scope.showComputePubkeyButton = false; @@ -218,7 +218,7 @@ function LoginModalController($scope, $timeout, $q, $ionicPopover, CryptoUtils, .catch(function (err) { UIUtils.onError('ERROR.CRYPTO_UNKNOWN_ERROR')(err); $scope.computing = false; - $scope.scryptFormDataChanged(); + $scope.onScryptFormChanged(); }); }, 100); }; @@ -245,14 +245,32 @@ function LoginModalController($scope, $timeout, $q, $ionicPopover, CryptoUtils, $scope.hideMethodsPopover(); if (method == $scope.formData.method) return; // same method - console.debug("[login] method changed: ", method); + console.debug("[login] method is: " + method); $scope.formData.method = method; - delete $scope.form.$submitted; // hide form's fields errors on the form + + if ($scope.form) { + // hide form's fields errors on the form + delete $scope.form.$submitted; + } // Scrypt (advanced or not) if (method == 'SCRYPT_DEFAULT' || method == 'SCRYPT_ADVANCED') { - var scrypt = params || _.findWhere($scope.scryptParamsValues, {id: 'DEFAULT'}); + // Search scrypt object + var scrypt; + if (params) { + scrypt = _.find($scope.scryptParamsValues, function(item){ + return item.params && angular.equals(item.params, params); + }); + if (!scrypt) { + scrypt = _.findWhere($scope.scryptParamsValues, {id: 'USER'}) || {}; + scrypt.params = params; + } + } + else { + scrypt = _.findWhere($scope.scryptParamsValues, {id: 'DEFAULT'}); + } $scope.changeScrypt(scrypt); + $scope.autoComputePubkey = $scope.autoComputePubkey && (method == 'SCRYPT_DEFAULT'); } else { @@ -266,6 +284,7 @@ function LoginModalController($scope, $timeout, $q, $ionicPopover, CryptoUtils, $scope.changeScrypt = function(scrypt) { // Protect params against changes $scope.formData.scrypt = angular.copy(scrypt||{}); + $scope.onScryptFormChanged(); }; $scope.fileChanged = function(event) { @@ -380,6 +399,9 @@ function LoginModalController($scope, $timeout, $q, $ionicPopover, CryptoUtils, } }; + // Default action + $scope.init(); + // TODO : for DEV only /*$timeout(function() { diff --git a/www/js/services/wallet-services.js b/www/js/services/wallet-services.js index e5355b01d..9ebcde2e5 100644 --- a/www/js/services/wallet-services.js +++ b/www/js/services/wallet-services.js @@ -3,7 +3,7 @@ angular.module('cesium.wallet.services', ['ngApi', 'ngFileSaver', 'cesium.bma.se 'cesium.settings.services']) -.factory('csWallet', function($q, $rootScope, $timeout, $translate, $filter, $ionicHistory, +.factory('csWallet', function($q, $rootScope, $timeout, $translate, $filter, $ionicHistory, UIUtils, Api, Idle, localStorage, sessionStorage, Modals, CryptoUtils, BMA, csConfig, csSettings, FileSaver, Blob, csWot, csTx, csCurrency) { 'ngInject'; diff --git a/www/templates/login/form_file_import.html b/www/templates/login/form_file_import.html index f4fd7ce48..574cf6609 100644 --- a/www/templates/login/form_file_import.html +++ b/www/templates/login/form_file_import.html @@ -3,7 +3,7 @@ </div> -<div class="item item-icon-left "> +<div class="item item-icon-left item-text-wrap"> <i class="icon ion-ios-information-outline positive"></i> <span class="positive" translate>LOGIN.FILE.HELP</span> </div> diff --git a/www/templates/login/form_scrypt_advanced.html b/www/templates/login/form_scrypt_advanced.html index d87edfeb4..93b21b85b 100644 --- a/www/templates/login/form_scrypt_advanced.html +++ b/www/templates/login/form_scrypt_advanced.html @@ -12,19 +12,31 @@ <div class="col no-padding"> <label class="item item-input"> <span class="input-label" translate>LOGIN.SCRYPT.N</span> - <input class="no-padding-right" type="number" placeholder="N" ng-model="formData.scrypt.params.N" required> + <input class="no-padding-right" type="number" placeholder="N" + ng-model="formData.scrypt.params.N" + ng-model-options="{ debounce: 650 }" + ng-change="onScryptFormChanged()" + required> </label> </div> <div class="col no-padding"> <label class="item item-input"> <span class="input-label" translate>LOGIN.SCRYPT.r</span> - <input class="no-padding-right" type="number" placeholder="r" ng-model="formData.scrypt.params.r" required> + <input class="no-padding-right" type="number" placeholder="r" + ng-model="formData.scrypt.params.r" + ng-model-options="{ debounce: 650 }" + ng-change="onScryptFormChanged()" + required> </label> </div> <div class="col no-padding"> <label class="item item-input"> <span class="input-label" translate>LOGIN.SCRYPT.p</span> - <input class="no-padding-right" type="number" placeholder="p" ng-model="formData.scrypt.params.p" required> + <input class="no-padding-right" type="number" placeholder="p" + ng-model="formData.scrypt.params.p" + ng-model-options="{ debounce: 650 }" + ng-change="onScryptFormChanged()" + required> </label> </div> </div> -- GitLab