Browse Source

[Boutique] Contact : spam et sender from #1407

feature/souke
Guillaume Bourgeois 1 year ago
parent
commit
b362a754a7
4 changed files with 30 additions and 22 deletions
  1. +13
    -3
      common/components/MailerService.php
  2. +11
    -9
      common/forms/ContactForm.php
  3. +4
    -7
      producer/controllers/SiteController.php
  4. +2
    -3
      producer/views/site/contact.php

+ 13
- 3
common/components/MailerService.php View File

{ {
$message = $this->composeBase($toEmail, $view, $params); $message = $this->composeBase($toEmail, $view, $params);
$this->initMessageFromProducer($message, $subject, $producer); $this->initMessageFromProducer($message, $subject, $producer);
$message->send();
return $message->send();
} }


public function sendFromSite(string $subject, string $view, array $params, string $toEmail) public function sendFromSite(string $subject, string $view, array $params, string $toEmail)
{ {
$message = $this->composeBase($toEmail, $view, $params); $message = $this->composeBase($toEmail, $view, $params);
$this->initMessageFromSite($message, $subject); $this->initMessageFromSite($message, $subject);
$message->send();
return $message->send();
}

public function sendProducer(Producer $producer, string $subject, string $view, array $params = [], string $replyTo = null)
{
$message = $this->composeBase($producer->contact_email, $view, $params);
if($replyTo) {
$message->setReplyTo($replyTo);
}
$this->initMessageFromSite($message, $subject);
return $message->send();
} }


public function sendAdmin(string $subject, string $view, array $params = [], string $replyTo = null) public function sendAdmin(string $subject, string $view, array $params = [], string $replyTo = null)
$message->setReplyTo($replyTo); $message->setReplyTo($replyTo);
} }
$this->initMessageFromSite($message, $subject); $this->initMessageFromSite($message, $subject);
$message->send();
return $message->send();
} }


private function composeBase(string $toEmail, string $view, array $params = []) private function composeBase(string $toEmail, string $view, array $params = [])

+ 11
- 9
common/forms/ContactForm.php View File



namespace common\forms; namespace common\forms;


use common\logic\Producer\Producer\Model\Producer;
use Yii; use Yii;
use yii\base\Model; use yii\base\Model;


* @param string $email the target email address * @param string $email the target email address
* @return boolean whether the email was sent * @return boolean whether the email was sent
*/ */
public function sendEmail($email)
public function sendEmail(Producer $producer)
{ {
return Yii::$app->mailer->compose([
'html' => 'contact-html',
'text' => 'contact-text'], [ 'content' => $this->body,
return Yii::$app->mailerService->sendProducer(
$producer,
'Contact : ' . $this->subject,
'contact',
[
'content' => $this->body,
'name' => $this->name 'name' => $this->name
])
->setTo($email)
->setFrom([$this->email => $this->name])
->setSubject('[Opendistrib] Contact : ' . $this->subject)
->send();
],
$this->email
);
} }


} }

+ 4
- 7
producer/controllers/SiteController.php View File

$model = new ContactForm(); $model = new ContactForm();
$producer = $this->getProducerCurrent(); $producer = $this->getProducerCurrent();


/*if ($model->load(\Yii::$app->request->post()) && $model->validate()) {
if ($model->load(\Yii::$app->request->post()) && $model->validate()) {
$isSent = false; $isSent = false;
if (is_array($producer->contact)) {
$email = $this->getProducerModule()->getMainContactEmail($producer);
if (strlen($email) && $model->sendEmail($email)) {
$isSent = true;
}
if ($producer->contact_email && strlen($producer->contact_email) > 0 && $model->sendEmail($producer)) {
$isSent = true;
} }


if ($isSent) { if ($isSent) {
} }


$model = new ContactForm(); $model = new ContactForm();
}*/
}


return $this->render('contact', [ return $this->render('contact', [
'model' => $model, 'model' => $model,

+ 2
- 3
producer/views/site/contact.php View File



?> ?>
<div class="site-contact"> <div class="site-contact">
<div class="alert alert-warning">Page en maintenance</div>
<!--<div class="row">
<div class="row">
<div class="col-lg-5"> <div class="col-lg-5">
<?php $form = ActiveForm::begin(['id' => 'contact-form', 'enableClientValidation' => false,]); ?> <?php $form = ActiveForm::begin(['id' => 'contact-form', 'enableClientValidation' => false,]); ?>
<?= $form->field($model, 'name') ?> <?= $form->field($model, 'name') ?>
</div> </div>
<?php ActiveForm::end(); ?> <?php ActiveForm::end(); ?>
</div> </div>
</div>-->
</div>
</div> </div>

Loading…
Cancel
Save