diff --git a/src/appstore.js b/src/appstore.js index 36e037e6e..49f44835e 100644 --- a/src/appstore.js +++ b/src/appstore.js @@ -66,6 +66,7 @@ AppstoreError.PLAN_LIMIT = 'Plan limit reached'; // upstream 402 (subsciption_ex AppstoreError.LICENSE_ERROR = 'License Error'; // upstream 422 (no license, invalid license) AppstoreError.INVALID_TOKEN = 'Invalid token'; // upstream 401 (invalid token) AppstoreError.NOT_REGISTERED = 'Not registered'; // upstream 412 (no token, not set yet) +AppstoreError.ALREADY_REGISTERED = 'Already registered'; var NOOP_CALLBACK = function (error) { if (error) debug(error); }; @@ -394,13 +395,17 @@ function registerCloudron(options, callback) { registerUser(options.email, options.password, done); } - maybeSignup(function (error) { - if (error) return callback(error); + getCloudronToken(function (error) { + if (!error || error.reason !== AppstoreError.NOT_REGISTERED) return callback(new AppstoreError(AppstoreError.ALREADY_REGISTERED)); - login(options.email, options.password, options.totpToken || '', function (error, result) { + maybeSignup(function (error) { if (error) return callback(error); - subscribeCloudron(result.accessToken, callback); + login(options.email, options.password, options.totpToken || '', function (error, result) { + if (error) return callback(error); + + subscribeCloudron(result.accessToken, callback); + }); }); }); } diff --git a/src/routes/appstore.js b/src/routes/appstore.js index ef2eb2151..f7e85d604 100644 --- a/src/routes/appstore.js +++ b/src/routes/appstore.js @@ -66,6 +66,7 @@ function registerCloudron(req, res, next) { 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.ALREADY_REGISTERED) return next(new HttpError(422, error.message)); if (error && error.reason === AppstoreError.EXTERNAL_ERROR) return next(new HttpError(424, error.message)); if (error) return next(new HttpError(500, error));