+ //Generate each route route
+ foreach($this->config['recover']['route'] as $route => $tag) {
+ //Only process defined routes
+ if (!empty($this->config['route'][$route])) {
+ //Process for recover mail url
+ if ($route == 'recover') {
+ //Set the url in context
+ $context[$tag] = $this->router->generate(
+ $this->config['route'][$route]['name'],
+ //Prepend recover context with tag
+ [
+ 'mail' => $smail = $this->slugger->short($context['recipient_mail']),
+ 'pass' => $spass = $this->slugger->hash($pass = $user->getPassword()),
+ 'hash' => $this->slugger->hash($smail.$spass)
+ ]+$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['recover']['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['recover']['mail']['html'])
+ ->textTemplate($this->config['recover']['mail']['text'])
+
+ //Set context
+ ->context($context);
+
+ //Try sending message
+ //XXX: mail delivery may silently fail
+ try {
+ //Send message
+ $this->mailer->send($message);
+
+ //Add notice
+ $this->addFlash('notice', $this->translator->trans('Your recovery mail has been sent, to retrieve your account you must follow the recuperate link inside'));
+
+ //Add junk warning
+ $this->addFlash('warning', $this->translator->trans('If you did not receive a recovery mail, check your Spam or Junk mail folders'));
+
+ //Redirect on the same route with sent=1 to cleanup form
+ return $this->redirectToRoute($request->get('_route'), ['sent' => 1]+$request->get('_route_params'), 302);
+ //Catch obvious transport exception
+ } catch(TransportExceptionInterface $e) {
+ //Add error message mail unreachable
+ $form->get('mail')->addError(new FormError($this->translator->trans('Unable to reach account')));
+ }
+ }