Commit 7f12cd1c by Damien Moulard

WIP prevent automaticaly enabeling user at password creation

parent dc64330f
...@@ -33,3 +33,7 @@ app.swagger_ui: ...@@ -33,3 +33,7 @@ app.swagger_ui:
payum_all: payum_all:
resource: "@PayumBundle/Resources/config/routing/all.xml" 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
...@@ -9,6 +9,7 @@ use FOS\UserBundle\Event\GetResponseUserEvent; ...@@ -9,6 +9,7 @@ use FOS\UserBundle\Event\GetResponseUserEvent;
use FOS\UserBundle\FOSUserEvents; use FOS\UserBundle\FOSUserEvents;
use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
class RegistrationController extends BaseController class RegistrationController extends BaseController
{ {
...@@ -63,4 +64,29 @@ class RegistrationController extends BaseController ...@@ -63,4 +64,29 @@ class RegistrationController extends BaseController
'form' => $form->createView(), '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'));
}
} }
...@@ -31,18 +31,18 @@ class GeolocListener ...@@ -31,18 +31,18 @@ class GeolocListener
return; return;
} }
if (empty($entity->getLat()) && empty($entity->getLon())) { if (empty($entity->getLat()) && empty($entity->getLon())) {
// GEOCODING ADDRESS : // // GEOCODING ADDRESS :
$httpClient = new \Http\Adapter\Guzzle6\Client(); // $httpClient = new \Http\Adapter\Guzzle6\Client();
$provider = Nominatim::withOpenStreetMapServer($httpClient, 'Mozilla/5.0'); // $provider = Nominatim::withOpenStreetMapServer($httpClient, 'Mozilla/5.0');
$geocoder = new \Geocoder\StatefulGeocoder($provider, 'fr'); // $geocoder = new \Geocoder\StatefulGeocoder($provider, 'fr');
$fullAddress = $entity->getAdresse() . ' ' . $entity->getCpostal() . ' ' . $entity->getVille(); // $fullAddress = $entity->getAdresse() . ' ' . $entity->getCpostal() . ' ' . $entity->getVille();
// Query geocoding from complete address // // Query geocoding from complete address
$result = $geocoder->geocodeQuery(GeocodeQuery::create($fullAddress)); // $result = $geocoder->geocodeQuery(GeocodeQuery::create($fullAddress));
if (count($result) > 0) { // if (count($result) > 0) {
$coords = $result->first()->getCoordinates(); // $coords = $result->first()->getCoordinates();
$entity->setLat(floatval(str_replace(',', '.', $coords->getLatitude()))); // $entity->setLat(floatval(str_replace(',', '.', $coords->getLatitude())));
$entity->setLon(floatval(str_replace(',', '.', $coords->getLongitude()))); // $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