From: Raphaƫl Gertz Date: Mon, 7 Dec 2020 22:56:44 +0000 (+0100) Subject: Move recover global form error message to mail entity X-Git-Tag: 0.1.4 X-Git-Url: https://git.rapsys.eu/userbundle/commitdiff_plain/4bee264432b21f4798ab6f660abc99287890261a?ds=sidebyside Move recover global form error message to mail entity Prefill title on registration action Add every group to user where group's title is in rapsys_user.default.group --- diff --git a/Controller/DefaultController.php b/Controller/DefaultController.php index 4bab49b..9e4c117 100644 --- a/Controller/DefaultController.php +++ b/Controller/DefaultController.php @@ -97,13 +97,12 @@ class DefaultController extends AbstractController { 'method' => 'POST' ]); - //Set mail from login form - $recover->get('mail')->setData($login->get('mail')->getData()); - - //Add recover error - $recover->addError(new FormError( - $this->translator->trans('Use this form to recover your account') - )); + //Get recover mail entity + $recover->get('mail') + //Set mail from login form + ->setData($login->get('mail')->getData()) + //Add recover error + ->addError(new FormError($this->translator->trans('Use this form to recover your account'))); //Add recover form to context $context['recover'] = $recover->createView(); @@ -362,9 +361,13 @@ class DefaultController extends AbstractController { } public function register(Request $request, UserPasswordEncoderInterface $encoder, MailerInterface $mailer) { + //Get doctrine + $doctrine = $this->getDoctrine(); + //Create the RegisterType form and give the proper parameters $form = $this->createForm($this->config['register']['view']['form'], null, array( 'class_title' => $this->config['class']['title'], + 'title' => $doctrine->getRepository($this->config['class']['title'])->findOneByTitle($this->config['default']['title']), //Set action to register route name and context 'action' => $this->generateUrl($this->config['route']['register']['name'], $this->config['route']['register']['context']), 'method' => 'POST' @@ -427,9 +430,6 @@ class DefaultController extends AbstractController { //Set context ->context(['subject' => $mail['subject']]+$mail['context']+$this->config['register']['view']['context']); - //Get doctrine - $doctrine = $this->getDoctrine(); - //Get manager $manager = $doctrine->getManager(); @@ -448,10 +448,20 @@ class DefaultController extends AbstractController { $user->setActive(true); $user->setTitle($data['title']); - //XXX: For now there is no point in setting a role at subscription - //TODO: see if we can't modify group constructor to set role directly from args - //XXX: see vendor/symfony/symfony/src/Symfony/Component/Security/Core/Role/Role.php - #$user->addGroup($doctrine->getRepository($this->config['class']['group'])->findOneByRole('ROLE_USER')); + //Iterate on default group + foreach($this->config['default']['group'] as $i => $groupTitle) { + //Fetch group + if (($group = $doctrine->getRepository($this->config['class']['group'])->findOneByTitle($groupTitle))) { + //Set default group + //XXX: see vendor/symfony/security-core/Role/Role.php + $user->addGroup($group); + //Group not found + } else { + //Throw exception + //XXX: consider missing group as fatal + throw new \Exception(sprintf('Group from rapsys_user.default.group[%d] not found by title: %s', $i, $groupTitle)); + } + } $user->setCreated(new \DateTime('now')); $user->setUpdated(new \DateTime('now'));