Add appstore accessToken to subscription setup links
This commit is contained in:
@@ -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;
|
||||
|
||||
+3
-32
@@ -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;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user