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');
    }