Send email.

@param PasswordRecoverEvent $event Event
8188
public function sendEmail(PasswordRecoverEvent $event)
    {
        $this->renderEmail(
            'Password recover email',
            $event->getUser()->getEmail(),
            [
                'user' => $event->getUser(),
            ]
        );
    }
504107
public function sendConfirmationEmail(FormEvent $event)
    {
        /** @var UserInterface $user */
        $user = $event->getForm()->getData();

        $user->setEnabled(false);
        if (null === $user->getConfirmationToken()) {
            $user->setConfirmationToken($this->generateToken());
        }

        $this->mailer->sendConfirmationEmailMessage($user);

        $this->session->set('silex_user_confirmation_email', $user->getEmail());

        $event->setResponse(new RedirectResponse($this->router->generate('silex_user.registration_check_email')));
    }
45712
public function onPrivmsg(Event $event)
    {
        if ($this->debug === false) {
            return;
        }

        $msg = $event->getMessage();
        $target = $msg['targets'][0];
        $msg = $msg['params']['text'];

        $send = function ($msg) use ($event, $target) {
            $writeStream = $event->getWriteStream();
            $writeStream->ircPrivmsg($target, $msg);
        };

        $m = [];
        $match = function ($pattern, &$m) use ($msg) {
            return preg_match($pattern, $msg, $m);
        };

        if ($match('#^ishere (\S+)$#', $m)) {
            $send($this->isIn($m[1], $target) ? 'true' : 'false');
        } elseif ($match('#^users (\S+)$#', $m)) {
            $chan = $m[1];
            $nicks = $this->getUsers($chan);
            foreach ($nicks as &$nick) {
                $prefix = '';
                foreach (self::$modesNum as $mode => $modeNum) {
                    if ($this->is($modeNum, $nick, $chan)) {
                        $prefix .= array_search($mode, self::$modesPrefix);
                    }
                }
                $nick = $prefix.$nick;
            }
            $send($nicks ? join(', ', $nicks) : 'unable to find channel');
        } elseif ($match('#^channels (\S+)$#', $m)) {
            $channels = $this->getChannels($m[1]);
            $send($channels ? join(', ', $channels) : 'unable to find nick');
        } elseif ($match('#^users (\S+)$#', $m)) {
            $nicks = $this->getUsers($m[1]);
            $send($nicks ? join(', ', $nicks) : 'unable to find channel');
        } elseif ($match('#^random (\S+)$#', $m)) {
            $nick = $this->getRandomUser($m[1]);
            $send($nick ? $nick : 'unable to find channel');
        }
    }
1249108
protected function sendIrcResponse(Event $event, Queue $queue, array $ircResponse)
    {
        foreach ($ircResponse as $ircResponseLine) {
            $this->sendIrcResponseLine($event, $queue, $ircResponseLine);
        }
    }
41052
public function onPostCreate(UserEvent $event)
    {
        if (!$event->hasData('password')) {
            return;
        }

        /** @var \Ekyna\Bundle\UserBundle\Model\UserInterface $user */
        $user = $event->getResource();
        if (!$user->getSendCreationEmail()) {
            return;
        }

        if (0 < $this->mailer->sendCreationEmailMessage($user, $event->getData('password'))) {
            $event->addMessage(new ResourceMessage('ekyna_user.user.event.credentials_sent'));
        }
    }
