+ $message = (new TemplatedEmail())
+ //Set sender
+ ->from(new NamedAddress($this->config['contact']['mail'], $this->config['contact']['name']))
+ //Set recipient
+ //XXX: remove the debug set in vendor/symfony/mime/Address.php +46
+ ->to(new NamedAddress($mail['context']['recipient_mail'], $mail['context']['recipient_name']))
+ //Set subject
+ ->subject($mail['subject'])
+
+ //Set path to twig templates
+ ->htmlTemplate($mail['html'])
+ ->textTemplate($mail['text'])
+
+ //Set context
+ ->context(['subject' => $mail['subject']]+$mail['context']+$this->config['recover_mail']['view']['context']);
+
+ //Try sending message
+ //XXX: mail delivery may silently fail
+ try {
+ //Send message
+ $mailer->send($message);
+
+ //Redirect on the same route with sent=1 to cleanup form
+ return $this->redirectToRoute($request->get('_route'), ['recipient' => $recipient, 'hash' => $hash, 'sent' => 1]+$request->get('_route_params'));
+ //Catch obvious transport exception
+ } catch(TransportExceptionInterface $e) {
+ //Add error message mail unreachable
+ $form->get('mail')->addError(new FormError($this->translator->trans('Account password updated but unable to contact: %mail%', array('%mail%' => $mail['context']['recipient_mail']))));
+ }
+ }
+ }
+ //Accout not found
+ } else {
+ //Add error message to mail field
+ $form->get('mail')->addError(new FormError($this->translator->trans('Unable to find account: %mail%', ['%mail%' => $slugger->unshort($recipient)])));
+ }
+
+ //Render view
+ return $this->render(
+ //Template
+ $this->config['recover_mail']['view']['name'],
+ //Context
+ ['form' => $form->createView(), 'sent' => $request->query->get('sent', 0), 'notfound' => $notfound]+$this->config['recover_mail']['view']['context']
+ );
+ }
+
+ public function register(Request $request, UserPasswordEncoderInterface $encoder, MailerInterface $mailer) {
+ //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'],
+ //Set action to register route name and context
+ 'action' => $this->generateUrl($this->config['route']['register']['name'], $this->config['route']['register']['context']),
+ 'method' => 'POST'
+ ));
+
+ if ($request->isMethod('POST')) {
+ //Refill the fields in case the form is not valid.
+ $form->handleRequest($request);
+
+ if ($form->isValid()) {
+ //Set data
+ $data = $form->getData();
+
+ //Set mail shortcut
+ $mail =& $this->config['register']['mail'];
+
+ //Generate each route route
+ foreach($this->config['register']['route'] as $route => $tag) {
+ if (empty($mail['context'][$tag]) && !empty($this->config['route'][$route])) {
+ $mail['context'][$tag] = $this->get('router')->generate(
+ $this->config['route'][$route]['name'],
+ $this->config['route'][$route]['context'],
+ UrlGeneratorInterface::ABSOLUTE_URL