-
-
Notifications
You must be signed in to change notification settings - Fork 476
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Email users on account security changes (#1426)
Co-authored-by: Jordi Boggiano <[email protected]>
- Loading branch information
Showing
5 changed files
with
85 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of Packagist. | ||
* | ||
* (c) Jordi Boggiano <[email protected]> | ||
* Nils Adermann <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace App\Security; | ||
|
||
use Symfony\Bridge\Twig\Mime\TemplatedEmail; | ||
use Symfony\Component\Mailer\MailerInterface; | ||
use Symfony\Component\Mime\Address; | ||
|
||
/** | ||
* @author Pierre Ambroise <[email protected]> | ||
*/ | ||
class UserNotifier | ||
{ | ||
private MailerInterface $mailer; | ||
private string $mailFromEmail; | ||
private string $mailFromName; | ||
|
||
public function __construct(string $mailFromEmail, string $mailFromName, MailerInterface $mailer) | ||
{ | ||
$this->mailer = $mailer; | ||
$this->mailFromEmail = $mailFromEmail; | ||
$this->mailFromName = $mailFromName; | ||
} | ||
|
||
public function notifyChange(string $email, string $reason): void | ||
{ | ||
$email = (new TemplatedEmail()) | ||
->from(new Address($this->mailFromEmail, $this->mailFromName)) | ||
->to($email) | ||
->subject('A change has been made to your account') | ||
->textTemplate('email/alert_change.txt.twig') | ||
->context([ | ||
'reason' => $reason, | ||
]); | ||
|
||
$this->mailer->send($email); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{% autoescape false -%} | ||
|
||
A critical account security change has been made to your account: | ||
|
||
------------------------------- | ||
Change: {{ reason }} | ||
Time: {{ 'now'|date('c') }} | ||
------------------------------- | ||
|
||
{%- endautoescape %} |