fix(auth): clear skips when using new instance [EE-3331] (#7027)

pull/7089/head^2
itsconquest 2022-06-17 14:45:47 +12:00 committed by GitHub
parent 8ed41de815
commit 212400c283
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 9 deletions

View File

@ -49,6 +49,7 @@ function StateManagerFactory(
}; };
manager.setPasswordChangeSkipped = function (userID) { manager.setPasswordChangeSkipped = function (userID) {
state.UI.instanceId = state.UI.instanceId || state.application.instanceId;
state.UI.timesPasswordChangeSkipped = state.UI.timesPasswordChangeSkipped || {}; state.UI.timesPasswordChangeSkipped = state.UI.timesPasswordChangeSkipped || {};
state.UI.timesPasswordChangeSkipped[userID] = state.UI.timesPasswordChangeSkipped[userID] + 1 || 1; state.UI.timesPasswordChangeSkipped[userID] = state.UI.timesPasswordChangeSkipped[userID] + 1 || 1;
LocalStorage.storeUIState(state.UI); LocalStorage.storeUIState(state.UI);
@ -141,11 +142,6 @@ function StateManagerFactory(
manager.initialize = initialize; manager.initialize = initialize;
async function initialize() { async function initialize() {
return $async(async () => { return $async(async () => {
const UIState = LocalStorage.getUIState();
if (UIState) {
state.UI = UIState;
}
const endpointState = LocalStorage.getEndpointState(); const endpointState = LocalStorage.getEndpointState();
if (endpointState) { if (endpointState) {
state.endpoint = endpointState; state.endpoint = endpointState;
@ -158,6 +154,16 @@ function StateManagerFactory(
await loadApplicationState(); 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; state.loading = false;
$analytics.setPortainerStatus(state.application.instanceId, state.application.version); $analytics.setPortainerStatus(state.application.instanceId, state.application.version);
$analytics.setOptOut(!state.application.enableTelemetry); $analytics.setOptOut(!state.application.enableTelemetry);

View File

@ -22,7 +22,7 @@ angular.module('portainer.app').controller('AccountController', [
try { try {
await UserService.updateUserPassword($scope.userID, $scope.formValues.currentPassword, $scope.formValues.newPassword); await UserService.updateUserPassword($scope.userID, $scope.formValues.currentPassword, $scope.formValues.newPassword);
Notifications.success('Success', 'Password successfully updated'); Notifications.success('Success', 'Password successfully updated');
StateManager.resetPasswordChangeSkips($scope.userID); StateManager.resetPasswordChangeSkips($scope.userID.toString());
$scope.forceChangePassword = false; $scope.forceChangePassword = false;
$state.go('portainer.logout'); $state.go('portainer.logout');
} catch (err) { } catch (err) {
@ -34,7 +34,7 @@ angular.module('portainer.app').controller('AccountController', [
$scope.skipPasswordChange = async function () { $scope.skipPasswordChange = async function () {
try { try {
if ($scope.userCanSkip()) { if ($scope.userCanSkip()) {
StateManager.setPasswordChangeSkipped($scope.userID); StateManager.setPasswordChangeSkipped($scope.userID.toString());
$scope.forceChangePassword = false; $scope.forceChangePassword = false;
$state.go('portainer.home'); $state.go('portainer.home');
} }
@ -130,11 +130,13 @@ angular.module('portainer.app').controller('AccountController', [
$scope.AuthenticationMethod = data.AuthenticationMethod; $scope.AuthenticationMethod = data.AuthenticationMethod;
if (state.UI.requiredPasswordLength && state.UI.requiredPasswordLength !== data.RequiredPasswordLength) { if (state.UI.requiredPasswordLength && state.UI.requiredPasswordLength !== data.RequiredPasswordLength) {
StateManager.clearPasswordChangeSkips($scope.userID); StateManager.clearPasswordChangeSkips($scope.userID.toString());
} }
$scope.timesPasswordChangeSkipped = $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; $scope.requiredPasswordLength = data.RequiredPasswordLength;
StateManager.setRequiredPasswordLength(data.RequiredPasswordLength); StateManager.setRequiredPasswordLength(data.RequiredPasswordLength);