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) {
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);
return res.body.accessToken;
};

View File

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

View File

@ -239,7 +239,11 @@ describe('Selfhost DigitalOcean with filesystem backend', function () {
});
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 () {