I am using Symfony & Api Platform with docker, and I am trying to create a reset password feature in my application that also sends a mail when its succesfull. I have installed a package called ‘CoopTilleulsForgotPasswordBundle’.
I read and followed the instructions from their github https://github.com/coopTilleuls/CoopTilleulsForgotPasswordBundle/tree/main
After setting everything up according to the documentation that is provided.
I tested it with loading ‘Fixtures’ fake data( symfony console doctrine:fixtures:load ).
And then I used Postman to try it out with fake data that had been loaded to my database thanks to fixtures.
But When I send a Post request with a body,
[email => fake_email@from_database.com]
to the route: ‘localhost::80/api/forgot-password/’
I receive: ‘{“message”:”No parameter sent.”}’
This is kind if confusing because I did not really understand what it meant.
I hoped and expected some token back as verification that it found the email.
I am not to familiar with Symfony but I really want to try it out for the project I am working on.
As I mentioned It confused me as I didnt understood what I should do to solve this.
I tried adding a parameter with a provider from ‘config/packages/coop_tilleuls_forgot_password.yaml’ when sending the email
# config/packages/coop_tilleuls_forgot_password.yaml
coop_tilleuls_forgot_password:
providers:
customer:
default: true
password_token:
class: 'AppEntityPasswordToken' # required
expires_in: '1 day'
user_field: 'user'
serialization_groups: []
user:
class: 'AppEntityUser' # required
email_field: 'email'
According to the documentation the key should be ‘FP-provider’ with value of a provider.
FP-provider => customer
But I am still getting the same message ‘No parameter found’.
I then tried create a GetTokenController
namespace AppControllerApi;
use SymfonyComponentHttpFoundationResponse;
final class GetTokenController
{
public function __invoke(): Response
{
// return new Response('', Response::HTTP_NO_CONTENT);
return new Response('Testing', Response::HTTP_OK);
}
}
At the moment I am kind of stuck trying to create api endpoint(s) that provide a reset feature in my application.
Config > Packages > Security.yaml
access_control:
- { path: '^/api/forgot-password', role: PUBLIC_ACCESS }
SRC > Entity > passwordToken.php
<?php
namespace AppEntity;
use CoopTilleulsForgotPasswordBundleEntityAbstractPasswordToken;
use DoctrineORMMapping as ORM;
#[ORMEntity]
class PasswordToken extends AbstractPasswordToken
{
#[ORMId]
#[ORMColumn(type: 'integer', nullable: false)]
#[ORMGeneratedValue(strategy: 'AUTO')]
private ?int $id = null;
#[ORMManyToOne(targetEntity: User::class)]
#[ORMJoinColumn(nullable: false, name: 'user_id')]
private $user;
public function getId(): ?int
{
return $this->id;
}
public function getUser()
{
return $this->user;
}
/**
* @param User $user
*/
public function setUser($user): void
{
$this->user = $user;
}
}
Config > Packages > coop_tilleuls_forgot_password.yaml
coop_tilleuls_forgot_password:
providers:
customer:
default: true
password_token:
class: 'AppEntityPasswordToken' # required
expires_in: '1 day'
user_field: 'user'
serialization_groups: []
user:
class: 'AppEntityUser' # required
email_field: 'email'
password_field: 'password'
Config > Routes > coop_tilleuls_forgot_password.yaml
coop_tilleuls_forgot_password:
resource: "@CoopTilleulsForgotPasswordBundle/Resources/config/routing.xml"
# prefix: /forgot_password
# resource: .
type: coop_tilleuls_forgot_password
prefix: '/api/forgot-password'