From 212400c28303740981b0bfaf3032f1cba0d75f73 Mon Sep 17 00:00:00 2001 From: itsconquest Date: Fri, 17 Jun 2022 14:45:47 +1200 Subject: [PATCH] fix(auth): clear skips when using new instance [EE-3331] (#7027) --- app/portainer/services/stateManager.js | 16 +++++++++++----- app/portainer/views/account/accountController.js | 10 ++++++---- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/app/portainer/services/stateManager.js b/app/portainer/services/stateManager.js index 95174ae01..cf36935e0 100644 --- a/app/portainer/services/stateManager.js +++ b/app/portainer/services/stateManager.js @@ -49,6 +49,7 @@ function StateManagerFactory( }; manager.setPasswordChangeSkipped = function (userID) { + state.UI.instanceId = state.UI.instanceId || state.application.instanceId; state.UI.timesPasswordChangeSkipped = state.UI.timesPasswordChangeSkipped || {}; state.UI.timesPasswordChangeSkipped[userID] = state.UI.timesPasswordChangeSkipped[userID] + 1 || 1; LocalStorage.storeUIState(state.UI); @@ -141,11 +142,6 @@ function StateManagerFactory( manager.initialize = initialize; async function initialize() { return $async(async () => { - const UIState = LocalStorage.getUIState(); - if (UIState) { - state.UI = UIState; - } - const endpointState = LocalStorage.getEndpointState(); if (endpointState) { state.endpoint = endpointState; @@ -158,6 +154,16 @@ function StateManagerFactory( await loadApplicationState(); } + const UIState = LocalStorage.getUIState(); + if (UIState) { + state.UI = UIState; + if (state.UI.instanceId && state.UI.instanceId !== state.application.instanceId) { + state.UI.instanceId = state.application.instanceId; + state.UI.timesPasswordChangeSkipped = {}; + LocalStorage.storeUIState(state.UI); + } + } + state.loading = false; $analytics.setPortainerStatus(state.application.instanceId, state.application.version); $analytics.setOptOut(!state.application.enableTelemetry); diff --git a/app/portainer/views/account/accountController.js b/app/portainer/views/account/accountController.js index 9032abe9d..428481b1f 100644 --- a/app/portainer/views/account/accountController.js +++ b/app/portainer/views/account/accountController.js @@ -22,7 +22,7 @@ angular.module('portainer.app').controller('AccountController', [ try { await UserService.updateUserPassword($scope.userID, $scope.formValues.currentPassword, $scope.formValues.newPassword); Notifications.success('Success', 'Password successfully updated'); - StateManager.resetPasswordChangeSkips($scope.userID); + StateManager.resetPasswordChangeSkips($scope.userID.toString()); $scope.forceChangePassword = false; $state.go('portainer.logout'); } catch (err) { @@ -34,7 +34,7 @@ angular.module('portainer.app').controller('AccountController', [ $scope.skipPasswordChange = async function () { try { if ($scope.userCanSkip()) { - StateManager.setPasswordChangeSkipped($scope.userID); + StateManager.setPasswordChangeSkipped($scope.userID.toString()); $scope.forceChangePassword = false; $state.go('portainer.home'); } @@ -130,11 +130,13 @@ angular.module('portainer.app').controller('AccountController', [ $scope.AuthenticationMethod = data.AuthenticationMethod; if (state.UI.requiredPasswordLength && state.UI.requiredPasswordLength !== data.RequiredPasswordLength) { - StateManager.clearPasswordChangeSkips($scope.userID); + StateManager.clearPasswordChangeSkips($scope.userID.toString()); } $scope.timesPasswordChangeSkipped = - state.UI.timesPasswordChangeSkipped && state.UI.timesPasswordChangeSkipped[$scope.userID] ? state.UI.timesPasswordChangeSkipped[$scope.userID] : 0; + state.UI.timesPasswordChangeSkipped && state.UI.timesPasswordChangeSkipped[$scope.userID.toString()] + ? state.UI.timesPasswordChangeSkipped[$scope.userID.toString()] + : 0; $scope.requiredPasswordLength = data.RequiredPasswordLength; StateManager.setRequiredPasswordLength(data.RequiredPasswordLength);