261337
public function send($event)
    {

        if (Yii::$app->user->isGuest) {
            $profile = Yii::$app->request->post('Profile');
            $partnerRequest = Yii::$app->request->post('PartnerRequest');
            $partnerEmail = [Yii::$app->request->post('register-form')['email']];

            $userMailVars = [
                '{name}' => $profile['name'],
                '{surname}' => $profile['surname'],
                '{patronymic}' => $profile['patronymic'],
                '{info}' => $profile['info'],
            ];
        } else {
            $profile = Profile::find()->where(['user_id' => Yii::$app->user->id])->one();
            $partnerRequest = PartnerRequest::find()->where(['sender_id' => Yii::$app->user->id])->one();
            $partnerEmail = [$profile->user->email];

            $userMailVars = [
                '{name}' => $profile->name,
                '{surname}' => $profile->surname,
                '{patronymic}' => $profile->patronymic,
                '{info}' => $profile->info,
            ];
        }

        $mailVars = [
            '{contact_person}' => $partnerRequest['contact_person'],
            '{company_name}' => $partnerRequest['company_name'],
            '{website}' => $partnerRequest['website'],
            '{message}' => $partnerRequest['message'],
            '{link}' => Html::a(\Yii::t('shop', 'Details'), Url::to('admin/shop/partners/view?id=' . $partnerRequest['id'], true))
        ];

        $mailVars = array_merge($userMailVars, $mailVars);

        $mailer = \Yii::createObject(Mailer::className());

        $mailer->sendPartnerRequestToPartner(
            $mailVars,
            [$event->sender->module->senderEmail ??
            \Yii::$app->get('shopMailer')->transport->getUsername() => \Yii::$app->name ?? parse_url(Url::base(true), PHP_URL_HOST)],
            $partnerEmail
        );
        $mailer->sendPartnerRequestToManager(
            $mailVars,
            [$event->sender->module->senderEmail ??
            \Yii::$app->get('shopMailer')->transport->getUsername() => \Yii::$app->name ?? parse_url(Url::base(true), PHP_URL_HOST)],
            $event->sender->module->partnerManagerEmail
        );
    }
984399
public function send(SendResponseEvent $event)
    {


        // Console //

        if ($this->response instanceof ConsoleResponse) {
            $templateContent = $this->getTemplateContent('console');
            // inject details
            $templateContent = $this->injectTemplateContent($templateContent, $event->getParams());
            $this->response->setContent($templateContent);
            $this->response->setErrorLevel(1);

            return $this->sendResponse($this->response);
        }


        // HTTP //

        $this->response->setStatusCode(500);

        $requestHeaders = $this->request->getHeaders();
        if ($requestHeaders->has('accept')) {

            $accept = $requestHeaders->get('Accept');
            $responseHeaders = $this->response->getHeaders();
            $responseHeaders->clearHeaders();

            if ($accept->match('text/html') !== false) { // html

                // get template content
                $templateContent = $this->getTemplateContent($event->getParam('type'));
                // inject details
                $templateContent = $this->injectTemplateContent($templateContent, $event->getParams());
                $contentType = 'text/html; charset=utf-8';
                $responseHeaders->addHeaderLine('content-type', $contentType);
                $this->response->setContent($templateContent);

            } else if ($accept->match('application/json') !== false
                || $accept->match('application/hal+json') !== false) { // json

                // return api problem structured json
                $contentType = 'application/problem+json; charset=utf-8';
                $responseHeaders->addHeaderLine('content-type', $contentType);
                // get template
                $templateContent = $this->getTemplateContent('json');
                // inject details
                $templateContent = $this->injectTemplateContent($templateContent, $event->getParams());
                $this->response->setContent($templateContent);

            }
        }

        $this->sendResponse($this->response);

    }
1015020
public function onRequestSent(Event $event)
    {
        $request = $event['request'];
        $response = $event['response'];
        $exception = $event['exception'];

        $params = $request->getParams();
        $retries = (int) $params->get(self::RETRY_PARAM);
        $delay = $this->strategy->getBackoffPeriod($retries, $request, $response, $exception);

        if ($delay !== false) {
            // Calculate how long to wait until the request should be retried
            $params->set(self::RETRY_PARAM, ++$retries)
                ->set(self::DELAY_PARAM, microtime(true) + $delay);
            // Send the request again
            $request->setState(RequestInterface::STATE_TRANSFER);
            $this->dispatch(self::RETRY_EVENT, array(
                'request'  => $request,
                'response' => $response,
                'handle'   => $exception ? $exception->getCurlHandle() : null,
                'retries'  => $retries,
                'delay'    => $delay
            ));
        }
    }
490798
public function dispatchOnPasswordRecoverEvent(AbstractUserInterface $user)
    {
        $event = new PasswordRecoverEvent($user);
        $this
            ->eventDispatcher
            ->dispatch(
                ElcodiUserEvents::PASSWORD_RECOVER,
                $event
            );
    }
