create lost password email
This commit is contained in:
@@ -27,10 +27,18 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Thelia\Core\Event\ActionEvent;
|
||||
use Thelia\Core\Event\Customer\CustomerCreateOrUpdateEvent;
|
||||
use Thelia\Core\Event\Customer\CustomerEvent;
|
||||
use Thelia\Core\Event\LostPasswordEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Core\Security\SecurityContext;
|
||||
use Thelia\Core\Template\ParserInterface;
|
||||
use Thelia\Mailer\MailerFactory;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Model\Customer as CustomerModel;
|
||||
use Thelia\Core\Event\Customer\CustomerLoginEvent;
|
||||
use Thelia\Model\CustomerQuery;
|
||||
use Thelia\Model\LangQuery;
|
||||
use Thelia\Model\MessageQuery;
|
||||
use Thelia\Tools\Password;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -44,9 +52,15 @@ class Customer extends BaseAction implements EventSubscriberInterface
|
||||
{
|
||||
protected $securityContext;
|
||||
|
||||
public function __construct(SecurityContext $securityContext)
|
||||
protected $parser;
|
||||
|
||||
protected $mailer;
|
||||
|
||||
public function __construct(SecurityContext $securityContext, ParserInterface $parser, MailerFactory $mailer)
|
||||
{
|
||||
$this->securityContext = $securityContext;
|
||||
$this->mailer = $mailer;
|
||||
$this->parser = $parser;
|
||||
}
|
||||
|
||||
public function create(CustomerCreateOrUpdateEvent $event)
|
||||
@@ -140,6 +154,60 @@ class Customer extends BaseAction implements EventSubscriberInterface
|
||||
$this->securityContext->clearCustomerUser();
|
||||
}
|
||||
|
||||
public function lostPassword(LostPasswordEvent $event)
|
||||
{
|
||||
$contact_email = ConfigQuery::read('store_email');
|
||||
|
||||
if ($contact_email) {
|
||||
if (null !== $customer = CustomerQuery::create()->filterByEmail($event->getEmail())->findOne()) {
|
||||
|
||||
$password = Password::generateRandom(8);
|
||||
|
||||
$customer
|
||||
->setPassword($password)
|
||||
->save()
|
||||
;
|
||||
|
||||
if ($customer->getLang() !== null) {
|
||||
$lang = LangQuery::create()
|
||||
->findPk($customer->getLang());
|
||||
|
||||
$locale = $lang->getLocale();
|
||||
} else {
|
||||
$lang = LangQuery::create()
|
||||
->filterByByDefault(1)
|
||||
->findOne();
|
||||
|
||||
$locale = $lang->getLocale();
|
||||
}
|
||||
|
||||
$message = MessageQuery::create()
|
||||
->filterByName('lost_password')
|
||||
->findOne();
|
||||
|
||||
$message->setLocale($locale);
|
||||
|
||||
if (false === $message) {
|
||||
throw new \Exception("Failed to load message 'order_confirmation'.");
|
||||
}
|
||||
|
||||
$this->parser->assign('password', $password);
|
||||
|
||||
$instance = \Swift_Message::newInstance()
|
||||
->addTo($customer->getEmail(), $customer->getFirstname()." ".$customer->getLastname())
|
||||
->addFrom($contact_email, ConfigQuery::read('store_name'))
|
||||
;
|
||||
|
||||
// Build subject and body
|
||||
|
||||
$message->buildMessage($this->parser, $instance);
|
||||
|
||||
$this->mailer->send($instance);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of event names this subscriber wants to listen to.
|
||||
*
|
||||
@@ -169,6 +237,7 @@ class Customer extends BaseAction implements EventSubscriberInterface
|
||||
TheliaEvents::CUSTOMER_LOGOUT => array('logout', 128),
|
||||
TheliaEvents::CUSTOMER_LOGIN => array('login', 128),
|
||||
TheliaEvents::CUSTOMER_DELETEACCOUNT => array('delete', 128),
|
||||
TheliaEvents::LOST_PASSWORD => array('lostPassword', 128)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,8 @@
|
||||
|
||||
<service id="thelia.action.customer" class="Thelia\Action\Customer" scope="request">
|
||||
<argument type="service" id="thelia.securityContext"/>
|
||||
<argument type="service" id="thelia.parser"/>
|
||||
<argument type="service" id="mailer"/>
|
||||
<tag name="kernel.event_subscriber"/>
|
||||
</service>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user