/** * Validation of email adress * * @param Application $app A Silex application where the controller is mounted on * @param Request $request The current request * @return RedirectResponse */ public function registerConfirm(PhraseaApplication $app, Request $request) { if (null === ($code = $request->query->get('code'))) { $app->addFlash('error', $app->trans('Invalid unlock link.')); return $app->redirectPath('homepage'); } try { $datas = $app['tokens']->helloToken($code); } catch (NotFoundHttpException $e) { $app->addFlash('error', $app->trans('Invalid unlock link.')); return $app->redirectPath('homepage'); } if (null === ($user = $app['manipulator.user']->getRepository()->find((int) $datas['usr_id']))) { $app->addFlash('error', _('Invalid unlock link.')); return $app->redirectPath('homepage'); } if (!$user->isMailLocked()) { $app->addFlash('info', $app->trans('Account is already unlocked, you can login.')); return $app->redirectPath('homepage'); } $app['tokens']->removeToken($code); $user->setMailLocked(false); try { $receiver = Receiver::fromUser($user); } catch (InvalidArgumentException $e) { $app->addFlash('success', $app->trans('Account has been unlocked, you can now login.')); return $app->redirectPath('homepage'); } $app['tokens']->removeToken($code); if (count($app['acl']->get($user)->get_granted_base()) > 0) { $mail = MailSuccessEmailConfirmationRegistered::create($app, $receiver); $app['notification.deliverer']->deliver($mail); $app->addFlash('success', $app->trans('Account has been unlocked, you can now login.')); } else { $mail = MailSuccessEmailConfirmationUnregistered::create($app, $receiver); $app['notification.deliverer']->deliver($mail); $app->addFlash('info', $app->trans('Account has been unlocked, you still have to wait for admin approval.')); } return $app->redirectPath('homepage'); }
public function getMail() { return MailSuccessEmailConfirmationUnregistered::create($this->getApp(), $this->getReceiverMock(), $this->getEmitterMock(), $this->getMessage(), $this->getUrl(), $this->getExpiration()); }
/** * Validation of email address * * @param Request $request The current request * @return RedirectResponse */ public function registerConfirm(Request $request) { if (null === ($code = $request->query->get('code'))) { $this->app->addFlash('error', $this->app->trans('Invalid unlock link.')); return $this->app->redirectPath('homepage'); } if (null === ($token = $this->getTokenRepository()->findValidToken($code))) { $this->app->addFlash('error', $this->app->trans('Invalid unlock link.')); return $this->app->redirectPath('homepage'); } $user = $token->getUser(); if (!$user->isMailLocked()) { $this->app->addFlash('info', $this->app->trans('Account is already unlocked, you can login.')); return $this->app->redirectPath('homepage'); } $tokenManipulator = $this->getTokenManipulator(); $tokenManipulator->delete($token); $user->setMailLocked(false); try { $receiver = Receiver::fromUser($user); } catch (InvalidArgumentException $e) { $this->app->addFlash('success', $this->app->trans('Account has been unlocked, you can now login.')); return $this->app->redirectPath('homepage'); } $tokenManipulator->delete($token); if (count($this->getAclForUser($user)->get_granted_base()) > 0) { $mail = MailSuccessEmailConfirmationRegistered::create($this->app, $receiver); $this->deliver($mail); $this->app->addFlash('success', $this->app->trans('Account has been unlocked, you can now login.')); } else { $mail = MailSuccessEmailConfirmationUnregistered::create($this->app, $receiver); $this->deliver($mail); $this->app->addFlash('info', $this->app->trans('Account has been unlocked, you still have to wait for admin approval.')); } return $this->app->redirectPath('homepage'); }