diff --git a/src/index.html b/src/index.html
index 48ce06c71..2ba820616 100644
--- a/src/index.html
+++ b/src/index.html
@@ -115,9 +115,8 @@
-
-
- Setup Subscription
- Reactivate Subscription
+
+ {{ subscription.plan.id === 'free' ? 'Setup' : 'Reactivate' }} Subscription
-
diff --git a/src/js/client.js b/src/js/client.js
index a4a8c1a84..f28be47b9 100644
--- a/src/js/client.js
+++ b/src/js/client.js
@@ -2207,6 +2207,30 @@ angular.module('Application').service('Client', ['$http', '$interval', '$timeout
});
};
+ Client.prototype.getAppstoreUserToken = function (callback) {
+ post('/api/v1/appstore/user_token', {}, null, function (error, data, status) {
+ if (error) return callback(error);
+ if (status !== 201) return callback(new ClientError(status, data));
+
+ callback(null, data.accessToken);
+ });
+ };
+
+ // This will change the location
+ Client.prototype.openSubscriptionSetup = function (subscription) {
+ var that = this;
+
+ this.getAppstoreUserToken(function (error, result) {
+ if (error) return console.error('Unable to get appstore user token.', error);
+
+ var token = result;
+ var email = subscription.emailEncoded;
+ var cloudronId = subscription.cloudronId;
+
+ window.location.href = that.getConfig().webServerOrigin + '/console.html#/userprofile?view=subscriptions&email=' + email + '&cloudronId=' + cloudronId + '&token=' + token;
+ });
+ };
+
Client.prototype.getAppstoreAppByIdAndVersion = function (appId, version, callback) {
var url = '/api/v1/appstore/apps/' + appId;
if (version && version !== 'latest') url += '/versions/' + version;
diff --git a/src/js/main.js b/src/js/main.js
index 2dd6aba28..37a06b396 100644
--- a/src/js/main.js
+++ b/src/js/main.js
@@ -14,8 +14,6 @@ angular.module('Application').controller('MainController', ['$scope', '$route',
$scope.notifications = [];
$scope.hideNavBarActions = $location.path() === '/logs';
- var waitingForPlanSelection = false;
-
$scope.isActive = function (url) {
if (!$route.current) return false;
return $route.current.$$route.originalPath.indexOf(url) === 0;
@@ -27,35 +25,8 @@ angular.module('Application').controller('MainController', ['$scope', '$route',
Client.logout();
};
- // NOTE: this function is exported and called from the settings.js
- $scope.pollSubscriptionStatus = function () {
- if (waitingForPlanSelection) return; // prevent double polling
- waitingForPlanSelection = true;
-
- function checkPlan() {
- if (!waitingForPlanSelection) return;
-
- Client.getSubscription(function (error, subscription) {
- if (error) return console.error(error);
-
- // check again to give more immediate feedback once a subscription was setup
- if (subscription.plan.id === 'free' || subscription.plan.id === 'expired') {
- $timeout(checkPlan, 5000);
- } else {
- waitingForPlanSelection = false;
- $scope.subscription = subscription;
-
- // check for updates to stay in sync
- Client.checkForUpdates(function (error) {
- if (error) return console.error(error);
-
- Client.refreshConfig();
- });
- }
- });
- }
-
- checkPlan();
+ $scope.openSubscriptionSetup = function () {
+ Client.openSubscriptionSetup($scope.subscription);
};
// NOTE: this function is exported and called from the appstore.js
@@ -64,7 +35,7 @@ angular.module('Application').controller('MainController', ['$scope', '$route',
Client.getSubscription(function (error, subscription) {
if (error && error.statusCode === 412) return; // ignore if not yet registered
- if (error) console.error(error);
+ if (error) return console.error(error);
$scope.subscription = subscription;
});
diff --git a/src/views/settings.html b/src/views/settings.html
index 4101d28cd..a14107690 100644
--- a/src/views/settings.html
+++ b/src/views/settings.html
@@ -250,9 +250,7 @@
diff --git a/src/views/settings.js b/src/views/settings.js
index 339a13497..90b4d25db 100644
--- a/src/views/settings.js
+++ b/src/views/settings.js
@@ -387,11 +387,8 @@ angular.module('Application').controller('SettingsController', ['$scope', '$loca
});
}
- $scope.pollSubscriptionStatus = function () {
- if (!$scope.$parent) return; // user changed view. otherwise we get an error that $scope.$parent is null
-
- // poll on the main controller
- $scope.$parent.pollSubscriptionStatus();
+ $scope.openSubscriptionSetup = function () {
+ Client.openSubscriptionSetup($scope.subscription);
};
$('#avatarFileInput').get(0).onchange = function (event) {