6

I want to send emails to signup user and activate it until cerntain actions are done.

I don't know whether this feature is available already, or I need to implement the logic myself. With the default authentication and user models, it looks like quite complicated to modify the logics. how difficult is it to implement such features?

chuan
  • 194
  • 2
  • 14
  • Strapi version 4, I answered this question on this post: [enter link description here](https://stackoverflow.com/questions/70732379/strapi-new-user-registration-keeps-getting-email-is-already-taken-error-no-em/70732504#70732504) – Tellisense Jan 16 '22 at 18:33
  • I answered this question on this post [enter link description here](https://stackoverflow.com/questions/70732379/strapi-new-user-registration-keeps-getting-email-is-already-taken-error-no-em/70732504#70732504) – Tellisense Jan 16 '22 at 18:34
  • Please refer to my answer if the above is not clear. https://stackoverflow.com/questions/70788997/strapi-email-confirmation-is-not-working-properly-i-click-the-link-and-nothing – Tellisense Jan 20 '22 at 16:46

3 Answers3

10

As you said, there is already a default logic for the Users in Strapi. However, the files can be edited and you can custom the behavior.

In your case, you need to go to ./api/user/controllers/User.js file in the create method and add your custom logic for sending an email where the User has been created (see https://github.com/strapi/strapi-generate-users/blob/master/files/api/user/controllers/User.js#L52).

I hope this answer will help you!

PS: I'm one of the authors of Strapi.

  • how would you disable and activate the user? using a new table to keep track or is it possible to modify the user model? – chuan Jan 19 '17 at 16:27
  • You can modify the user model by only adding new attributes. Please avoid to remove one of them, it could cause some issues, I don't recommend to do that. – Aurélien Georget Jan 20 '17 at 09:51
0

You can add a user model file in extensions/user-permissions/models/user.js with an afterCreate hook:

lifecycles: {
    async afterCreate(data) {
        // SEND EMAIL HERE
    },
}
t j
  • 7,026
  • 12
  • 46
  • 66
  • Doesn't work... tried that but nothing happens. I added this: module.exports = {lifecycles: { async afterCreate(data) { strapi.plugins['users-permissions'].services.user.sendConfirmationEmail(data) }, } } – ConfusedDev Dec 20 '21 at 14:10
0

It seems there is an option for this feature. enter image description here

atazmin
  • 4,757
  • 1
  • 32
  • 23
  • Here is a more detail version of the above answer: https://stackoverflow.com/questions/70732379/strapi-new-user-registration-keeps-getting-email-is-already-taken-error-no-em/70732504#70732504 – Tellisense Jan 16 '22 at 18:35