Ghost/ghost/admin/mirage/config/authentication.js
Fabien O'Carroll 3e5a62309f Use Admin API v2 with session auth (#1046)
refs #9865
- removed all `oauth2` and token-based ESA auth
- added new `cookie` authenticator which handles session creation
- updated the session store to extend from the `ephemeral` in-memory store and to restore by fetching the currently logged in user and using the success/failure state to indicate authentication state
  - ESA automatically calls this `.restore()` method on app boot
  - the `session` service caches the current-user query so there's no unnecessary requests being made for the "logged in" state
- removed the now-unnecessary token refresh and logout routines from the `application` route
- removed the now-unnecessary token refresh routines from the `ajax` service
- removed `access_token` query param from iframe file downloaders
- changed Ember Data adapters and `ghost-paths` to use the `/ghost/api/v2/admin/` namespace
2018-10-05 19:46:33 +01:00

77 lines
2.2 KiB
JavaScript

/* eslint-disable camelcase */
import {Response} from 'ember-cli-mirage';
import {isBlank} from '@ember/utils';
export default function mockAuthentication(server) {
server.post('/session', function () {
// Password sign-in
return new Response(201);
});
server.post('/authentication/passwordreset', function (schema, request) {
let {passwordreset} = JSON.parse(request.requestBody);
// eslint-disable-next-line ember-suave/prefer-destructuring
let email = passwordreset[0].email;
if (email === 'unknown@example.com') {
return new Response(404, {}, {
errors: [
{
message: 'There is no user with that email address.',
errorType: 'NotFoundError'
}
]
});
} else {
return {
passwordreset: [
{message: 'Check your email for further instructions.'}
]
};
}
});
server.get('/authentication/invitation/', function (schema, request) {
let {email} = request.queryParams;
let invite = schema.invites.findBy({email});
let user = schema.users.find(invite.createdBy);
let valid = !!invite;
let invitedBy = user && user.name;
return {
invitation: [{
valid,
invitedBy
}]
};
});
/* Setup ---------------------------------------------------------------- */
server.post('/authentication/setup', function ({roles, users}) {
let attrs = this.normalizedRequestAttrs();
let role = roles.findBy({name: 'Owner'});
// create owner role unless already exists
if (!role) {
role = roles.create({name: 'Owner'});
}
attrs.roles = [role];
if (!isBlank(attrs.email)) {
attrs.slug = attrs.email.split('@')[0].dasherize();
}
// NOTE: server does not use the user factory to fill in blank fields
return users.create(attrs);
});
server.get('/authentication/setup/', function () {
return {
setup: [
{status: true}
]
};
});
}