Verify the appstore details and register the cloudron with the store

This commit is contained in:
Johannes Zellner
2016-08-01 13:08:05 +02:00
parent f60ff45cb6
commit aedd370e76
2 changed files with 61 additions and 1 deletions
+15
View File
@@ -151,5 +151,20 @@ angular.module('Application').service('AppStore', ['$http', '$base64', 'Client',
}); });
}; };
AppStore.prototype.registerCloudron = function (token, userId, fqdn, callback) {
if (Client.getConfig().apiServerOrigin === null) return callback(new AppStoreError(420, 'Enhance Your Calm'));
var data = {
domain: fqdn
};
$http.post(Client.getConfig().apiServerOrigin + '/api/v1/users/' + userId + '/cloudrons', data, { params: { accessToken: token }}).success(function (data, status) {
if (status !== 201) return callback(new AppStoreError(status, data));
return callback(null, data.cloudron);
}).error(function (data, status) {
return callback(new AppStoreError(status, data));
});
};
return new AppStore(); return new AppStore();
}]); }]);
+46 -1
View File
@@ -1,6 +1,6 @@
'use strict'; 'use strict';
angular.module('Application').controller('MainController', ['$scope', '$route', '$interval', 'Client', function ($scope, $route, $interval, Client) { angular.module('Application').controller('MainController', ['$scope', '$route', '$interval', 'Client', 'AppStore', function ($scope, $route, $interval, Client, AppStore) {
$scope.initialized = false; $scope.initialized = false;
$scope.user = Client.getUserInfo(); $scope.user = Client.getUserInfo();
$scope.installedApps = Client.getInstalledApps(); $scope.installedApps = Client.getInstalledApps();
@@ -165,6 +165,49 @@ angular.module('Application').controller('MainController', ['$scope', '$route',
}); });
}); });
function checkAppstoreAccount() {
if (!$scope.user.admin) return;
// only check after tutorial was shown
if ($scope.user.showTutorial) return setTimeout(checkAppstoreAccount, 5000);
Client.getAppstoreConfig(function (error, appstoreConfig) {
if (error) return console.error(error);
if (!appstoreConfig.token) {
console.log('No token, prompt the user');
} else {
console.log('Got token', appstoreConfig.token);
AppStore.getProfile(appstoreConfig.token, function (error, result) {
if (error) {
console.error('failed to get profile', error);
return;
}
console.log('Got profile', result);
if (!appstoreConfig.cloudronId) {
console.log('No cloudronId, try to register');
AppStore.registerCloudron(appstoreConfig.token, result.id, Client.getConfig().fqdn, function (error, result) {
if (error) return console.error(error);
console.log('Successfully registered cloudron', result);
// TODO set the cloudron id now with the appstore details
});
} else {
AppStore.getCloudron(appstoreConfig.token, result.id, appstoreConfig.cloudronId, function (error, result) {
if (error) return console.error(error);
console.log('Successfully got cloudron', result);
});
}
});
}
});
}
// wait till the view has loaded until showing a modal dialog // wait till the view has loaded until showing a modal dialog
Client.onConfig(function (config) { Client.onConfig(function (config) {
// if (!config.billing) { // if (!config.billing) {
@@ -191,6 +234,8 @@ angular.module('Application').controller('MainController', ['$scope', '$route',
if (config.cloudronName) { if (config.cloudronName) {
document.title = config.cloudronName; document.title = config.cloudronName;
} }
checkAppstoreAccount();
}); });