Sends the password-reset-token of a user to an email-adress.

@param UserInterface $user
@param string $from From-Email-Address
@param string $to To-Email-Address

@throws NoTokenFoundException
@throws TokenEmailsLimitReachedException
436875
private function sendTokenEmail(UserInterface $user, $from, $to)
    {
        if (null === $user->getPasswordResetToken()) {
            throw new NoTokenFoundException($user);
        }

        $maxNumberEmails = $this->getParameter('sulu_security.reset_password.mail.token_send_limit');

        if ($user->getPasswordResetTokenEmailsSent() === $maxNumberEmails) {
            throw new TokenEmailsLimitReachedException($maxNumberEmails, $user);
        }
        $mailer = $this->get('mailer');
        $em = $this->getDoctrine()->getManager();
        $message = $mailer->createMessage()->setSubject(
                $this->getSubject()
            )->setFrom($from)->setTo($to)->setBody(
                $this->getMessage($user)
            );
        $mailer->send($message);
        $user->setPasswordResetTokenEmailsSent($user->getPasswordResetTokenEmailsSent() + 1);
        $em->persist($user);
        $em->flush();
    }
1201894
public function replaceSubjectUser(User $from, User $to)
    {
        $subjects = $this->subjectRepo->findByCreator($from);
        if (count($subjects) > 0) {
            foreach ($subjects as $subject) {
                $subject->setCreator($to);
            }
            $this->om->flush();
        }

        return count($subjects);
    }
880256
public function sendUpdateEmailConfirmation(UserInterface $user, $confirmationUrl, $toEmail)
    {
        $template = $this->parameters['template']['email_updating'];
        $fromEmail = $this->parameters['from_email']['confirmation'];
        $context = array(
            'user' => $user,
            'confirmationUrl' => $confirmationUrl,
        );

        $this->sendMessage($template, $context, $fromEmail, $toEmail);
    }
689563
public function replaceUser(User $from, User $to)
    {
        $notificationUserParameters = $this->notificationUserParametersRepository->findByUser($from);

        if (count($notificationUserParameters) > 0) {
            foreach ($notificationUserParameters as $notificationUserParameter) {
                $notificationUserParameter->setUser($to);
            }

            $this->em->flush();
        }

        return count($notificationUserParameters);
    }
900718
public function replaceUser(User $from, User $to)
    {
        $corrections = $this->em->getRepository('IcapDropzoneBundle:Correction')->findByUser($from);

        if (count($corrections) > 0) {
            foreach ($corrections as $correction) {
                $correction->setUser($to);
            }

            $this->em->flush();
        }

        return count($corrections);
    }
383262
public function send(NumberAwareInterface $user): void
    {
        $token = $this->pinGenerator->generate();
        $user->setPhoneNumberVerificationToken($token);
        $user->setPhoneNumberRequestedAt(new \DateTime());

        if (!$this->disabled) {
            $this->smsSender->send($user->getPhoneNumber(), 'Your token is: ' . $token);
        }
    }
1227735
public function replaceCompetencyProgressUser(User $from, User $to)
    {
        $competencyProgresses = $this->competencyProgressRepo->findByUser($from);

        if (count($competencyProgresses) > 0) {
            foreach ($competencyProgresses as $competencyProgress) {
                $competencyProgress->setUser($to);
            }

            $this->om->flush();
        }

        return count($competencyProgresses);
    }
428443
public function setUser(UserInterface $user): UserTokenInterface
    {
        $serialize_user = serialize($user);

        $this->Session->set($this->session_key, $serialize_user);

        return $this;
    }
1149175
public function replaceDocumentUser(User $from, User $to)
    {
        $documents = $this->documentRepo->findByUser($from);

        if (count($documents) > 0) {
            foreach ($documents as $document) {
                $document->setUser($to);
            }

            $this->om->flush();
        }

        return count($documents);
    }
1096952
public function transferRoles(User $from, User $to)
    {
        $roles = $from->getEntityRoles();

        foreach ($roles as $role) {
            $to->addRole($role);
        }

        $this->objectManager->flush();

        return count($roles);
    }
