Use new registration API
This commit is contained in:
@@ -1,93 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
/* global angular:false */
|
||||
|
||||
angular.module('Application').service('AppStore', ['$http', '$base64', 'Client', function ($http, $base64, Client) {
|
||||
|
||||
function AppStoreError(statusCode, message) {
|
||||
Error.call(this);
|
||||
this.name = this.constructor.name;
|
||||
this.statusCode = statusCode;
|
||||
if (typeof message == 'string') {
|
||||
this.message = message;
|
||||
} else {
|
||||
this.message = JSON.stringify(message);
|
||||
}
|
||||
}
|
||||
|
||||
function AppStore() {
|
||||
}
|
||||
|
||||
AppStore.prototype.register = function (email, password, callback) {
|
||||
if (Client.getConfig().apiServerOrigin === null) return callback(new AppStoreError(420, 'Enhance Your Calm'));
|
||||
|
||||
var data = {
|
||||
email: email,
|
||||
password: password
|
||||
};
|
||||
|
||||
$http.post(Client.getConfig().apiServerOrigin + '/api/v1/users', data).success(function (data, status) {
|
||||
if (status !== 201) return callback(new AppStoreError(status, data));
|
||||
return callback(null, data);
|
||||
}).error(function (data, status) {
|
||||
return callback(new AppStoreError(status, data));
|
||||
});
|
||||
};
|
||||
|
||||
AppStore.prototype.login = function (email, password, totpToken, callback) {
|
||||
if (Client.getConfig().apiServerOrigin === null) return callback(new AppStoreError(420, 'Enhance Your Calm'));
|
||||
|
||||
var data = {
|
||||
email: email,
|
||||
password: password,
|
||||
persistent: true,
|
||||
totpToken: totpToken
|
||||
};
|
||||
|
||||
$http.post(Client.getConfig().apiServerOrigin + '/api/v1/login', data).success(function (data, status) {
|
||||
if (status !== 200) return callback(new AppStoreError(status, data));
|
||||
return callback(null, data);
|
||||
}).error(function (data, status) {
|
||||
return callback(new AppStoreError(status, data));
|
||||
});
|
||||
};
|
||||
|
||||
AppStore.prototype.logout = function (email, password, callback) {
|
||||
if (Client.getConfig().apiServerOrigin === null) return callback(new AppStoreError(420, 'Enhance Your Calm'));
|
||||
|
||||
$http.post(Client.getConfig().apiServerOrigin + '/api/v1/logout').success(function (data, status) {
|
||||
if (status !== 200) return callback(new AppStoreError(status, data));
|
||||
return callback(null);
|
||||
}).error(function (data, status) {
|
||||
return callback(new AppStoreError(status, data));
|
||||
});
|
||||
};
|
||||
|
||||
AppStore.prototype.getProfile = function (token, callback) {
|
||||
if (Client.getConfig().apiServerOrigin === null) return callback(new AppStoreError(420, 'Enhance Your Calm'));
|
||||
|
||||
$http.get(Client.getConfig().apiServerOrigin + '/api/v1/profile', { params: { accessToken: token }}).success(function (data, status) {
|
||||
if (status !== 200) return callback(new AppStoreError(status, data));
|
||||
|
||||
// just some helper property, since angular bindings cannot dot his easily
|
||||
data.profile.emailEncoded = encodeURIComponent(data.profile.email);
|
||||
|
||||
return callback(null, data.profile);
|
||||
}).error(function (data, status) {
|
||||
return callback(new AppStoreError(status, data));
|
||||
});
|
||||
};
|
||||
|
||||
AppStore.prototype.getSubscription = function (appstoreConfig, callback) {
|
||||
if (Client.getConfig().apiServerOrigin === null) return callback(new AppStoreError(420, 'Enhance Your Calm'));
|
||||
|
||||
$http.get(Client.getConfig().apiServerOrigin + '/api/v1/users/' + appstoreConfig.userId + '/cloudrons/' + appstoreConfig.cloudronId + '/subscription', { params: { accessToken: appstoreConfig.token }}).success(function (data, status) {
|
||||
if (status !== 200) return callback(new AppStoreError(status, data));
|
||||
return callback(null, data.subscription);
|
||||
}).error(function (data, status) {
|
||||
return callback(new AppStoreError(status, data));
|
||||
});
|
||||
};
|
||||
|
||||
return new AppStore();
|
||||
}]);
|
||||
@@ -611,24 +611,6 @@ angular.module('Application').service('Client', ['$http', '$interval', 'md5', 'N
|
||||
});
|
||||
};
|
||||
|
||||
Client.prototype.setAppstoreConfig = function (appstoreConfig, callback) {
|
||||
post('/api/v1/settings/appstore_config', appstoreConfig, null, function (error, data, status) {
|
||||
if (error) return callback(error);
|
||||
if (status !== 202) return callback(new ClientError(status, data));
|
||||
|
||||
callback(null);
|
||||
});
|
||||
};
|
||||
|
||||
Client.prototype.getAppstoreConfig = function (callback) {
|
||||
get('/api/v1/settings/appstore_config', null, function (error, data, status) {
|
||||
if (error) return callback(error);
|
||||
if (status !== 200) return callback(new ClientError(status, data));
|
||||
|
||||
callback(null, data);
|
||||
});
|
||||
};
|
||||
|
||||
Client.prototype.getRemoteSupport = function (callback) {
|
||||
get('/api/v1/support/remote_support', null, function (error, data, status) {
|
||||
if (error) return callback(error);
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
/* global angular:false */
|
||||
/* global $:false */
|
||||
|
||||
angular.module('Application').controller('MainController', ['$scope', '$route', '$timeout', '$location', 'Client', 'AppStore', function ($scope, $route, $timeout, $location, Client, AppStore) {
|
||||
angular.module('Application').controller('MainController', ['$scope', '$route', '$timeout', '$location', 'Client', function ($scope, $route, $timeout, $location, Client) {
|
||||
$scope.initialized = false; // used to animate the UI
|
||||
$scope.user = Client.getUserInfo();
|
||||
$scope.installedApps = Client.getInstalledApps();
|
||||
|
||||
Reference in New Issue
Block a user