mirror of
https://github.com/portainer/portainer.git
synced 2025-08-09 07:45:22 +02:00
feat(adminmonitor): redirect to timeout page if admin is not created in 5 mins [EE-2691] (#6688)
This PR solves the issue that the Portainer instance will be always accessible in certain cases, like `restart: always` setting with docker run, even if the administrator is not created in the first 5 minutes. The solution is that the user will be redirected to a timeout page when any actions, such as refresh the page and click button, are made after administrator initialisation window(5 minutes) timeout.
This commit is contained in:
parent
167825ff3f
commit
2059a9e064
9 changed files with 147 additions and 33 deletions
|
@ -1,7 +1,7 @@
|
|||
import axiosOrigin, { AxiosError, AxiosRequestConfig } from 'axios';
|
||||
import { loadProgressBar } from 'axios-progress-bar';
|
||||
import 'axios-progress-bar/dist/nprogress.css';
|
||||
|
||||
import 'axios-progress-bar/dist/nprogress.css';
|
||||
import PortainerError from '@/portainer/error';
|
||||
import { get as localStorageGet } from '@/portainer/hooks/useLocalStorage';
|
||||
|
||||
|
|
|
@ -60,6 +60,7 @@ angular.module('portainer.app').controller('InitAdminController', [
|
|||
}
|
||||
})
|
||||
.catch(function error(err) {
|
||||
handleError(err);
|
||||
Notifications.error('Failure', err, 'Unable to create administrator user');
|
||||
})
|
||||
.finally(function final() {
|
||||
|
@ -67,6 +68,16 @@ angular.module('portainer.app').controller('InitAdminController', [
|
|||
});
|
||||
};
|
||||
|
||||
function handleError(err) {
|
||||
if (err.status === 303) {
|
||||
const headers = err.headers();
|
||||
const REDIRECT_REASON_TIMEOUT = 'AdminInitTimeout';
|
||||
if (headers && headers['redirect-reason'] === REDIRECT_REASON_TIMEOUT) {
|
||||
window.location.href = '/timeout.html';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function createAdministratorFlow() {
|
||||
UserService.administratorExists()
|
||||
.then(function success(exists) {
|
||||
|
@ -94,6 +105,7 @@ angular.module('portainer.app').controller('InitAdminController', [
|
|||
try {
|
||||
await restoreAsyncFn();
|
||||
} catch (err) {
|
||||
handleError(err);
|
||||
Notifications.error('Failure', err, 'Unable to restore the backup');
|
||||
$scope.state.backupInProgress = false;
|
||||
|
||||
|
@ -105,6 +117,7 @@ angular.module('portainer.app').controller('InitAdminController', [
|
|||
Notifications.success('The backup has successfully been restored');
|
||||
$state.go('portainer.auth');
|
||||
} catch (err) {
|
||||
handleError(err);
|
||||
Notifications.error('Failure', err, 'Unable to check for status');
|
||||
await wait(2);
|
||||
location.reload();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue