1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-08-10 00:05:24 +02:00

feat(user):logout after change password EE-1590 (#6267)

* fix(user) logout after password change
This commit is contained in:
sunportainer 2022-01-21 08:33:43 +08:00 committed by GitHub
parent 58de8e175f
commit 661f0aad49
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 53 additions and 11 deletions

View file

@ -218,3 +218,17 @@ export function confirmImageExport(callback: ConfirmCallback) {
callback,
});
}
export function confirmChangePassword() {
return confirmAsync({
title: 'Are you sure?',
message:
'You will be logged out after the password change. Do you want to change your password?',
buttons: {
confirm: {
label: 'Change',
className: 'btn-primary',
},
},
});
}

View file

@ -10,6 +10,7 @@ import {
confirmDetachment,
confirmDeletionAsync,
confirmEndpointSnapshot,
confirmChangePassword,
confirmImageExport,
confirmImageForceRemoval,
confirmRedeploy,
@ -53,6 +54,7 @@ export function ModalServiceAngular() {
confirmDeletionAsync,
confirmContainerRecreation,
confirmEndpointSnapshot,
confirmChangePassword,
confirmImageExport,
confirmServiceForceUpdate,
selectRegistry,

View file

@ -16,15 +16,17 @@ angular.module('portainer.app').controller('AccountController', [
userTheme: '',
};
$scope.updatePassword = function () {
UserService.updateUserPassword($scope.userID, $scope.formValues.currentPassword, $scope.formValues.newPassword)
.then(function success() {
$scope.updatePassword = async function () {
const confirmed = await ModalService.confirmChangePassword();
if (confirmed) {
try {
await UserService.updateUserPassword($scope.userID, $scope.formValues.currentPassword, $scope.formValues.newPassword);
Notifications.success('Success', 'Password successfully updated');
$state.reload();
})
.catch(function error(err) {
$state.go('portainer.logout');
} catch (err) {
Notifications.error('Failure', err, err.msg);
});
}
}
};
$scope.removeAction = (selectedTokens) => {

View file

@ -63,11 +63,21 @@ angular.module('portainer.app').controller('UserController', [
});
};
$scope.updatePassword = function () {
$scope.updatePassword = async function () {
const isCurrentUser = Authentication.getUserDetails().ID === $scope.user.Id;
const confirmed = !isCurrentUser || (await ModalService.confirmChangePassword());
if (!confirmed) {
return;
}
UserService.updateUser($scope.user.Id, { password: $scope.formValues.newPassword })
.then(function success() {
Notifications.success('Password successfully updated');
$state.reload();
if (isCurrentUser) {
$state.go('portainer.logout');
} else {
$state.reload();
}
})
.catch(function error(err) {
Notifications.error('Failure', err, 'Unable to update user password');