mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
Migrated setup method
This commit is contained in:
parent
a5990e555b
commit
ddabd5e808
4 changed files with 47 additions and 5 deletions
|
@ -192,5 +192,10 @@ module.exports = {
|
||||||
resetPassword() {
|
resetPassword() {
|
||||||
debug('validate resetPassword');
|
debug('validate resetPassword');
|
||||||
return this.add(...arguments);
|
return this.add(...arguments);
|
||||||
|
},
|
||||||
|
|
||||||
|
setup() {
|
||||||
|
debug('validate setup');
|
||||||
|
return this.add(...arguments);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -7,6 +7,33 @@ const invitations = require('../../services/invitations');
|
||||||
module.exports = {
|
module.exports = {
|
||||||
docName: 'authentication',
|
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: {
|
generateResetToken: {
|
||||||
permissions: true,
|
permissions: true,
|
||||||
options: [
|
options: [
|
||||||
|
@ -15,7 +42,7 @@ module.exports = {
|
||||||
query(frame) {
|
query(frame) {
|
||||||
return Promise.resolve()
|
return Promise.resolve()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
return auth.setup.assertSetupCompleted(true);
|
return auth.setup.assertSetupCompleted(true)();
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
return auth.passwordreset.generateToken(frame.data.email, api.settings);
|
return auth.passwordreset.generateToken(frame.data.email, api.settings);
|
||||||
|
@ -25,6 +52,7 @@ module.exports = {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
resetPassword: {
|
resetPassword: {
|
||||||
validation: {
|
validation: {
|
||||||
docName: 'passwordreset',
|
docName: 'passwordreset',
|
||||||
|
@ -41,7 +69,7 @@ module.exports = {
|
||||||
query(frame) {
|
query(frame) {
|
||||||
return Promise.resolve()
|
return Promise.resolve()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
return auth.setup.assertSetupCompleted(true);
|
return auth.setup.assertSetupCompleted(true)();
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
return auth.passwordreset.extractTokenParts(frame);
|
return auth.passwordreset.extractTokenParts(frame);
|
||||||
|
@ -68,7 +96,7 @@ module.exports = {
|
||||||
query(frame) {
|
query(frame) {
|
||||||
return Promise.resolve()
|
return Promise.resolve()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
return auth.setup.assertSetupCompleted(true);
|
return auth.setup.assertSetupCompleted(true)();
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
return invitations.accept(frame.data);
|
return invitations.accept(frame.data);
|
||||||
|
@ -84,7 +112,7 @@ module.exports = {
|
||||||
query(frame) {
|
query(frame) {
|
||||||
return Promise.resolve()
|
return Promise.resolve()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
return auth.setup.assertSetupCompleted(true);
|
return auth.setup.assertSetupCompleted(true)();
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
const email = frame.data.email;
|
const email = frame.data.email;
|
||||||
|
|
|
@ -1,7 +1,16 @@
|
||||||
const common = require('../../../../../lib/common');
|
const common = require('../../../../../lib/common');
|
||||||
|
const mapper = require('./utils/mapper');
|
||||||
const debug = require('ghost-ignition').debug('api:v2:utils:serializers:output:authentication');
|
const debug = require('ghost-ignition').debug('api:v2:utils:serializers:output:authentication');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
setup(user, apiConfig, frame) {
|
||||||
|
frame.response = {
|
||||||
|
users: [
|
||||||
|
mapper.mapUser(user, {options: {context: {internal: true}}})
|
||||||
|
]
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
acceptInvitation(data, apiConfig, frame) {
|
acceptInvitation(data, apiConfig, frame) {
|
||||||
debug('acceptInvitation');
|
debug('acceptInvitation');
|
||||||
|
|
||||||
|
|
|
@ -189,7 +189,7 @@ module.exports = function apiRoutes() {
|
||||||
router.put('/authentication/passwordreset', shared.middlewares.brute.globalBlock, api.http(apiv2.authentication.resetPassword));
|
router.put('/authentication/passwordreset', shared.middlewares.brute.globalBlock, api.http(apiv2.authentication.resetPassword));
|
||||||
router.post('/authentication/invitation', api.http(apiv2.authentication.acceptInvitation));
|
router.post('/authentication/invitation', api.http(apiv2.authentication.acceptInvitation));
|
||||||
router.get('/authentication/invitation', api.http(apiv2.authentication.isInvitation));
|
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.put('/authentication/setup', mw.authAdminApi, api.http(api.authentication.updateSetup));
|
||||||
router.get('/authentication/setup', api.http(api.authentication.isSetup));
|
router.get('/authentication/setup', api.http(api.authentication.isSetup));
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue