3
3
namespace App \User \EventListener ;
4
4
5
5
use App \DB \Entity \User \User ;
6
+ use App \System \Mail \MailerAdapter ;
6
7
use App \User \Achievements \AchievementManager ;
7
8
use Doctrine \Persistence \Event \LifecycleEventArgs ;
8
9
use Exception ;
9
10
use Psr \Log \LoggerInterface ;
10
- use Symfony \Bridge \Twig \Mime \TemplatedEmail ;
11
- use Symfony \Component \Mailer \Exception \TransportExceptionInterface ;
12
- use Symfony \Component \Mailer \MailerInterface ;
13
- use Symfony \Component \Mime \Address ;
14
11
use Symfony \Contracts \Translation \TranslatorInterface ;
15
12
use SymfonyCasts \Bundle \VerifyEmail \VerifyEmailHelperInterface ;
16
13
17
14
class UserPostPersistNotifier
18
15
{
19
16
protected AchievementManager $ achievement_manager ;
20
17
protected VerifyEmailHelperInterface $ verify_email_helper ;
21
- protected MailerInterface $ mailer ;
18
+ protected MailerAdapter $ mailer ;
22
19
protected LoggerInterface $ logger ;
23
20
protected TranslatorInterface $ translator ;
24
21
25
22
public function __construct (AchievementManager $ achievement_manager ,
26
23
VerifyEmailHelperInterface $ verify_email_helper ,
27
- MailerInterface $ mailer , LoggerInterface $ logger ,
24
+ MailerAdapter $ mailer ,
25
+ LoggerInterface $ logger ,
28
26
TranslatorInterface $ translator )
29
27
{
30
28
$ this ->translator = $ translator ;
@@ -50,27 +48,20 @@ protected function addVerifiedDeveloperAchievement(User $user): void
50
48
51
49
protected function sendVerifyEmail (User $ user ): void
52
50
{
53
- try {
54
- $ signatureComponents = $ this ->verify_email_helper ->generateSignature (
55
- 'registration_confirmation_route ' ,
56
- $ user ->getId (),
57
- $ user ->getEmail ()
58
- );
51
+ $ signatureComponents = $ this ->verify_email_helper ->generateSignature (
52
+ 'registration_confirmation_route ' ,
53
+ $ user ->getId (),
54
+ $ user ->getEmail ()
55
+ );
59
56
60
- $ email = (new TemplatedEmail ())
61
- ->from (new Address ('share@catrob.at ' ))
62
- ->to ($ user ->getEmail ())
63
- ->subject ($ this ->translator ->trans ('user.verification.email ' , [], 'catroweb ' ))
64
- ->htmlTemplate ('security/registration/confirmation_email.html.twig ' )
65
- ->context ([
66
- 'signedUrl ' => $ signatureComponents ->getSignedUrl (),
67
- 'user ' => $ user ,
68
- ])
69
- ;
70
-
71
- $ this ->mailer ->send ($ email );
72
- } catch (TransportExceptionInterface $ e ) {
73
- $ this ->logger ->critical ("Can't send verification email to \"" .$ user ->getEmail ().'" ' .$ e ->getMessage ());
74
- }
57
+ $ this ->mailer ->send (
58
+ $ user ->getEmail (),
59
+ $ this ->translator ->trans ('user.verification.email ' , [], 'catroweb ' ),
60
+ 'security/registration/confirmation_email.html.twig ' ,
61
+ [
62
+ 'signedUrl ' => $ signatureComponents ->getSignedUrl (),
63
+ 'user ' => $ user ,
64
+ ]
65
+ );
75
66
}
76
67
}
0 commit comments