create lost password email

This commit is contained in:
Manuel Raynaud
2014-02-11 16:13:30 +01:00
parent 5983e4447f
commit 3244e88585
5 changed files with 97 additions and 4 deletions

View File

@@ -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)
);
}
}

View File

@@ -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>

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,19 @@
# This is a fix for InnoDB in MySQL >= 4.1.x
# It "suspends judgement" for fkey relationships until are tables are set.
SET FOREIGN_KEY_CHECKS = 0;
ALTER TABLE `product` CHANGE `position` `position` INT( 11 ) NOT NULL DEFAULT '0';
ALTER TABLE `product_version` CHANGE `position` `position` INT( 11 ) NOT NULL DEFAULT '0';
SELECT @max := MAX(`id`) FROM `message`;
SET @max := @max+1;
INSERT INTO `message` (`id`, `name`, `secured`, `created_at`, `updated_at`, `version`, `version_created_at`, `version_created_by`) VALUES
(@max, 'lost_password', 1, NOW(), NOW(), 2, NOW(), NULL);
INSERT INTO `message_i18n` (`id`, `locale`, `title`, `subject`, `text_message`, `html_message`) VALUES
(@max, 'en_US', 'Your new password', 'Your new password', 'Your new passord is : {$password}', '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\r\n<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="fr">\r\n<head>\r\n<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />\r\n<title>changing password email for {config key="urlsite"} </title>\r\n{literal}\r\n<style type="text/css">\r\nbody {font-family: Arial, Helvetica, sans-serif;font-size:100%;text-align:center;}\r\n#liencompte {margin:25px 0 ;text-align: middle;font-size:10pt;}\r\n#wrapper {width:480pt;margin:0 auto;}\r\n#entete {padding-bottom:20px;margin-bottom:10px;border-bottom:1px dotted #000;}\r\n#logotexte {float:left;width:180pt;height:75pt;border:1pt solid #000;font-size:18pt;text-align:center;}\r\n#logoimg{float:left;}\r\n#h2 {margin:0;padding:0;font-size:140%;text-align:center;}\r\n#h3 {margin:0;padding:0;font-size:120%;text-align:center;}\r\n</style>\r\n{/literal}\r\n</head>\r\n<body>\r\n<div id="wrapper">\r\n<div id="entete">\r\n<h1 id="logotexte">{config key="store_name"}</h1>\r\n<h2 id="info">Changement de mot de passe</h2>\r\n<h5 id="mdp"> You have lost your password <br />\r\nYour new password is <span style="font-size:80%">{$password}</span>.</h5>\r\n</div>\r\n</div>\r\n<p id="liencompte">Vous pouvez &agrave; pr&eacute;sent vous connecter sur <a href="{config key="urlsite"}">{config key="urlsite"}</a>.<br /> Please, change this password after your first connection</p>\r\n</body>\r\n</html>'),
(@max, 'fr_FR', 'Votre nouveau mot de passe', 'Votre nouveau mot de passe', 'Votre nouveau mot de passe est : {$password}', '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\r\n<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="fr">\r\n<head>\r\n<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />\r\n<title>courriel de confirmation de changement de mot de passe de {config key="urlsite"} </title>\r\n{literal}\r\n<style type="text/css">\r\nbody {font-family: Arial, Helvetica, sans-serif;font-size:100%;text-align:center;}\r\n#liencompte {margin:25px 0 ;text-align: middle;font-size:10pt;}\r\n#wrapper {width:480pt;margin:0 auto;}\r\n#entete {padding-bottom:20px;margin-bottom:10px;border-bottom:1px dotted #000;}\r\n#logotexte {float:left;width:180pt;height:75pt;border:1pt solid #000;font-size:18pt;text-align:center;}\r\n#logoimg{float:left;}\r\n#h2 {margin:0;padding:0;font-size:140%;text-align:center;}\r\n#h3 {margin:0;padding:0;font-size:120%;text-align:center;}\r\n</style>\r\n{/literal}\r\n</head>\r\n<body>\r\n<div id="wrapper">\r\n<div id="entete">\r\n<h1 id="logotexte">{config key="store_name"}</h1>\r\n<h2 id="info">Changement de mot de passe</h2>\r\n<h5 id="mdp"> Vous avez perdu votre mot de passe. <br />\r\nVotre nouveau mot de passe est <span style="font-size:80%">{$password}</span>.</h5>\r\n</div>\r\n</div>\r\n<p id="liencompte">Vous pouvez &agrave; pr&eacute;sent vous connecter sur <a href="{config key="urlsite"}">{config key="urlsite"}</a>.<br /> N''oubliez pas de modifier votre mot de passe.</p>\r\n</body>\r\n</html>');
SET FOREIGN_KEY_CHECKS = 1;

View File

@@ -17,7 +17,7 @@
<h1 id="main-label" class="page-header">{intl l="Password Forgotten"}</h1>
{form name="thelia.front.customer.lostpassword"}
<form id="form-forgotpassword" action="{url path="/password"}" method="post">
{form_hidden_fields form=$form}
<p>{intl l="Please enter your email address below."} {intl l="You will receive a link to reset your password."}</p>
{form_field form=$form field="email"}
<div class="form-group group-email {if $error}has-error{elseif !$error && $value != ""}has-success{/if}">