Hello,
I’m looking for the best solution to customize the user controller. I want to send a custom welcome email to all my new user.
What’s the best practice?
Using **api/user/controller/User.**js or extensions/users-permissions/controller/User.js
If a refer to this post : Register account email validation link is in user-permissions but if I see this page : Backend customization - Strapi Developer Documentation is in api/user…
Is this code still working :
//path : ./api/user/controllers/User.js.
module.exports = {
// GET /hello
signup: async ctx => {
// Store the new user in database.
const user = await User.create(ctx.query);
// Send an email to validate his subscriptions.
strapi.services.email.send('welcome@mysite.com', user.email, 'Welcome', '...');
// Send response to the server.
ctx.send({
ok: true,
});
},
};
I try it, it didn’t work.
So I try this :
//path : ./user-permissions/controller/User.js
/**
* Promise to add a/an user.
* @return {Promise}
*/
async add(values) {
if (values.password) {
values.password = await strapi.plugins[
"users-permissions"
].services.user.hashPassword(values);
}
// Send a test email
await strapi.plugins["email"].services.email.send({
to: "***@gmail.com",
from: "demo@strapi.io",
//cc: 'helenedarroze@strapi.io',
//bcc: 'ghislainearabian@strapi.io',
replyTo: "demo@strapi.io",
subject: "It's just a test",
text: "Hello world!",
html: "Hello world!",
});
return strapi.query("user", "users-permissions").create(values);
},
Again, it’s not working.