diff --git a/src/js/client.js b/src/js/client.js index 17713d14a..46adbe614 100644 --- a/src/js/client.js +++ b/src/js/client.js @@ -1464,24 +1464,17 @@ angular.module('Application').service('Client', ['$http', '$interval', '$timeout }); }; - Client.prototype.createAdmin = function (username, password, email, displayName, callback) { + Client.prototype.createAdmin = function (data, callback) { var that = this; - var data = { - username: username, - password: password, - email: email, - displayName: displayName - }; - - post('/api/v1/cloudron/activate', data, null, function (error, data, status) { + post('/api/v1/cloudron/activate', data, null, function (error, result, status) { if (error) return callback(error); - if (status !== 201) return callback(new ClientError(status, data)); + if (status !== 201) return callback(new ClientError(status, result)); - that.setToken(data.token); - that.setUserInfo({ username: username, email: email, admin: true, twoFactorAuthenticationEnabled: false, source: '', avatarUrl: null }); + that.setToken(result.token); + that.setUserInfo({ username: data.username, email: data.email, admin: true, twoFactorAuthenticationEnabled: false, source: '', avatarUrl: null }); - callback(null, data.activated); + callback(null, result.activated); }); }; diff --git a/src/js/main.js b/src/js/main.js index 4bef2cefb..b94133ca3 100644 --- a/src/js/main.js +++ b/src/js/main.js @@ -91,9 +91,9 @@ angular.module('Application').controller('MainController', ['$scope', '$route', if (!status.activated) { console.log('Not activated yet, redirecting', status); if (status.restore.active || status.restore.errorMessage) { // show the error message in restore page - window.location.href = '/restore.html'; + window.location.href = '/restore.html' + window.location.search; } else { - window.location.href = status.adminFqdn ? '/setup.html' : '/setupdns.html'; + window.location.href = (status.adminFqdn ? '/setup.html' : '/setupdns.html') + window.location.search; } return; } @@ -101,7 +101,7 @@ angular.module('Application').controller('MainController', ['$scope', '$route', // support local development with localhost check if (window.location.hostname !== status.adminFqdn && window.location.hostname !== 'localhost') { // user is accessing by IP or by the old admin location (pre-migration) - window.location.href = '/setupdns.html'; + window.location.href = '/setupdns.html' + window.location.search; return; } diff --git a/src/js/restore.js b/src/js/restore.js index 44bed7279..9cfad2537 100644 --- a/src/js/restore.js +++ b/src/js/restore.js @@ -38,6 +38,7 @@ app.controller('RestoreController', ['$scope', 'Client', function ($scope, Clien $scope.advancedVisible = false; $scope.password = ''; $scope.encrypted = false; // only used if a backup config contains that flag + $scope.setupToken = ''; $scope.sysinfo = { provider: 'generic', @@ -159,7 +160,8 @@ app.controller('RestoreController', ['$scope', 'Client', function ($scope, Clien var backupConfig = { provider: $scope.provider, - format: $scope.format + format: $scope.format, + setupToken: $scope.setupToken }; if ($scope.password) backupConfig.password = $scope.password; @@ -374,6 +376,7 @@ app.controller('RestoreController', ['$scope', 'Client', function ($scope, Clien $scope.status = status; $scope.instanceId = search.instanceId; + $scope.setupToken = search.setupToken; $scope.initialized = true; }); } diff --git a/src/js/setup.js b/src/js/setup.js index ef52db471..3ceaa335f 100644 --- a/src/js/setup.js +++ b/src/js/setup.js @@ -15,6 +15,7 @@ app.controller('SetupController', ['$scope', 'Client', function ($scope, Client) $scope.initialized = false; $scope.apiServerOrigin = ''; $scope.webServerOrigin = ''; + $scope.setupToken = ''; $scope.owner = { error: null, @@ -29,7 +30,15 @@ app.controller('SetupController', ['$scope', 'Client', function ($scope, Client) $scope.owner.busy = true; $scope.owner.error = null; - Client.createAdmin($scope.owner.username, $scope.owner.password, $scope.owner.email, $scope.owner.displayName, function (error) { + var data = { + username: $scope.owner.username, + password: $scope.owner.password, + email: $scope.owner.email, + displayName: $scope.owner.displayName, + setupToken: $scope.setupToken + }; + + Client.createAdmin(data, function (error) { if (error && error.statusCode === 400) { $scope.owner.busy = false; $scope.owner.error = { username: error.message }; @@ -92,6 +101,7 @@ app.controller('SetupController', ['$scope', 'Client', function ($scope, Client) $scope.apiServerOrigin = status.apiServerOrigin; $scope.webServerOrigin = status.webServerOrigin; + $scope.setupToken = search.setupToken; $scope.initialized = true; // Ensure we have a good autofocus diff --git a/src/js/setupdns.js b/src/js/setupdns.js index 5ae162d41..c9d7079b9 100644 --- a/src/js/setupdns.js +++ b/src/js/setupdns.js @@ -24,6 +24,8 @@ app.controller('SetupDNSController', ['$scope', '$http', '$timeout', 'Client', f $scope.advancedVisible = false; $scope.webServerOrigin = ''; $scope.clipboardDone = false; + $scope.search = window.location.search; + $scope.setupToken = ''; $scope.tlsProvider = [ { name: 'Let\'s Encrypt Prod', value: 'letsencrypt-prod' }, @@ -220,14 +222,19 @@ app.controller('SetupDNSController', ['$scope', '$http', '$timeout', 'Client', f tlsConfig: tlsConfig }, sysinfoConfig: sysinfoConfig, - providerToken: $scope.instanceId + providerToken: $scope.instanceId, + setupToken: $scope.setupToken }; Client.setup(data, function (error) { if (error) { $scope.dnsCredentials.busy = false; if (error.statusCode === 422) { - $scope.error.ami = error.message; + if (provider === 'ami') { + $scope.error.ami = error.message; + } else { + $scope.error.setup = error.message; + } } else { $scope.error.dnsCredentials = error.message; } @@ -248,7 +255,7 @@ app.controller('SetupDNSController', ['$scope', '$http', '$timeout', 'Client', f $scope.state = 'initialized'; $scope.dnsCredentials.busy = false; } else { // proceed to activation - window.location.href = 'https://' + status.adminFqdn + '/setup.html'; + window.location.href = 'https://' + status.adminFqdn + '/setup.html' + (window.location.search); } return; } @@ -283,6 +290,7 @@ app.controller('SetupDNSController', ['$scope', '$http', '$timeout', 'Client', f } $scope.instanceId = search.instanceId; + $scope.setupToken = search.setupToken; $scope.provider = status.provider; $scope.webServerOrigin = status.webServerOrigin; $scope.state = 'initialized'; diff --git a/src/setup.html b/src/setup.html index 048306fa9..48a36a594 100644 --- a/src/setup.html +++ b/src/setup.html @@ -61,6 +61,7 @@

Welcome to Cloudron

Setup Admin Account

+

{{ owner.error.generic }}


diff --git a/src/setupdns.html b/src/setupdns.html index 456bbb49c..7e7f3c34c 100644 --- a/src/setupdns.html +++ b/src/setupdns.html @@ -267,7 +267,7 @@
-
Looking to restore?
+
Looking to restore?