Commit 7f12cd1c by Damien Moulard

WIP prevent automaticaly enabeling user at password creation

parent dc64330f
......@@ -33,3 +33,7 @@ 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
......@@ -9,6 +9,7 @@ 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
{
......@@ -63,4 +64,29 @@ 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'));
}
}
......@@ -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