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