Ejemplo n.º 1
0
 /**
  * @param AuthEvent $e
  *
  * @return mixed
  */
 public function __invoke(AuthEvent $e)
 {
     $siteName = $this->coreOptions->getSiteName();
     $user = $e->getUser();
     $userEmail = $user->info->email;
     $userName = $user->info->displayName;
     $resetLink = $e->getResetLink();
     $fromEmail = $this->options->getFromEmail();
     $fromName = $this->options->getFromName();
     $mail = $this->mailService->get('htmltemplate');
     $mail->user = $user;
     $mail->resetlink = $resetLink;
     $mail->setTemplate('mail/forgotPassword');
     $mail->setSubject(sprintf('a new password was requestet for %s', $siteName));
     $mail->setTo($userEmail);
     $mail->setFrom($fromEmail, $fromName);
     return $this->mailService->send($mail);
 }
Ejemplo n.º 2
0
 /**
  * allows an event attachment just by class
  * @param JobEvent $e
  */
 public function __invoke(AuthEvent $e)
 {
     /* @todo: get siteName from options */
     $siteName = "YAWIK";
     /** @var ServiceManager $serviceManager */
     $serviceManager = $this->getServiceManager();
     $config = $serviceManager->get('config');
     /**
      * the sender of the mail is the currently logged in user
      */
     /** @var AuthenticationService $authService */
     $authService = $serviceManager->get('authenticationservice');
     $user = $e->getUser();
     $userEmail = $user->info->email;
     $userName = $user->info->displayName;
     $resetLink = $e->getResetLink();
     /** @var ControllerPluginManagerFactory $controllerPluginManager */
     //$controllerPluginManager = $serviceManager->get('controllerPluginManager');
     //$urlPlugin               = $controllerPluginManager->get('url');
     $fromEmail = 'Yawik-System';
     $fromName = $userName;
     if (array_key_exists('mails', $config) && array_key_exists('from', $config['mails'])) {
         if (array_key_exists('email', $config['mails']['from'])) {
             $fromEmail = $config['mails']['from']['email'];
         }
         if (array_key_exists('name', $config['mails']['from'])) {
             $fromName = $config['mails']['from']['name'];
         }
     }
     /**
      * the receiver of the mail is the "admin" of the running yawik installation
      */
     //$config                  = $serviceManager->get('config');
     $mailService = $serviceManager->get('Core/MailService');
     $mail = $mailService->get('htmltemplate');
     $mail->user = $user;
     $mail->resetlink = $resetLink;
     $mail->setTemplate('mail/forgotPassword');
     $mail->setSubject(sprintf('a new password was requestet for %s', $siteName));
     $mail->setTo($userEmail);
     $mail->setFrom($fromEmail, $fromName);
     $mailService->send($mail);
     return;
 }
Ejemplo n.º 3
0
 /**
  * @todo remove unused $mailer parameter an fix tests
  *
  * @param InputFilterInterface $filter
  * @param Plugin\Mailer $mailer
  * @param Url $url
  * @throws \LogicException
  * @throws UserDoesNotHaveAnEmailException
  * @throws UserNotFoundException
  */
 public function proceed(InputFilterInterface $filter, Plugin\Mailer $mailer, Url $url)
 {
     if (!$filter->isValid()) {
         throw new \LogicException('Form is not valid');
     }
     $identity = $filter->getValue('identity');
     $suffix = $this->loginFilter->filter();
     if (!($user = $this->userRepository->findByLoginOrEmail($identity, $suffix))) {
         throw new UserNotFoundException('User is not found');
     }
     if (!($email = $user->getInfo()->getEmail())) {
         throw new UserDoesNotHaveAnEmailException('User does not have an email');
     }
     $tokenHash = $this->tokenGenerator->generate($user);
     $resetLink = $url->fromRoute('lang/goto-reset-password', array('token' => $tokenHash, 'userId' => $user->getId()), array('force_canonical' => true));
     $e = new AuthEvent();
     $e->setResetLink($resetLink);
     $e->setUser($user);
     $this->eventManager->trigger(AuthEvent::EVENT_AUTH_NEWPASSWORD, $e);
 }