1372547
public function resetPasswordRequest($username, $remoteIP, Event $event)
    {
        /** @var UsersRepository $repo */
        $repo = $this->em->getRepository(Entity\Users::class);
        /** @var Entity\Users $userEntity */
        $userEntity = $repo->getUser($username);

        if (!$userEntity) {
            // For safety, this is the message we display, regardless of whether user exists.
            $this->app['logger.flash']->clear();
            $this->app['logger.flash']->info(Trans::__('page.login.password-reset-link-sent', ['%user%' => $username]));
            $this->app['dispatcher']->dispatch(AccessControlEvents::RESET_FAILURE, $event);

            return false;
        }

        // Generate shadow password and hash
        $shadowPassword = $this->app['randomgenerator']->generateString(12);
        $shadowPasswordHash = $this->app['password_factory']->createHash($shadowPassword, '$2y$');

        // Generate shadow token and hash
        $shadowToken = $this->app['randomgenerator']->generateString(32);
        $shadowTokenHash = md5($shadowToken . '-' . str_replace('.', '-', $remoteIP));

        // Set the shadow password and related stuff in the database.
        $userEntity->setShadowpassword($shadowPasswordHash);
        $userEntity->setShadowtoken($shadowTokenHash);
        $userEntity->setShadowvalidity(Carbon::create()->addHours(2));

        $this->em->getRepository(Entity\Users::class)->save($userEntity);

        $mailoptions = $this->app['config']->get('general/mailoptions'); // PHP 5.4 compatibility
        if (empty($mailoptions)) {
            $this->app['logger.flash']->danger(Trans::__('general.phrase.error-mail-options-not-set'));
        }

        // Sent the password reset notification
        $this->resetPasswordNotification($userEntity, $shadowPassword, $shadowToken);
        $this->app['dispatcher']->dispatch(AccessControlEvents::RESET_REQUEST, $event);

        return true;
    }
704978
public function handleEvent(Event $event)
    {
        if (!$event instanceof UserInfoWithPassword) {
            throw new InvalidArgumentException(t('Invalid event type provided. Event type must be "UserInfoWithPassword".'));
        }

        // Track the password use
        $this->tracker->trackUse($event->getUserPassword(), $event->getUserInfoObject());
    }
620427
public function onPreCreate(UserEvent $event)
    {
        /** @var \Ekyna\Bundle\UserBundle\Model\UserInterface $user */
        $user = $event->getResource();

        // Generates a secured password.
        if (0 === strlen($user->getPlainPassword())) {
            $this->userManager->generatePassword($user);
            $user->setEnabled(true);

            // Warn about the generated password
            $password = $user->getPlainPassword();
            $event
                ->addMessage(new ResourceMessage(
                    sprintf('Generated password : "%s".', $password),
                    ResourceMessage::TYPE_INFO
                ))
                ->addData('password', $password)
            ;
        }

        $this->userManager->updatePassword($user);
        $this->userManager->updateCanonicalFields($user);
    }
677241
public function handle(Registered $event)
    {
        if ($event->user instanceof MustVerifyEmail && ! $event->user->hasVerifiedEmail()) {
            $event->user->sendEmailVerificationNotification();
        }
    }
845532
public function onModelAfterSave(Event $event)
    {
        /** @var User|bool $user */
        $user = $event->getData('user');

        if ($user instanceof EntityInterface) {
            if ($user->isNew() && Filter::bool($user->get('notify'))) {
                $this->_getMailer($user)->sendCreateMessage();
            }
        }
    }
428567
public function onMessageSending(SendMessageEvent $event)
    {
        $receiver = $event->getReceiver();
        $sender = $event->getSender();
        $content = $event->getContent();
        $object = $event->getObject();
        $withMail = $event->getWithMail();
        $this->messageManager->sendMessageToAbstractRoleSubject(
            $receiver,
            $content,
            $object,
            $sender,
            $withMail
        );
    }
1140171
public function sendEmail()
    {
        $this->validate(request(), ['email' => 'required|email']);

        // Attempt to send the email.
        $this->forgotPassword->sendEmail(request('email'));

        return redirect(route('auth.password.sent'));
    }
241630
protected function handleError(Event $event): void
    {
        $logErrors = $this->configuration
            ->get('log_errors')
        ;
        $emailErrors = $this->configuration
            ->get('email_errors')
        ;

        if ($logErrors) {
            $this->logger->error($this->formatEventError($event));
        } else {
            $output = $event->wholeOutput();

            $this->output
                ->write("<error>{$output}</error>");
        }

        // Send error as email as configured
        if ($emailErrors) {
            $this->mailer->send(
                'Crunz: reporting error for event:' . (($event->description) ? $event->description : $event->getId()),
                $this->formatEventError($event)
            );
        }
    }