1. Go to this page and download the library: Download roadiz/user-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/ */
declare(strict_types=1);
namespace App\Controller;
use RZ\Roadiz\CoreBundle\Repository\UserRepository;
use RZ\Roadiz\CoreBundle\Security\LoginLink\LoginLinkSenderInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Http\LoginLink\LoginLinkHandlerInterface;
final readonly class SecurityController
{
public function __construct(
private LoginLinkSenderInterface $loginLinkSender,
) {
}
#[Route('/api/users/login_link', name: 'public_user_login_link_request', methods: ['POST'])]
public function requestLoginLink(
LoginLinkHandlerInterface $loginLinkHandler,
UserRepository $userRepository,
Request $request
): Response {
// load the user in some way (e.g. using the form input)
$email = $request->getPayload()->get('email');
$user = $userRepository->findOneBy(['email' => $email]);
if (null === $user) {
// Do not leak if a user exists or not
return new JsonResponse(null, Response::HTTP_NO_CONTENT);
}
// create a login link for $user this returns an instance
// of LoginLinkDetails
$loginLinkDetails = $loginLinkHandler->createLoginLink($user, $request);
$this->loginLinkSender->sendLoginLink($user, $loginLinkDetails);
return new JsonResponse(null, Response::HTTP_NO_CONTENT);
}
}