+ /**
+ * Confirm account from mail link
+ *
+ * @param Request $request The request
+ * @param Registry $manager The doctrine registry
+ * @param UserPasswordEncoderInterface $encoder The password encoder
+ * @param EntityManagerInterface $manager The doctrine entity manager
+ * @param SluggerUtil $slugger The slugger
+ * @param MailerInterface $mailer The mailer
+ * @param string $mail The shorted mail address
+ * @param string $hash The hashed password
+ * @return Response The response
+ */
+ public function confirm(Request $request, Registry $doctrine, UserPasswordEncoderInterface $encoder, EntityManagerInterface $manager, SluggerUtil $slugger, MailerInterface $mailer, $mail, $hash) {
+ //With invalid hash
+ if ($hash != $slugger->hash($mail)) {
+ //Throw bad request
+ throw new BadRequestHttpException($this->translator->trans('Invalid %field% field: %value%', ['%field%' => 'hash', '%value%' => $hash]));
+ }
+
+ //Get mail
+ $mail = $slugger->unshort($smail = $mail);
+
+ //Without valid mail
+ if (filter_var($mail, FILTER_VALIDATE_EMAIL) === false) {
+ //Throw bad request
+ //XXX: prevent slugger reverse engineering by not displaying decoded mail
+ throw new BadRequestHttpException($this->translator->trans('Invalid %field% field: %value%', ['%field%' => 'mail', '%value%' => $smail]));
+ }
+
+ //Without existing registrant
+ if (!($user = $doctrine->getRepository($this->config['class']['user'])->findOneByMail($mail))) {
+ //Add error message mail already exists
+ //XXX: prevent slugger reverse engineering by not displaying decoded mail
+ $this->addFlash('error', $this->translator->trans('Account %mail% do not exists', ['%mail%' => $smail]));
+
+ //Redirect to register view
+ return $this->redirectToRoute($this->config['route']['register']['name'], ['mail' => $smail, 'field' => $sfield = $slugger->serialize([]), 'hash' => $slugger->hash($smail.$sfield)]+$this->config['route']['register']['context']);
+ }
+
+ //Set active
+ $user->setActive(true);
+
+ //Set updated
+ $user->setUpdated(new \DateTime('now'));
+
+ //Persist user
+ $manager->persist($user);
+
+ //Send to database
+ $manager->flush();
+
+ //Add error message mail already exists
+ $this->addFlash('notice', $this->translator->trans('Your account has been activated'));
+
+ //Redirect to user view
+ return $this->redirectToRoute($this->config['route']['edit']['name'], ['mail' => $smail, 'hash' => $slugger->hash($smail)]+$this->config['route']['edit']['context']);
+ }
+
+ /**
+ * Edit account by shorted mail
+ *
+ * @param Request $request The request
+ * @param Registry $manager The doctrine registry
+ * @param EntityManagerInterface $manager The doctrine entity manager
+ * @param SluggerUtil $slugger The slugger
+ * @param string $mail The shorted mail address
+ * @param string $hash The hashed password
+ * @return Response The response
+ */
+ public function edit(Request $request, Registry $doctrine, EntityManagerInterface $manager, SluggerUtil $slugger, $mail, $hash) {
+ //With invalid hash
+ if ($hash != $slugger->hash($mail)) {
+ //Throw bad request
+ throw new BadRequestHttpException($this->translator->trans('Invalid %field% field: %value%', ['%field%' => 'hash', '%value%' => $hash]));
+ }
+
+ //Get mail
+ $mail = $slugger->unshort($smail = $mail);
+
+ //With existing subscriber
+ if (empty($user = $doctrine->getRepository($this->config['class']['user'])->findOneByMail($mail))) {
+ //Throw not found
+ //XXX: prevent slugger reverse engineering by not displaying decoded mail
+ throw $this->createNotFoundException($this->translator->trans('Unable to find account %mail%', ['%mail%' => $smail]));
+ }
+
+ //Prevent access when not admin, user is not guest and not currently logged user
+ if (!$this->isGranted('ROLE_ADMIN') && $user != $this->getUser()) {
+ //Throw access denied
+ //XXX: prevent slugger reverse engineering by not displaying decoded mail
+ throw $this->createAccessDeniedException($this->translator->trans('Unable to access user: %mail%', ['%mail%' => $smail]));
+ }
+
+ //Create the RegisterType form and give the proper parameters
+ $form = $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
+ //XXX: prefer a reset on login to force user unspam action
+ 'password' => false,
+ //Set method
+ '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();
+
+ //Queue snippet save
+ $manager->persist($data);
+
+ //Flush to get the ids
+ $manager->flush();
+
+ //Add notice
+ $this->addFlash('notice', $this->translator->trans('Account %mail% updated', ['%mail%' => $mail = $data->getMail()]));
+
+ //Redirect to user view
+ //TODO: extract referer ??? or useless ???
+ return $this->redirectToRoute($this->config['route']['edit']['name'], ['mail' => $smail = $slugger->short($mail), 'hash' => $slugger->hash($smail)]+$this->config['route']['edit']['context']);
+
+ //Redirect to cleanup the form
+ return $this->redirectToRoute('rapsys_air', ['user' => $data->getId()]);
+ }
+ } else {
+ //Add notice
+ $this->addFlash('notice', $this->translator->trans('To change your password relogin with your mail %mail% and any password then follow the procedure', ['%mail%' => $mail]));
+ }
+
+ //Render view
+ return $this->render(
+ //Template
+ $this->config['edit']['view']['name'],
+ //Context
+ ['form' => $form->createView(), 'sent' => $request->query->get('sent', 0)]+$this->config['edit']['view']['context']
+ );
+ }
+
+ /**
+ * Login
+ *
+ * @todo When account is not activated, refuse login and send verification mail ?
+ * @todo Redirect to referer if route is not connect ?
+ *
+ * @param Request $request The request
+ * @param AuthenticationUtils $authenticationUtils The authentication utils
+ * @param RouterInterface $router The router instance
+ * @param SluggerUtil $slugger The slugger
+ * @param string $mail The shorted mail address
+ * @param string $hash The hashed password
+ * @return Response The response
+ */
+ public function login(Request $request, AuthenticationUtils $authenticationUtils, RouterInterface $router, SluggerUtil $slugger, $mail, $hash) {