562459
public function replaceUser(User $from, User $to)
    {
        $portfolioUsers = $this->repo->findByUser($from);

        if (count($portfolioUsers) > 0) {
            foreach ($portfolioUsers as $portfolioUser) {
                $portfolioUser->setUser($to);
            }

            $this->om->flush();
        }

        return count($portfolioUsers);
    }
80929
function copyAsUser($from, $to)
    {
        copy($from, $to);

        $this->chown($to, user());
    }
1271050
public function replaceUser(User $from, User $to)
    {
        $portfolioGuides = $this->entityManager->getRepository('IcapPortfolioBundle:PortfolioGuide')->findByUser($from);

        if (count($portfolioGuides) > 0) {
            foreach ($portfolioGuides as $portfolioGuide) {
                $portfolioGuide->setUser($to);
            }

            $this->entityManager->flush();
        }

        return count($portfolioGuides);
    }
509939
public function resettingPassword(Request $request, UserPasswordEncoderInterface $encoder, EventDispatcherInterface $dispatcher, \Swift_Mailer $mailer, TranslatorInterface $translator, $token)
    {
        // Get Doctrine
        $em = $this->getDoctrine()->getManager();

        // Find User
        $user = $em->getRepository($this->getParameter('pd_user.user_class'))->findOneBy(['confirmationToken' => $token]);
        if (null === $user) {
            throw $this->createNotFoundException(sprintf($translator->trans('security.token_notfound'), $token));
        }

        // Build Form
        $form = $this->createForm(ResettingPasswordType::class, $user);

        // Handle Form Submit
        $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid()) {
            // Encode Password & Set Token
            $password = $encoder->encodePassword($user, $form->get('plainPassword')->getData());
            $user->setPassword($password)
                ->setConfirmationToken(null)
                ->setPasswordRequestedAt(null);

            // Save User
            $em->persist($user);
            $em->flush();

            // Dispatch Register Event
            if ($response = $dispatcher->dispatch(UserEvent::RESETTING_COMPLETE, new UserEvent($user))->getResponse()) {
                return $response;
            }

            // Send Resetting Complete
            $this->sendEmail($user, $mailer, 'Account Password Resetting', 'Password resetting completed.', 'Resetting_Completed');

            // Render Success
            return $this->render($this->getParameter('pd_user.template_path') . '/Resetting/resettingSuccess.html.twig', [
                'sendEmail' => false,
            ]);
        }

        // Render
        return $this->render($this->getParameter('pd_user.template_path') . '/Resetting/resettingPassword.html.twig', [
            'token' => $token,
            'form' => $form->createView(),
        ]);
    }
1046013
public function replaceUser(User $from, User $to)
    {
        $favourites = $this->repo->findByUser($from);

        if (count($favourites) > 0) {
            foreach ($favourites as $favourite) {
                $favourite->setUser($to);
            }

            $this->om->flush();
        }

        return count($favourites);
    }
673746
public function replaceCorrectionUser(User $from, User $to)
    {
        $corrections = $this->correctionRepo->findByUser($from);

        if (count($corrections) > 0) {
            foreach ($corrections as $correction) {
                $correction->setUser($to);
            }

            $this->om->flush();
        }

        return count($corrections);
    }
579161
public function sendCreationEmailMessage(UserInterface $user, $password)
    {
        /** @var \Ekyna\Bundle\UserBundle\Model\UserInterface $user */
        $siteName  = $this->settingsManager->getParameter('general.site_name');
        $userName = sprintf('%s %s', $user->getFirstName(), $user->getLastName());
        $login = $user->getUsername();

        if (0 === strlen($password)) {
            return 0;
        }

        if (null === $loginUrl = $this->getLoginUrl($user)) {
            return 0;
        }

        $rendered = $this->templating->render(
            'EkynaUserBundle:Admin/User:creation_email.html.twig',
            [
                'username'  => $userName,
                'sitename'  => $siteName,
                'login_url' => $loginUrl,
                'login'     => $login,
                'password'  => $password,
            ]
        );

        $subject = $this->translator->trans(
            'ekyna_user.email.creation.subject',
            ['%sitename%' => $siteName]
        );

        return $this->sendEmail($rendered, $user->getEmail(), $userName, $subject);
    }