use appstore.login

This commit is contained in:
Girish Ramakrishnan 2017-04-15 08:00:57 -07:00
parent d545ae7134
commit 728b12f866
3 changed files with 9 additions and 8 deletions

View File

@ -24,7 +24,7 @@ function AppStore(origin) {
} }
AppStore.prototype.getAccessToken = function (user) { AppStore.prototype.getAccessToken = function (user) {
var res = request.get(this._origin + '/api/v1/login').auth(user.email, user.password).end(); var res = request.post(this._origin + '/api/v1/login').send({ email: user.email, password: user.password, persistent: true }).end();
common.verifyResponse2xx(res, 'Could not login as user:' + user.email + ' password:' + user.password); common.verifyResponse2xx(res, 'Could not login as user:' + user.email + ' password:' + user.password);
return res.body.accessToken; return res.body.accessToken;
}; };

View File

@ -799,11 +799,8 @@ Cloudron.prototype.checkNginxRateLimit = function (owner, times, callback) {
}); });
}; };
Cloudron.prototype.setAppstoreConfig = function (email, password, callback) { Cloudron.prototype.setAppstoreConfig = function (id, token, callback) {
superagent.post(process.env.APPSTORE_API_ORIGIN + '/api/v1/login').send({ email: email, password: password, persistent: true }).end(function (error, result) { var res = request.post('https://' + that._adminFqdn + '/api/v1/settings/appstore_config').send({ userId: id, token: token }).end();
if (error || result.statusCode !== 200) return callback('Error logging into appstore:' + error.message); common.verifyResponse2xx(res, 'Could not set appstore config');
superagent.post('https://' + that._adminFqdn + '/api/v1/settings/appstore_config').send({ userId: result.userId, token: result.accessToken }).end(callback);
});
}; };

View File

@ -239,7 +239,11 @@ describe('Selfhost DigitalOcean with filesystem backend', function () {
}); });
it('can set appstore config', function (done) { it('can set appstore config', function (done) {
cloudron.setAppstoreConfig(process.env.APPSTORE_USERNAME, process.env.APPSTORE_PASSWORD, done); var token = appStore.getAccessToken(owner);
appStore.setCredentials(owner.password, token);
var profile = appStore.getProfile();
console.dir(profile);
cloudron.setAppstoreConfig(profile.id, token);
}); });
it('can update the box', function () { it('can update the box', function () {