2016-11-14 16:16:51 +03:00
|
|
|
/* eslint-disable camelcase */
|
2017-01-02 21:49:44 +03:00
|
|
|
import {Response} from 'ember-cli-mirage';
|
2021-07-15 17:27:29 +03:00
|
|
|
import {dasherize} from '@ember/string';
|
2017-08-22 10:53:26 +03:00
|
|
|
import {isBlank} from '@ember/utils';
|
2016-08-17 18:14:33 +03:00
|
|
|
|
|
|
|
export default function mockAuthentication(server) {
|
2018-10-05 21:46:33 +03:00
|
|
|
server.post('/session', function () {
|
2017-09-04 22:17:04 +03:00
|
|
|
// Password sign-in
|
2018-10-05 21:46:33 +03:00
|
|
|
return new Response(201);
|
2016-08-17 18:14:33 +03:00
|
|
|
});
|
|
|
|
|
2017-01-02 21:49:44 +03:00
|
|
|
server.post('/authentication/passwordreset', function (schema, request) {
|
2016-09-26 19:59:04 +03:00
|
|
|
let {passwordreset} = JSON.parse(request.requestBody);
|
2016-08-17 18:14:33 +03:00
|
|
|
let email = passwordreset[0].email;
|
|
|
|
|
|
|
|
if (email === 'unknown@example.com') {
|
2017-01-02 21:49:44 +03:00
|
|
|
return new Response(404, {}, {
|
2016-08-17 18:14:33 +03:00
|
|
|
errors: [
|
|
|
|
{
|
|
|
|
message: 'There is no user with that email address.',
|
2019-03-25 14:29:14 +03:00
|
|
|
type: 'NotFoundError'
|
2016-08-17 18:14:33 +03:00
|
|
|
}
|
|
|
|
]
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
return {
|
|
|
|
passwordreset: [
|
|
|
|
{message: 'Check your email for further instructions.'}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-01-02 21:49:44 +03:00
|
|
|
server.get('/authentication/invitation/', function (schema, request) {
|
2016-09-30 14:43:40 +03:00
|
|
|
let {email} = request.queryParams;
|
2017-01-02 21:49:44 +03:00
|
|
|
let invite = schema.invites.findBy({email});
|
2016-09-30 14:43:40 +03:00
|
|
|
let valid = !!invite;
|
|
|
|
|
|
|
|
return {
|
|
|
|
invitation: [{
|
2018-12-17 13:57:26 +03:00
|
|
|
valid
|
2016-09-30 14:43:40 +03:00
|
|
|
}]
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2016-08-17 18:14:33 +03:00
|
|
|
/* Setup ---------------------------------------------------------------- */
|
|
|
|
|
2019-01-08 17:39:37 +03:00
|
|
|
server.post('/authentication/setup', function ({roles, users}, request) {
|
|
|
|
let attrs = JSON.parse(request.requestBody).setup;
|
2017-01-02 21:49:44 +03:00
|
|
|
let role = roles.findBy({name: 'Owner'});
|
2016-08-17 18:14:33 +03:00
|
|
|
|
|
|
|
// create owner role unless already exists
|
|
|
|
if (!role) {
|
2017-01-02 21:49:44 +03:00
|
|
|
role = roles.create({name: 'Owner'});
|
2016-08-17 18:14:33 +03:00
|
|
|
}
|
|
|
|
attrs.roles = [role];
|
|
|
|
|
|
|
|
if (!isBlank(attrs.email)) {
|
2021-07-15 17:27:29 +03:00
|
|
|
attrs.slug = dasherize(attrs.email.split('@')[0]);
|
2016-08-17 18:14:33 +03:00
|
|
|
}
|
|
|
|
|
2017-01-02 21:49:44 +03:00
|
|
|
// NOTE: server does not use the user factory to fill in blank fields
|
|
|
|
return users.create(attrs);
|
2016-08-17 18:14:33 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
server.get('/authentication/setup/', function () {
|
|
|
|
return {
|
|
|
|
setup: [
|
|
|
|
{status: true}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|