mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-24 19:33:02 +03:00
Migrated authentication.acceptInvitation method to v2
This commit is contained in:
parent
4da03a38b6
commit
f4b97d3bc8
@ -1,6 +1,7 @@
|
||||
const auth = require('../../services/auth');
|
||||
const api = require('./index');
|
||||
const web = require('../../web');
|
||||
const auth = require('../../services/auth');
|
||||
const invitations = require('../../services/invitations');
|
||||
|
||||
module.exports = {
|
||||
docName: 'authentication',
|
||||
@ -56,5 +57,21 @@ module.exports = {
|
||||
});
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
acceptInvitation: {
|
||||
validation: {
|
||||
docName: 'invitations'
|
||||
},
|
||||
permissions: false,
|
||||
query(frame) {
|
||||
return Promise.resolve()
|
||||
.then(() => {
|
||||
return auth.setup.assertSetupCompleted(true);
|
||||
})
|
||||
.then(() => {
|
||||
return invitations.accept(frame.data);
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -0,0 +1,14 @@
|
||||
const common = require('../../../../../lib/common');
|
||||
const debug = require('ghost-ignition').debug('api:v2:utils:serializers:output:authentication');
|
||||
|
||||
module.exports = {
|
||||
acceptInvitation(data, apiConfig, frame) {
|
||||
debug('acceptInvitation');
|
||||
|
||||
frame.response = {
|
||||
invitation: [
|
||||
{message: common.i18n.t('common.api.authentication.mail.invitationAccepted')}
|
||||
]
|
||||
};
|
||||
}
|
||||
};
|
28
core/server/api/v2/utils/validators/input/invitations.js
Normal file
28
core/server/api/v2/utils/validators/input/invitations.js
Normal file
@ -0,0 +1,28 @@
|
||||
const Promise = require('bluebird');
|
||||
const debug = require('ghost-ignition').debug('api:v2:utils:validators:input:invitation');
|
||||
const common = require('../../../../../lib/common');
|
||||
|
||||
module.exports = {
|
||||
acceptInvitation(apiConfig, frame) {
|
||||
debug('acceptInvitation');
|
||||
|
||||
const data = frame.data.invitation[0];
|
||||
|
||||
if (!data.token) {
|
||||
return Promise.reject(new common.errors.ValidationError({message: common.i18n.t('errors.api.authentication.noTokenProvided')}));
|
||||
}
|
||||
|
||||
if (!data.email) {
|
||||
return Promise.reject(new common.errors.ValidationError({message: common.i18n.t('errors.api.authentication.noEmailProvided')}));
|
||||
}
|
||||
|
||||
if (!data.password) {
|
||||
return Promise.reject(new common.errors.ValidationError({message: common.i18n.t('errors.api.authentication.noPasswordProvided')}));
|
||||
}
|
||||
|
||||
if (!data.name) {
|
||||
return Promise.reject(new common.errors.ValidationError({message: common.i18n.t('errors.api.authentication.noNameProvided')}));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -187,7 +187,7 @@ module.exports = function apiRoutes() {
|
||||
api.http(apiv2.authentication.generateResetToken)
|
||||
);
|
||||
router.put('/authentication/passwordreset', shared.middlewares.brute.globalBlock, api.http(apiv2.authentication.resetPassword));
|
||||
router.post('/authentication/invitation', api.http(api.authentication.acceptInvitation));
|
||||
router.post('/authentication/invitation', api.http(apiv2.authentication.acceptInvitation));
|
||||
router.get('/authentication/invitation', api.http(api.authentication.isInvitation));
|
||||
router.post('/authentication/setup', api.http(api.authentication.setup));
|
||||
router.put('/authentication/setup', mw.authAdminApi, api.http(api.authentication.updateSetup));
|
||||
|
@ -426,7 +426,10 @@ describe.only('Authentication API v2', function () {
|
||||
}]
|
||||
})
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(200);
|
||||
.expect(200)
|
||||
.then((res) => {
|
||||
res.body.invitation[0].message.should.equal('Invitation accepted.');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user