coopTilleuls / CoopTilleulsForgotPasswordBundle

Provides a "forgot password" complete feature for your API through a Symfony bundle
MIT License
79 stars 25 forks source link

Feature Request: Customizable Token Generation #137

Closed aynaitlamine closed 5 months ago

aynaitlamine commented 5 months ago

Is your feature request related to a problem? Please describe. I am looking to customize the token generated by the "CoopTilleulsForgotPasswordBundle" to be a 6-digit numeric token. Currently, the bundle generates tokens that are not configurable to this specific format, and there is no clear documentation on how to override this functionality.

Describe the solution you'd like I would like the ability to customize the token generation process, specifically to generate a 6-digit numeric token. Ideally, this could be achieved by providing an interface or a configuration option that allows developers to specify their own token generation logic.

Describe alternatives you've considered I have considered overriding the default token generator service by creating a custom token generator class and manually configuring it within the Symfony service container. However, this approach is not straightforward due to the lack of a dedicated interface for token generation within the bundle. Additionally, it would be more efficient and user-friendly to have a built-in mechanism for this customization.

Additional context Here is an example of the custom token generator I created to achieve the desired token format:

  namespace App\Service;

  use CoopTilleuls\ForgotPasswordBundle\Manager\TokenGeneratorInterface;

  class CustomTokenGenerator implements TokenGeneratorInterface
  {
      public function generateToken(): string
      {
          return str_pad(random_int(0, 999999), 6, '0', STR_PAD_LEFT);
      }
  }

And the corresponding service configuration:

  # config/services.yaml

  services:
      App\Service\CustomTokenGenerator:
          public: true
          tags: ['coop_tilleuls_forgot_password.token_generator']

      CoopTilleuls\ForgotPasswordBundle\Manager\TokenGenerator:
          alias: 'App\Service\CustomTokenGenerator'

While this approach works, having an officially supported way to configure the token generation would greatly enhance the usability and flexibility of the bundle.

Thank you for considering this feature request.

aynaitlamine commented 5 months ago

Hi @vincentchalamon ,

Thank you for the quick implementation and response. I have tested the solution with the provided instructions and it works perfectly for generating a 6-digit numeric token.

I appreciate the efficient handling of this feature request. I am closing this issue as completed.