2018-05-31 14:29:00 -05:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Email.js controller
|
|
|
|
*
|
|
|
|
* @description: A set of functions called "actions" of the `email` plugin.
|
|
|
|
*/
|
|
|
|
module.exports = {
|
2019-08-21 12:10:23 +02:00
|
|
|
send: async ctx => {
|
2018-05-31 14:29:00 -05:00
|
|
|
// Retrieve provider configuration.
|
2019-08-21 12:10:23 +02:00
|
|
|
const config = await strapi
|
|
|
|
.store({
|
|
|
|
environment: strapi.config.environment,
|
|
|
|
type: 'plugin',
|
|
|
|
name: 'email',
|
|
|
|
})
|
|
|
|
.get({ key: 'provider' });
|
2018-05-31 14:29:00 -05:00
|
|
|
|
|
|
|
// Verify if the file email is enable.
|
|
|
|
if (config.enabled === false) {
|
|
|
|
strapi.log.error('Email is disabled');
|
2019-08-21 12:10:23 +02:00
|
|
|
return ctx.badRequest(null, [
|
|
|
|
{
|
2020-04-06 17:39:48 +02:00
|
|
|
messages: [{ id: 'Email.status.disabled', message: 'Emails disabled' }],
|
2019-08-21 12:10:23 +02:00
|
|
|
},
|
|
|
|
]);
|
2018-05-31 14:29:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Something is wrong
|
|
|
|
if (ctx.status === 400) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-09-18 13:20:55 +02:00
|
|
|
let options = ctx.request.body;
|
2018-05-31 14:29:00 -05:00
|
|
|
|
2018-09-18 13:20:55 +02:00
|
|
|
await strapi.plugins.email.services.email.send(options, config);
|
2018-05-31 14:29:00 -05:00
|
|
|
|
|
|
|
// Send 200 `ok`
|
|
|
|
ctx.send({});
|
|
|
|
},
|
|
|
|
|
2019-08-21 12:10:23 +02:00
|
|
|
getEnvironments: async ctx => {
|
2020-04-06 17:39:48 +02:00
|
|
|
ctx.send({ environments: [] });
|
2018-05-31 14:29:00 -05:00
|
|
|
},
|
|
|
|
|
2019-08-21 12:10:23 +02:00
|
|
|
getSettings: async ctx => {
|
|
|
|
let config = await strapi.plugins.email.services.email.getProviderConfig(
|
|
|
|
ctx.params.environment
|
|
|
|
);
|
2018-05-31 14:29:00 -05:00
|
|
|
|
|
|
|
ctx.send({
|
|
|
|
providers: strapi.plugins.email.config.providers,
|
2019-08-21 12:10:23 +02:00
|
|
|
config,
|
2018-05-31 14:29:00 -05:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2019-08-21 12:10:23 +02:00
|
|
|
updateSettings: async ctx => {
|
|
|
|
await strapi
|
|
|
|
.store({
|
|
|
|
environment: ctx.params.environment,
|
|
|
|
type: 'plugin',
|
|
|
|
name: 'email',
|
|
|
|
})
|
|
|
|
.set({ key: 'provider', value: ctx.request.body });
|
2018-05-31 14:29:00 -05:00
|
|
|
|
2019-08-21 12:10:23 +02:00
|
|
|
ctx.send({ ok: true });
|
2018-05-31 14:29:00 -05:00
|
|
|
},
|
|
|
|
};
|