+ //With not enabled user
+ } elseif ($parent instanceof DisabledException) {
+ //Add error message account is not enabled
+ $this->addFlash('error', $this->translator->trans('Your account is not enabled'));
+
+ //Redirect on the same route with sent=1 to cleanup form
+ return new RedirectResponse($this->router->generate($request->get('_route'), $request->get('_route_params')), 302);
+ //With not activated user
+ } elseif ($parent instanceof UnactivatedException) {
+ //Set user
+ $user = $parent->getUser();
+
+ //Set context
+ $context = [
+ 'recipient_mail' => $user->getMail(),
+ 'recipient_name' => $user->getRecipientName()
+ ] + array_replace_recursive(
+ $this->config['context'],
+ $this->config['register']['view']['context'],
+ $this->config['register']['mail']['context']
+ );
+
+ //Generate each route route
+ foreach($this->config['register']['route'] as $route => $tag) {
+ //Only process defined routes
+ if (!empty($this->config['route'][$route])) {
+ //Process for confirm url
+ if ($route == 'confirm') {
+ //Set the url in context
+ $context[$tag] = $this->router->generate(
+ $this->config['route'][$route]['name'],
+ //Prepend confirm context with tag
+ [
+ 'mail' => $smail = $this->slugger->short($context['recipient_mail']),
+ 'hash' => $this->slugger->hash($smail)
+ ]+$this->config['route'][$route]['context'],
+ UrlGeneratorInterface::ABSOLUTE_URL
+ );
+ }
+ }
+ }
+
+ //Iterate on keys to translate
+ foreach($this->config['translate'] as $translate) {
+ //Extract keys
+ $keys = explode('.', $translate);
+
+ //Set current
+ $current =& $context;
+
+ //Iterate on each subkey
+ do {
+ //Skip unset translation keys
+ if (!isset($current[current($keys)])) {
+ continue(2);
+ }
+
+ //Set current to subkey
+ $current =& $current[current($keys)];
+ } while(next($keys));
+
+ //Set translation
+ $current = $this->translator->trans($current);
+
+ //Remove reference
+ unset($current);
+ }
+
+ //Translate subject
+ $context['subject'] = $subject = ucfirst(
+ $this->translator->trans(
+ $this->config['register']['mail']['subject'],
+ $this->slugger->flatten($context, null, '.', '%', '%')
+ )
+ );
+
+ //Create message
+ $message = (new TemplatedEmail())
+ //Set sender
+ ->from(new Address($this->config['contact']['address'], $this->config['contact']['name']))
+ //Set recipient
+ //XXX: remove the debug set in vendor/symfony/mime/Address.php +46
+ ->to(new Address($context['recipient_mail'], $context['recipient_name']))
+ //Set subject
+ ->subject($context['subject'])
+
+ //Set path to twig templates
+ ->htmlTemplate($this->config['register']['mail']['html'])
+ ->textTemplate($this->config['register']['mail']['text'])
+
+ //Set context
+ ->context($context);
+
+ //Try sending message
+ //XXX: mail delivery may silently fail
+ try {
+ //Send message
+ $this->mailer->send($message);
+ //Catch obvious transport exception
+ } catch(TransportExceptionInterface $e) {
+ //Add error message mail unreachable
+ $this->addFlash('error', $this->translator->trans('Unable to reach account'));
+ }
+
+ //Add notice
+ $this->addFlash('notice', $this->translator->trans('Your verification mail has been sent, to activate your account you must follow the confirmation link inside'));
+
+ //Add junk warning
+ $this->addFlash('warning', $this->translator->trans('If you did not receive a verification mail, check your Spam or Junk mail folders'));
+
+ //Redirect on the same route with sent=1 to cleanup form
+ return new RedirectResponse($this->router->generate($request->get('_route'), $request->get('_route_params')), 302);