2018-01-22 13:01:38 -08:00
|
|
|
'use strict';
|
|
|
|
|
|
2019-09-05 22:22:42 +02:00
|
|
|
/* global angular */
|
|
|
|
|
/* global $ */
|
|
|
|
|
|
2018-01-22 13:01:38 -08:00
|
|
|
// create main application module
|
|
|
|
|
var app = angular.module('Application', ['angular-md5', 'ui-notification', 'ui.bootstrap']);
|
|
|
|
|
|
2019-09-05 22:22:42 +02:00
|
|
|
app.controller('SetupController', ['$scope', 'Client', function ($scope, Client) {
|
2018-01-22 13:01:38 -08:00
|
|
|
// Stupid angular location provider either wants html5 location mode or not, do the query parsing on my own
|
|
|
|
|
var search = decodeURIComponent(window.location.search).slice(1).split('&').map(function (item) { return item.split('='); }).reduce(function (o, k) { o[k[0]] = k[1]; return o; }, {});
|
|
|
|
|
|
2019-09-05 22:22:42 +02:00
|
|
|
$scope.client = Client;
|
2020-06-09 15:39:27 +02:00
|
|
|
$scope.view = '';
|
|
|
|
|
$scope.busy = true;
|
2018-01-22 13:01:38 -08:00
|
|
|
$scope.account = {
|
|
|
|
|
email: '',
|
|
|
|
|
displayName: '',
|
2020-06-09 14:58:03 +02:00
|
|
|
requireEmail: true,
|
2018-01-22 13:01:38 -08:00
|
|
|
username: '',
|
|
|
|
|
password: ''
|
|
|
|
|
};
|
|
|
|
|
$scope.error = null;
|
|
|
|
|
$scope.apiServerOrigin = '';
|
2019-12-23 17:19:36 +01:00
|
|
|
$scope.webServerOrigin = '';
|
2018-01-22 13:01:38 -08:00
|
|
|
|
|
|
|
|
$scope.activateCloudron = function () {
|
|
|
|
|
$scope.busy = true;
|
|
|
|
|
$scope.error = null;
|
|
|
|
|
|
2019-08-06 10:03:12 +02:00
|
|
|
Client.createAdmin($scope.account.username, $scope.account.password, $scope.account.email, $scope.account.displayName, function (error) {
|
2018-01-22 13:01:38 -08:00
|
|
|
if (error && error.statusCode === 400) {
|
|
|
|
|
$scope.busy = false;
|
|
|
|
|
$scope.error = { username: error.message };
|
|
|
|
|
$scope.account.username = '';
|
2020-06-09 15:39:27 +02:00
|
|
|
$scope.ownerForm.username.$setPristine();
|
2018-01-22 13:01:38 -08:00
|
|
|
setTimeout(function () { $('#inputUsername').focus(); }, 200);
|
|
|
|
|
return;
|
|
|
|
|
} else if (error) {
|
|
|
|
|
$scope.busy = false;
|
|
|
|
|
console.error('Internal error', error);
|
|
|
|
|
$scope.error = { generic: error.message };
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
window.location.href = '/';
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2020-06-09 15:39:27 +02:00
|
|
|
$scope.email = {
|
|
|
|
|
error: null,
|
|
|
|
|
busy: false,
|
|
|
|
|
|
|
|
|
|
submit: function () {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$scope.invite = {
|
|
|
|
|
error: null,
|
|
|
|
|
busy: false,
|
|
|
|
|
|
|
|
|
|
submit: function () {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2020-06-09 15:03:35 +02:00
|
|
|
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 the ip first go to the real domain if already setup
|
|
|
|
|
if (status.adminFqdn && status.adminFqdn !== window.location.hostname) {
|
|
|
|
|
window.location.href = 'https://' + status.adminFqdn + '/setup.html';
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if we don't have a domain yet, first go to domain setup
|
|
|
|
|
if (!status.adminFqdn) {
|
|
|
|
|
window.location.href = '/setupdns.html';
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (status.activated) {
|
|
|
|
|
window.location.href = '/';
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-09 15:39:27 +02:00
|
|
|
function setView() {
|
|
|
|
|
if (search.view === 'owner') $scope.view = 'owner';
|
|
|
|
|
else if (search.view === 'email') $scope.view = 'email';
|
|
|
|
|
else if (search.view === 'invite') $scope.view = 'invite';
|
|
|
|
|
else $scope.view = 'owner';
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-05 22:22:42 +02:00
|
|
|
function init() {
|
|
|
|
|
Client.getStatus(function (error, status) {
|
|
|
|
|
if (error) return Client.initError(error, init);
|
2018-01-22 13:01:38 -08:00
|
|
|
|
2020-06-09 15:03:35 +02:00
|
|
|
redirectIfNeeded(status);
|
2020-06-09 15:39:27 +02:00
|
|
|
setView();
|
2018-01-22 13:01:38 -08:00
|
|
|
|
2019-09-05 22:22:42 +02:00
|
|
|
$scope.apiServerOrigin = status.apiServerOrigin;
|
2019-12-23 17:19:36 +01:00
|
|
|
$scope.webServerOrigin = status.webServerOrigin;
|
2018-01-22 13:01:38 -08:00
|
|
|
|
2020-06-09 15:39:27 +02:00
|
|
|
$scope.busy = false;
|
2018-01-22 13:01:38 -08:00
|
|
|
|
2019-09-05 22:22:42 +02:00
|
|
|
// Ensure we have a good autofocus
|
|
|
|
|
setTimeout(function () {
|
|
|
|
|
$(document).find("[autofocus]:first").focus();
|
|
|
|
|
}, 250);
|
|
|
|
|
});
|
|
|
|
|
}
|
2018-01-22 13:01:38 -08:00
|
|
|
|
2019-09-05 22:22:42 +02:00
|
|
|
init();
|
2018-01-22 13:01:38 -08:00
|
|
|
}]);
|