]> Raphaƫl G. Git Repositories - userbundle/blobdiff - Controller/DefaultController.php
Cleanup
[userbundle] / Controller / DefaultController.php
index 5c3c51c3e6ff3226b2d2776f868d3d3c6298998e..3a6571267e4400c807c471715f1c92c3290c6de4 100644 (file)
@@ -322,22 +322,6 @@ class DefaultController extends AbstractController {
                        throw $this->createAccessDeniedException($this->translator->trans('Unable to access user: %mail%', ['%mail%' => $smail]));
                }
 
-               //Create the RegisterType form and give the proper parameters
-               $editForm = $this->createForm($this->config['register']['view']['form'], $user, [
-                       //Set action to register route name and context
-                       'action' => $this->generateUrl($this->config['route']['edit']['name'], ['mail' => $smail, 'hash' => $slugger->hash($smail)]+$this->config['route']['edit']['context']),
-                       //Set civility class
-                       'civility_class' => $this->config['class']['civility'],
-                       //Set civility default
-                       'civility_default' => $doctrine->getRepository($this->config['class']['civility'])->findOneByTitle($this->config['default']['civility']),
-                       //Disable mail
-                       'mail' => $this->isGranted('ROLE_ADMIN'),
-                       //Disable password
-                       'password' => false,
-                       //Set method
-                       'method' => 'POST'
-               ]);
-
                //Create the RegisterType form and give the proper parameters
                $edit = $this->createForm($this->config['edit']['view']['edit'], $user, [
                        //Set action to register route name and context
@@ -749,11 +733,28 @@ class DefaultController extends AbstractController {
         * @return Response The response
         */
        public function register(Request $request, Registry $doctrine, UserPasswordEncoderInterface $encoder, EntityManagerInterface $manager, SluggerUtil $slugger, MailerInterface $mailer, LoggerInterface $logger, $mail, $field, $hash): Response {
-               //Init reflection
-               $reflection = new \ReflectionClass($this->config['class']['user']);
-
-               //Create new user
-               $user = $reflection->newInstance();
+               //With mail
+               if (!empty($_POST['register']['mail'])) {
+                       //Log new user infos
+                       $logger->emergency(
+                               $this->translator->trans(
+                                       'register: mail=%mail% locale=%locale% confirm=%confirm%',
+                                       [
+                                               '%mail%' => $postMail = $_POST['register']['mail'],
+                                               '%locale%' => $request->getLocale(),
+                                               '%confirm%' => $this->get('router')->generate(
+                                                       $this->config['route']['confirm']['name'],
+                                                       //Prepend subscribe context with tag
+                                                       [
+                                                               'mail' => $postSmail = $slugger->short($postMail),
+                                                               'hash' => $slugger->hash($postSmail)
+                                                       ]+$this->config['route']['confirm']['context'],
+                                                       UrlGeneratorInterface::ABSOLUTE_URL
+                                               )
+                                       ]
+                               )
+                       );
+               }
 
                //With mail and field
                if (!empty($field) && !empty($hash)) {
@@ -775,9 +776,6 @@ class DefaultController extends AbstractController {
                                        throw new BadRequestHttpException($this->translator->trans('Invalid %field% field: %value%', ['%field%' => 'mail', '%value%' => $smail]));
                                }
 
-                               //Set mail
-                               $user->setMail($mail);
-
                                //With existing registrant
                                if ($existing = $doctrine->getRepository($this->config['class']['user'])->findOneByMail($mail)) {
                                        //With disabled existing
@@ -912,6 +910,12 @@ class DefaultController extends AbstractController {
                        $field = [];
                }
 
+               //Init reflection
+               $reflection = new \ReflectionClass($this->config['class']['user']);
+
+               //Create new user
+               $user = $reflection->newInstance(strval($mail));
+
                //Create the RegisterType form and give the proper parameters
                $form = $this->createForm($this->config['register']['view']['form'], $user, $field+[
                        //Set action to register route name and context
@@ -1014,19 +1018,6 @@ class DefaultController extends AbstractController {
                                //XXX: DEBUG: remove me
                                //die($registerMail['context']['confirm_url']);
 
-                               //Log new user infos
-                               //XXX: useless ???
-                               $logger->emergency(
-                                       $this->translator->trans(
-                                               'newuser:mail=%mail%|locale=%locale%|confirm=%confirm%',
-                                               [
-                                                       '%mail%' => $data->getMail(),
-                                                       '%locale%' => $request->getLocale(),
-                                                       '%confirm%' => $registerMail['context'][$this->config['register']['route']['confirm']]
-                                               ]
-                                       )
-                               );
-
                                //Set recipient_name
                                $registerMail['context']['recipient_mail'] = $data->getMail();