Rename registration routes

This commit is contained in:
Girish Ramakrishnan
2019-05-05 13:00:45 -07:00
parent 22be3ad948
commit 20a2f56184
7 changed files with 111 additions and 182 deletions
+34 -1
View File
@@ -3,7 +3,10 @@
exports = module.exports = {
getApps: getApps,
getApp: getApp,
getAppVersion: getAppVersion
getAppVersion: getAppVersion,
registerCloudron: registerCloudron,
getSubscription: getSubscription
};
var appstore = require('../appstore.js'),
@@ -48,3 +51,33 @@ function getAppVersion(req, res, next) {
next(new HttpSuccess(200, manifest));
});
}
function registerCloudron(req, res, next) {
assert.strictEqual(typeof req.body, 'object');
if (typeof req.body.email !== 'string' || !req.body.email) return next(new HttpError(400, 'email must be string'));
if (typeof req.body.password !== 'string' || !req.body.password) return next(new HttpError(400, 'password must be string'));
if ('totpToken' in req.body && typeof req.body.totpToken !== 'string') return next(new HttpError(400, 'totpToken must be string'));
if (typeof req.body.signup !== 'boolean') return next(new HttpError(400, 'signup must be a boolean'));
appstore.registerCloudron(req.body, function (error) {
if (error && error.reason === AppstoreError.ALREADY_EXISTS) return next(new HttpError(409, error.message));
if (error && error.reason === AppstoreError.ACCESS_DENIED) return next(new HttpError(412, error.message));
if (error && error.reason === AppstoreError.EXTERNAL_ERROR) return next(new HttpError(424, error.message));
if (error) return next(new HttpError(500, error));
next(new HttpSuccess(201, {}));
});
}
function getSubscription(req, res, next) {
assert.strictEqual(typeof req.body, 'object');
appstore.getSubscription(function (error, result) {
if (error && error.reason === AppstoreError.INVALID_TOKEN) return next(new HttpError(402, error.message));
if (error && error.reason === AppstoreError.EXTERNAL_ERROR) return next(new HttpError(424, error.message));
if (error) return next(new HttpError(500, error));
next(new HttpSuccess(200, result)); // { email, subscription }
});
}