Search code examples
node.jsregistrationstrapi

Strapi: how to set disabled as default a new user registered, then enable by an administrator


how can I set "disabled user" as default configuration to any new user which register on, then send to any administrator an email saying "new user!!" and the administrator could anable the new user and send to him an email to let him know was approved


Solution

  • You will have to customize the register function.

    To do so, you will have to use the extensions folder.

    See the documentation here: https://strapi.io/documentation/3.0.0-beta.x/concepts/concepts.html#extensions

    Here is the register function you will have to update: https://github.com/strapi/strapi/blob/master/packages/strapi-plugin-users-permissions/controllers/Auth.js#L358

    You will have to create ./extensions/users-permissions/controllers/Auth.js file that contains a module.exports with only the register function inside. Copy the plugin's one and paste it in the extension file we just created.

    Then in you extend register function, you will have to update the params object and set the blocked key to true. Just after this line https://github.com/strapi/strapi/blob/master/packages/strapi-plugin-users-permissions/controllers/Auth.js#L378.

    Then if you want to send an email, you can use the email plugin that provides you a way to send emails.

    Here is the example of how we send confirmation email: https://github.com/strapi/strapi/blob/master/packages/strapi-plugin-users-permissions/controllers/Auth.js#L508

    Copy this line and update values to send an email to yourself with the content you want.