| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Kunstmaan\AdminBundle\Service\AuthenticationMailer; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Kunstmaan\AdminBundle\Entity\UserInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Symfony\Bridge\Twig\Mime\TemplatedEmail; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Symfony\Component\Mailer\MailerInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Symfony\Component\Mime\Address; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Symfony\Component\Routing\Generator\UrlGeneratorInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use Symfony\Component\Routing\RouterInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use Symfony\Contracts\Translation\TranslatorInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | class SymfonyMailerService implements AuthenticationMailerInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |     /** @var MailerInterface */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     private $mailer; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |     /** @var TranslatorInterface */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     private $translator; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     /** @var UrlGeneratorInterface */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     private $urlGenerator; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |     /** @var Address */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     private $from; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     public function __construct(MailerInterface $mailer, TranslatorInterface $translator, UrlGeneratorInterface $urlGenerator, Address $from) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |         $this->mailer = $mailer; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |         $this->translator = $translator; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |         $this->urlGenerator = $urlGenerator; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |         $this->from = $from; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 32 |  |  |     public function sendPasswordResetEmail(UserInterface $user, string $locale) | 
            
                                                        
            
                                    
            
            
                | 33 |  |  |     { | 
            
                                                        
            
                                    
            
            
                | 34 |  |  |         $confirmationUrl = $this->urlGenerator->generate('cms_reset_password_confirm', ['token' => $user->getConfirmationToken()], RouterInterface::ABSOLUTE_URL); | 
            
                                                        
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 36 |  |  |         $email = (new TemplatedEmail()) | 
            
                                                        
            
                                    
            
            
                | 37 |  |  |             ->from($this->from) | 
            
                                                        
            
                                    
            
            
                | 38 |  |  |             ->to(new Address($user->getEmail())) | 
            
                                                        
            
                                    
            
            
                | 39 |  |  |             ->subject($this->translator->trans('Password reset email', [], null, $locale)) | 
            
                                                        
            
                                    
            
            
                | 40 |  |  |             ->htmlTemplate('@KunstmaanAdmin/Resetting/email.txt.twig') | 
            
                                                        
            
                                    
            
            
                | 41 |  |  |             ->context([ | 
            
                                                        
            
                                    
            
            
                | 42 |  |  |                 'user' => $user, | 
            
                                                        
            
                                    
            
            
                | 43 |  |  |                 'confirmationUrl' => $confirmationUrl, | 
            
                                                        
            
                                    
            
            
                | 44 |  |  |             ]); | 
            
                                                        
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 46 |  |  |         $this->mailer->send($email); | 
            
                                                        
            
                                    
            
            
                | 47 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 48 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 49 |  |  |  |