PHP code example of symfonycasts / reset-password-bundle
1. Go to this page and download the library: Download symfonycasts/reset-password-bundle library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
symfonycasts / reset-password-bundle example snippets
use App\Repository\ResetPasswordRequestRepository;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$containerConfigurator->extension('symfonycasts_reset_password', [
'request_password_repository' => ResetPasswordRequestRepository::class,
'lifetime' => 3600,
'throttle_limit' => 3600,
'enable_garbage_collection' => true,
]);
};
// ProfileController
#[Route(path: '/profile/{id}', name: 'app_update_profile', methods: ['GET', 'POST'])]
public function profile(Request $request, User $user, ResetPasswordRequestRepositoryInterface $repository): Response
{
$originalEmail = $user->getEmail();
$form = $this->createFormBuilder($user)
->add('email', EmailType::class)
->add('save', SubmitType::class, ['label' => 'Save Profile'])
->getForm()
;
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
if ($originalEmail !== $user->getEmail()) {
// The user changed their email address.
// Remove any old reset requests for the user.
$repository->removeRequests($user);
}
// Persist the user object and redirect...
}
return $this->render('profile.html.twig', ['form' => $form]);
}
// src/Entity/ResetPasswordRequest.php
namespace App\Entity;
use App\Repository\ResetPasswordRequestRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use SymfonyCasts\Bundle\ResetPassword\Model\ResetPasswordRequestInterface;
use SymfonyCasts\Bundle\ResetPassword\Model\ResetPasswordRequestTrait;
#[ORM\Entity(repositoryClass: ResetPasswordRequestRepository::class)]
#[ORM\AttributeOverrides([
new ORM\AttributeOverride(
name: 'selector',
column: new ORM\Column(type: Types::STRING, length: 20, options: ['collation' => 'utf8mb4_bin'])
),
])]
class ResetPasswordRequest implements ResetPasswordRequestInterface
{
use ResetPasswordRequestTrait;
// ...
}