From: Raphaƫl Gertz Date: Tue, 17 Aug 2021 23:56:28 +0000 (+0200) Subject: Cleanup X-Git-Tag: 0.2.0~40 X-Git-Url: https://git.rapsys.eu/userbundle/commitdiff_plain/c0d7b2e1474eff99cf5f3b0b79d25bdcd0086ab2 Cleanup Log submitted mail by default Instantiate user when mail is available and force cast it as string --- diff --git a/Controller/DefaultController.php b/Controller/DefaultController.php index 5c3c51c..3a65712 100644 --- a/Controller/DefaultController.php +++ b/Controller/DefaultController.php @@ -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();