diff --git a/src/js/client.js b/src/js/client.js index 2b275e546..fc97f5977 100644 --- a/src/js/client.js +++ b/src/js/client.js @@ -2026,6 +2026,35 @@ angular.module('Application').service('Client', ['$http', '$interval', 'md5', 'N this.getAppstoreApps(callback); }; + Client.prototype.getSubscription = function (callback) { + get('/api/v1/subscription', null, function (error, data, status) { + if (error) return callback(error); + if (status !== 200) return callback(new ClientError(status, data)); + + // just some helper property, since angular bindings cannot dot his easily + data.emailEncoded = encodeURIComponent(data.email); + + callback(null, data); // { email, plan: { id, name }, cancel_at, status } + }); + }; + + Client.prototype.subscribeCloudron = function (email, password, totpToken, signup, callback) { + var data = { + email: email, + password: password, + signup: signup + }; + + if (totpToken) data.totpToken = totpToken; + + post('/api/v1/subscription', data, null, function (error, data, status) { + if (error) return callback(error); + if (status !== 201) return callback(new ClientError(status, data)); + + callback(null); + }); + }; + client = new Client(); return client; }]);