The standard component of Security Symfony 4. The username field in the authorization form is composite. The first field is the country code, the second phone. It is necessary before symfony starts the authorization process, in essence, the username should be folded into one line and then you should search for the user and authorize How to do it?
1 answer
namespace App\EventListener; use Symfony\Component\HttpKernel\Event\GetResponseEvent; class LoginListener { public function onKernelRequest(GetResponseEvent $event){ $request = $event->getRequest(); if ($request->getMethod() == 'POST' && !empty($request->request->get('phoneCode')) && $request->request->get('phoneNumber')) { $phoneCode = $request->request->get('phoneCode'); $phoneNumber = $request->request->get('phoneNumber'); $username = $phoneCode . $phoneNumber; $request->request->set('_username', $username); } } } this is the //src/EventListener/LoginListener.php file
and also need to register in # config / services.yaml
App\EventListener\LoginListener: tags: - { name: kernel.event_listener, event: kernel.request, method: onKernelRequest, priority: 255 } |