/**
  * @param string $type
  * @param UserInterface $user
  */
 protected function sendMails($type, UserInterface $user)
 {
     if ($user instanceof BaseUser) {
         // get WebSpace type specific config
         $from = $this->getConfig($type, Configuration::MAIL_FROM);
         $to = $this->getConfig($type, Configuration::MAIL_TO);
         $subject = $this->getConfig($type, Configuration::MAIL_SUBJECT);
         $replyTo = $this->getConfig($type, Configuration::MAIL_REPLY_TO);
         $adminTemplate = $this->getTemplate($type, Configuration::TEMPLATE_ADMIN);
         $userTemplate = $this->getTemplate($type, Configuration::TEMPLATE_USER);
         if ($userTemplate) {
             // send email to user
             $body = $this->renderView($userTemplate, ['user' => $user]);
             $this->getMailHelper()->send($from, $user->getEmail(), $subject, $body, $replyTo);
         }
         if ($adminTemplate) {
             // send email to admin
             $body = $this->renderView($adminTemplate, ['user' => $user]);
             $this->getMailHelper()->send($from, $to, $subject, $body, $user->getEmail());
         }
     }
 }
Beispiel #2
0
 /**
  * Processes the email and adds it to the user.
  *
  * @param UserInterface $user
  * @param string        $email
  * @param null|array    $contact
  *
  * @throws EmailNotUniqueException
  */
 private function processEmail(UserInterface $user, $email, $contact = null)
 {
     if ($contact) {
         // if no email passed try to use the contact's first email
         if ($email === null && array_key_exists('emails', $contact) && count($contact['emails']) > 0 && $this->isEmailUnique($contact['emails'][0]['email'])) {
             $email = $contact['emails'][0]['email'];
         }
         if ($email !== null) {
             if (!$this->isEmailUnique($email)) {
                 throw new EmailNotUniqueException($email);
             }
             $user->setEmail($email);
         }
     } else {
         if ($email !== null) {
             if ($email !== $user->getEmail() && !$this->isEmailUnique($email)) {
                 throw new EmailNotUniqueException($email);
             }
             $user->setEmail($email);
         } else {
             $user->setEmail(null);
         }
     }
 }
Beispiel #3
0
 /**
  * Get Email address of a user; fallback to contact / account if not defined
  *
  * @param UserInterface $user
  * @param bool $useFallback
  *
  * @return null|string
  */
 public function getEmailAddressOfUser(UserInterface $user, $useFallback = true)
 {
     // take users email address
     $userEmail = $user->getEmail();
     if ($userEmail) {
         return $userEmail;
     }
     // fallback: get contacts / accounts main-email
     $contact = $user->getContact();
     if ($useFallback && $contact) {
         return $this->getEmailAddressOfContact($contact);
     }
     return null;
 }