Commit 36bd6850 by Damien Moulard

WIP prevent automaticaly enabeling user at password creation #2

parent 7f12cd1c
......@@ -34,6 +34,6 @@ app.swagger_ui:
payum_all:
resource: "@PayumBundle/Resources/config/routing/all.xml"
fos_user_registration_confirm:
path: /register/confirm/{token}
controller: App\Controller\RegistrationController::confirmAction
\ No newline at end of file
fos_user_resetting_reset:
path: /resetting/reset/{token}
controller: App\Controller\ResettingController::resetAction
\ No newline at end of file
......@@ -197,6 +197,9 @@ services:
App\Controller\RegistrationController:
autowire: false
App\Controller\ResettingController:
autowire: false
app.flux.listener:
class: App\Listener\FluxListener
tags:
......
......@@ -9,7 +9,6 @@ use FOS\UserBundle\Event\GetResponseUserEvent;
use FOS\UserBundle\FOSUserEvents;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
class RegistrationController extends BaseController
{
......@@ -64,29 +63,4 @@ class RegistrationController extends BaseController
'form' => $form->createView(),
]);
}
/**
* Override confirmAction from FOSUserBundle to prevent automatically enabeling a user
* if its account was created disabled by the admin
*
* @Route("/register/confirm/{token}", name="fos_user_registration_confirm")
*/
public function confirmAction(Request $request, $token)
{
$user = $this->get('fos_user.user_manager')->findUserByConfirmationToken($token);
if (null === $user) {
throw new NotFoundHttpException(sprintf('The user with confirmation token "%s" does not exist', $token));
}
$user->setConfirmationToken(null);
$user->setLastLogin(new \DateTime());
// Don't automatically enable user if created disabled
// $user->setEnabled(true);
$this->get('fos_user.user_manager')->updateUser($user);
return new RedirectResponse($this->generateUrl('fos_user_registration_confirmed'));
}
}
<?php
namespace App\Controller;
use FOS\UserBundle\Controller\ResettingController as BaseController;
use FOS\UserBundle\Event\GetResponseUserEvent;
use FOS\UserBundle\Event\FormEvent;
use FOS\UserBundle\FOSUserEvents;
use FOS\UserBundle\Model\UserInterface;
use FOS\UserBundle\Model\UserManagerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Routing\Annotation\Route;
class ResettingController extends BaseController
{
/**
* Override action from FOSUserBundle to prevent automatically enabeling a user
* if its account was created disabled by the admin
*
* @Route("/resetting/reset/{token}", name="fos_user_resetting_reset")
*/
public function resetAction(Request $request, $token)
{
$user = $this->get('fos_user.user_manager')->findUserByConfirmationToken($token);
if (null === $user) {
throw $this->createNotFoundException(sprintf('The user with password reset token "%s" does not exist', $token));
}
$event = new GetResponseUserEvent($user, $request);
$this->get('event_dispatcher')->dispatch($event, FOSUserEvents::RESETTING_RESET_INITIALIZE);
if (null !== $event->getResponse()) {
return $event->getResponse();
}
$form = $this->$formFactory->createForm();
$form->setData($user);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$event = new FormEvent($form, $request);
$this->get('event_dispatcher')->dispatch($event, FOSUserEvents::RESETTING_RESET_SUCCESS);
// Delete tokent but don't activate account
$user->setConfirmationToken(null);
$user->setPasswordRequestedAt(null);
// Don't automatically enable user if it was created disabled
// $user->setEnabled(true);
$this->get('fos_user.user_manager')->updateUser($user);
if (null === $response = $event->getResponse()) {
$url = $this->generateUrl('fos_user_profile_show');
$response = new RedirectResponse($url);
}
$this->get('event_dispatcher')->dispatch(new \Symfony\Component\EventDispatcher\GenericEvent($user), FOSUserEvents::RESETTING_RESET_COMPLETED);
return $response;
}
return $this->render('@FOSUser/Resetting/reset.html.twig', [
'token' => $token,
'form' => $form->createView(),
]);
}
}
\ No newline at end of file
......@@ -31,18 +31,18 @@ class GeolocListener
return;
}
if (empty($entity->getLat()) && empty($entity->getLon())) {
// // GEOCODING ADDRESS :
// $httpClient = new \Http\Adapter\Guzzle6\Client();
// $provider = Nominatim::withOpenStreetMapServer($httpClient, 'Mozilla/5.0');
// $geocoder = new \Geocoder\StatefulGeocoder($provider, 'fr');
// $fullAddress = $entity->getAdresse() . ' ' . $entity->getCpostal() . ' ' . $entity->getVille();
// // Query geocoding from complete address
// $result = $geocoder->geocodeQuery(GeocodeQuery::create($fullAddress));
// if (count($result) > 0) {
// $coords = $result->first()->getCoordinates();
// $entity->setLat(floatval(str_replace(',', '.', $coords->getLatitude())));
// $entity->setLon(floatval(str_replace(',', '.', $coords->getLongitude())));
// }
// GEOCODING ADDRESS :
$httpClient = new \Http\Adapter\Guzzle6\Client();
$provider = Nominatim::withOpenStreetMapServer($httpClient, 'Mozilla/5.0');
$geocoder = new \Geocoder\StatefulGeocoder($provider, 'fr');
$fullAddress = $entity->getAdresse() . ' ' . $entity->getCpostal() . ' ' . $entity->getVille();
// Query geocoding from complete address
$result = $geocoder->geocodeQuery(GeocodeQuery::create($fullAddress));
if (count($result) > 0) {
$coords = $result->first()->getCoordinates();
$entity->setLat(floatval(str_replace(',', '.', $coords->getLatitude())));
$entity->setLon(floatval(str_replace(',', '.', $coords->getLongitude())));
}
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment