script to send batch password recover code

This commit is contained in:
2018-08-31 17:04:45 +02:00
parent f6b6ec57bb
commit 04bdaa308a
5 changed files with 242 additions and 9 deletions

View File

@@ -47,26 +47,53 @@ class RecoverPasswordHelper
*/
protected $mailer;
protected $routeParameters;
const RECOVER_PASSWORD_ROUTE = 'password_recover';
public function __construct(
TokenManager $tokenManager,
UrlGeneratorInterface $urlGenerator,
Mailer $mailer
Mailer $mailer,
array $routeParameters
) {
$this->tokenManager = $tokenManager;
$this->urlGenerator = $urlGenerator;
$this->mailer = $mailer;
$this->routeParameters = $routeParameters;
}
public function generateUrl(User $user, \DateTimeInterface $expiration, $absolute = true)
/**
*
* @param User $user
* @param \DateTimeInterface $expiration
* @param bool $absolute
* @param array $parameters additional parameters to url
* @return string
*/
public function generateUrl(User $user, \DateTimeInterface $expiration, $absolute = true, array $parameters = [])
{
return $this->urlGenerator->generate(
$context = $this->urlGenerator->getContext();
$previousHost = $context->getHost();
$previousScheme = $context->getScheme();
$context->setHost($this->routeParameters['host']);
$context->setScheme($this->routeParameters['scheme']);
$url = $this->urlGenerator->generate(
self::RECOVER_PASSWORD_ROUTE,
$this->tokenManager->generate($user, $expiration),
\array_merge(
$this->tokenManager->generate($user, $expiration),
$parameters),
$absolute ? UrlGeneratorInterface::ABSOLUTE_URL : UrlGeneratorInterface::ABSOLUTE_PATH
);
// reset the host
$context->setHost($previousHost);
$context->setScheme($previousScheme);
return $url;
}
public function sendRecoverEmail(
@@ -74,21 +101,23 @@ class RecoverPasswordHelper
\DateTimeInterface $expiration,
$template = '@ChillMain/Password/recover_email.txt.twig',
array $templateParameters = [],
$force = false
$force = false,
array $additionalUrlParameters = [],
$emailSubject = 'Recover your password'
) {
$content = $this->mailer->renderContentToUser(
$user,
$template,
\array_merge([
'user' => $user,
'url' => $this->generateUrl($user, $expiration, true)
'url' => $this->generateUrl($user, $expiration, true, $additionalUrlParameters)
],
$templateParameters
));
$this->mailer->sendNotification(
$user,
[ 'Recover your password' ],
[ $emailSubject ],
[
'text/plain' => $content,
],