refactor init sequence

This commit is contained in:
Girish Ramakrishnan
2024-07-15 17:30:50 +02:00
parent 5b567ac941
commit 11dce549bd
6 changed files with 89 additions and 76 deletions
+3 -29
View File
@@ -1,6 +1,6 @@
'use strict';
/* global angular, window, document, localStorage */
/* global angular, window, document, localStorage, redirectIfNeeded */
/* global $ */
// create main application module
@@ -70,33 +70,6 @@ app.controller('SetupController', ['$scope', 'Client', function ($scope, Client)
}
};
function redirectIfNeeded(status) {
if ('develop' in search || localStorage.getItem('develop')) {
console.warn('Cloudron develop mode on. To disable run localStorage.removeItem(\'develop\')');
localStorage.setItem('develop', true);
return;
}
// if we are here from https://ip/activation.html ,go to https://admin/activation.html
if (status.adminFqdn && status.adminFqdn !== window.location.hostname) {
window.location.href = 'https://' + status.adminFqdn + '/activation.html';
return true;
}
// if we don't have a domain yet, first go to domain setup
if (!status.adminFqdn) {
window.location.href = '/setup.html';
return true;
}
if (status.activated) {
window.location.href = '/';
return true;
}
return false;
}
function setView(view) {
if (view === 'finished') {
$scope.view = 'finished';
@@ -109,7 +82,8 @@ app.controller('SetupController', ['$scope', 'Client', function ($scope, Client)
Client.getProvisionStatus(function (error, status) {
if (error) return Client.initError(error, init);
if (redirectIfNeeded(status)) return;
if (redirectIfNeeded(status, 'activation')) return; // redirected to some other view...
setView(search.view);
$scope.setupToken = search.setupToken;