From 755ecd6fb50204f61d08ffbc970d5ecd1ec84346 Mon Sep 17 00:00:00 2001 From: Mo Bitar Date: Sun, 14 Oct 2018 13:31:14 -0500 Subject: [PATCH] Password wizard lock continue, SFJS 0.3.18 --- .../app/directives/views/passwordWizard.js | 31 +++++++++++++++++++ .../directives/password-wizard.html.haml | 3 +- package-lock.json | 6 ++-- package.json | 2 +- 4 files changed, 36 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/app/directives/views/passwordWizard.js b/app/assets/javascripts/app/directives/views/passwordWizard.js index 09dd413f1..f93bed6d5 100644 --- a/app/assets/javascripts/app/directives/views/passwordWizard.js +++ b/app/assets/javascripts/app/directives/views/passwordWizard.js @@ -15,7 +15,20 @@ class PasswordWizard { controller($scope, modelManager, archiveManager, authManager, syncManager, $timeout) { 'ngInject'; + window.onbeforeunload = (e) => { + // Confirms with user to close tab before closing + return true; + }; + + $scope.$on("$destroy", function() { + window.onbeforeunload = null; + }); + $scope.dismiss = function() { + if($scope.lockContinue) { + alert("Cannot close window until pending tasks are complete."); + return; + } $scope.el.remove(); $scope.$destroy(); } @@ -64,6 +77,15 @@ class PasswordWizard { $scope.continue = function() { + if($scope.lockContinue || $scope.isContinuing) { + return; + } + + // isContinuing is a way to lock the continue function separate from lockContinue + // lockContinue can be locked by other places, but isContinuing is only lockable from within this function. + + $scope.isContinuing = true; + if($scope.step == FinishStep) { $scope.dismiss(); return; @@ -72,6 +94,8 @@ class PasswordWizard { let next = () => { $scope.step += 1; $scope.initializeStep($scope.step); + + $scope.isContinuing = false; } var preprocessor = $scope.preprocessorForStep($scope.step); @@ -151,8 +175,15 @@ class PasswordWizard { let currentPassword = $scope.formData.currentPassword; let newPass = $scope.securityUpdate ? currentPassword : $scope.formData.newPassword; + if(!currentPassword || currentPassword.length == 0) { + alert("Please enter your current password."); + callback(false); + return; + } + if($scope.changePassword) { if(!newPass || newPass.length == 0) { + alert("Please enter a new password."); callback(false); return; } diff --git a/app/assets/templates/directives/password-wizard.html.haml b/app/assets/templates/directives/password-wizard.html.haml index 6ede6d8d0..cbcdf6f54 100644 --- a/app/assets/templates/directives/password-wizard.html.haml +++ b/app/assets/templates/directives/password-wizard.html.haml @@ -72,7 +72,6 @@ .panel-column.stretch %form %input.form-control{:type => 'password', "ng-model" => "formData.currentPassword", "placeholder" => "Current Password", "sn-autofocus" => "true", "should-focus" => "true"} - %input.form-control{"ng-if" => "changePassword", :type => 'password', "ng-model" => "formData.newPassword", "placeholder" => "New Password"} %input.form-control{"ng-if" => "changePassword", :type => 'password', "ng-model" => "formData.newPasswordConfirmation", "placeholder" => "Confirm New Password"} @@ -104,6 +103,6 @@ .footer .empty - %a.right{"ng-click" => "continue()", "ng-class" => "{'disabled' : lockContinue}"} + %a.right{"ng-click" => "continue()", "ng-disabled" => "lockContinue", "ng-class" => "{'disabled' : lockContinue}"} .spinner.small.inline.info.mr-5{"ng-if" => "showSpinner"} {{continueTitle}} diff --git a/package-lock.json b/package-lock.json index 5eb5f0f6c..5eca12eab 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8006,9 +8006,9 @@ "dev": true }, "standard-file-js": { - "version": "0.3.17", - "resolved": "https://registry.npmjs.org/standard-file-js/-/standard-file-js-0.3.17.tgz", - "integrity": "sha512-YeX33yz19TB+JrkCWigO21Tugw6oVRi2s8m0lHG0JSOPr4UNA7ufdbzcFgQyDbh6UvF6eCevb1uezt3A3nejmQ==", + "version": "0.3.18", + "resolved": "https://registry.npmjs.org/standard-file-js/-/standard-file-js-0.3.18.tgz", + "integrity": "sha512-5EyOohX7qTZ5zmbnPP0L1bA07SZCd6U0wKEx9j5JXUT5xF2YVDc6clV4kkAmsXAwoMIGZQIs4x2Nvqc5ka4nCQ==", "dev": true }, "static-extend": { diff --git a/package.json b/package.json index 20fd8c1fe..3bedb384d 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "karma-jasmine": "^1.1.0", "karma-phantomjs-launcher": "^1.0.2", "sn-stylekit": "1.0.15", - "standard-file-js": "0.3.17", + "standard-file-js": "0.3.18", "sn-models": "0.1.9", "connect": "^3.6.6", "mocha": "^5.2.0",