0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00

Migrated setup method

This commit is contained in:
Nazar Gargol 2019-07-24 20:21:42 +02:00
parent a5990e555b
commit ddabd5e808
4 changed files with 47 additions and 5 deletions

View file

@ -192,5 +192,10 @@ module.exports = {
resetPassword() {
debug('validate resetPassword');
return this.add(...arguments);
},
setup() {
debug('validate setup');
return this.add(...arguments);
}
};

View file

@ -7,6 +7,33 @@ const invitations = require('../../services/invitations');
module.exports = {
docName: 'authentication',
setup: {
permissions: false,
validation: {
docName: 'setup'
},
query(frame) {
return Promise.resolve()
.then(() => {
return auth.setup.assertSetupCompleted(false)();
})
.then(() => {
const setupDetails = {
name: frame.data.setup[0].name,
email: frame.data.setup[0].email,
password: frame.data.setup[0].password,
blogTitle: frame.data.setup[0].blogTitle,
status: 'active'
};
return auth.setup.setupUser(setupDetails);
})
.then((data) => {
return auth.setup.doSettings(data, api.settings);
});
}
},
generateResetToken: {
permissions: true,
options: [
@ -15,7 +42,7 @@ module.exports = {
query(frame) {
return Promise.resolve()
.then(() => {
return auth.setup.assertSetupCompleted(true);
return auth.setup.assertSetupCompleted(true)();
})
.then(() => {
return auth.passwordreset.generateToken(frame.data.email, api.settings);
@ -25,6 +52,7 @@ module.exports = {
});
}
},
resetPassword: {
validation: {
docName: 'passwordreset',
@ -41,7 +69,7 @@ module.exports = {
query(frame) {
return Promise.resolve()
.then(() => {
return auth.setup.assertSetupCompleted(true);
return auth.setup.assertSetupCompleted(true)();
})
.then(() => {
return auth.passwordreset.extractTokenParts(frame);
@ -68,7 +96,7 @@ module.exports = {
query(frame) {
return Promise.resolve()
.then(() => {
return auth.setup.assertSetupCompleted(true);
return auth.setup.assertSetupCompleted(true)();
})
.then(() => {
return invitations.accept(frame.data);
@ -84,7 +112,7 @@ module.exports = {
query(frame) {
return Promise.resolve()
.then(() => {
return auth.setup.assertSetupCompleted(true);
return auth.setup.assertSetupCompleted(true)();
})
.then(() => {
const email = frame.data.email;

View file

@ -1,7 +1,16 @@
const common = require('../../../../../lib/common');
const mapper = require('./utils/mapper');
const debug = require('ghost-ignition').debug('api:v2:utils:serializers:output:authentication');
module.exports = {
setup(user, apiConfig, frame) {
frame.response = {
users: [
mapper.mapUser(user, {options: {context: {internal: true}}})
]
};
},
acceptInvitation(data, apiConfig, frame) {
debug('acceptInvitation');

View file

@ -189,7 +189,7 @@ module.exports = function apiRoutes() {
router.put('/authentication/passwordreset', shared.middlewares.brute.globalBlock, api.http(apiv2.authentication.resetPassword));
router.post('/authentication/invitation', api.http(apiv2.authentication.acceptInvitation));
router.get('/authentication/invitation', api.http(apiv2.authentication.isInvitation));
router.post('/authentication/setup', api.http(api.authentication.setup));
router.post('/authentication/setup', api.http(apiv2.authentication.setup));
router.put('/authentication/setup', mw.authAdminApi, api.http(api.authentication.updateSetup));
router.get('/authentication/setup', api.http(api.authentication.isSetup));