Move AMI instanceId verification to DNS setup

This commit is contained in:
Johannes Zellner
2017-04-03 21:27:40 +02:00
parent 4f9273819a
commit b9711d7b47
6 changed files with 36 additions and 14 deletions

View File

@@ -20,12 +20,11 @@ app.controller('SetupController', ['$scope', '$http', 'Client', function ($scope
$scope.provider = '';
$scope.apiServerOrigin = '';
$scope.setupToken = '';
$scope.instanceId = '';
$scope.activateCloudron = function () {
$scope.busy = true;
Client.createAdmin($scope.account.username, $scope.account.password, $scope.account.email, $scope.account.displayName, $scope.setupToken || $scope.instanceId, function (error) {
Client.createAdmin($scope.account.username, $scope.account.password, $scope.account.email, $scope.account.displayName, $scope.setupToken, function (error) {
if (error && error.statusCode === 403) {
$scope.busy = false;
$scope.error = $scope.provider === 'ami' ? 'Wrong instance id' : 'Wrong setup token';
@@ -82,7 +81,6 @@ app.controller('SetupController', ['$scope', '$http', 'Client', function ($scope
$scope.account.displayName = search.displayName || $scope.account.displayName;
$scope.account.requireEmail = !search.email;
$scope.provider = status.provider;
$scope.instanceId = search.instanceId;
$scope.apiServerOrigin = status.apiServerOrigin;
$scope.initialized = true;

View File

@@ -4,11 +4,14 @@
var app = angular.module('Application', ['angular-md5', 'ui-notification', 'ngTld']);
app.controller('SetupDNSController', ['$scope', '$http', 'Client', 'ngTld', function ($scope, $http, Client, ngTld) {
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; }, {});
$scope.initialized = false;
$scope.busy = false;
$scope.error = null;
$scope.provider = '';
$scope.showDNSSetup = false;
$scope.instanceId = '';
// keep in sync with certs.js
$scope.dnsProvider = [
@@ -36,7 +39,8 @@ app.controller('SetupDNSController', ['$scope', '$http', 'Client', 'ngTld', func
provider: $scope.dnsCredentials.provider,
accessKeyId: $scope.dnsCredentials.accessKeyId,
secretAccessKey: $scope.dnsCredentials.secretAccessKey,
token: $scope.dnsCredentials.digitalOceanToken
token: $scope.dnsCredentials.digitalOceanToken,
providerToken: $scope.instanceId
};
// special case the wildcard provider
@@ -46,7 +50,11 @@ app.controller('SetupDNSController', ['$scope', '$http', 'Client', 'ngTld', func
}
Client.setupDnsConfig(data, function (error) {
if (error) {
if (error && error.statusCode === 403) {
$scope.dnsCredentials.busy = false;
$scope.error = 'Wrong instance id provided.';
return;
} else if (error) {
$scope.dnsCredentials.busy = false;
$scope.dnsCredentials.error = error.message;
return;
@@ -84,6 +92,7 @@ app.controller('SetupDNSController', ['$scope', '$http', 'Client', 'ngTld', func
$scope.dnsCredentials.provider = 'wildcard';
}
$scope.instanceId = search.instanceId;
$scope.provider = status.provider;
$scope.initialized = true;
});

View File

@@ -81,11 +81,6 @@
<small ng-show="setupForm.password.$dirty && setupForm.password.$invalid">Password must be 8-30 character with at least one uppercase, one numeric and one special character</small>
</div>
</div>
<div class="form-group" ng-class="{ 'has-error': setupForm.instanceId.$dirty && (setupForm.instanceId.$invalid || error) }" ng-show="provider === 'ami'">
<p>Provide the EC2 instance id to verify you are the owner</p>
<input type="text" class="form-control" ng-model="instanceId" id="inputInstanceId" name="instanceId" placeholder="AWS EC2 instance id" ng-maxlength="20" ng-minlength="10" ng-required="provider === 'ami'" autocomplete="off">
<p ng-show="error" class="has-error">{{ error }}</p>
</div>
</div>
</div>
<div class="row">

View File

@@ -102,6 +102,17 @@
</p>
</div>
</div>
<div class="row" ng-show="provider === 'ami'">
<div class="col-md-10 col-md-offset-1 text-center">
<br/>
<h3>Owner verification</h3>
<p>Provide the EC2 instance id to verify you have access to this server.</p>
<div class="form-group" ng-class="{ 'has-error': dnsCredentialsForm.instanceId.$dirty && (dnsCredentialsForm.instanceId.$invalid || error) }">
<input type="text" class="form-control" ng-model="instanceId" id="inputInstanceId" name="instanceId" placeholder="AWS EC2 instance id" ng-maxlength="20" ng-minlength="10" ng-required="provider === 'ami'" autocomplete="off">
</div>
<p>&nbsp;<span ng-show="error" class="text-danger">{{ error }}</span></p>
</div>
</div>
<div class="row">
<div class="col-md-12 text-center">
<button type="submit" class="btn btn-primary" ng-disabled="dnsCredentialsForm.$invalid"/><i class="fa fa-circle-o-notch fa-spin" ng-show="dnsCredentials.busy"></i> Next</button>