finishing creating lost password template

This commit is contained in:
Manuel Raynaud
2013-09-11 17:22:23 +02:00
parent ccf35dd37c
commit 9cc3162696
5 changed files with 64 additions and 8 deletions

View File

@@ -41,6 +41,7 @@
<forms>
<form name="thelia.customer.creation" class="Thelia\Form\CustomerCreation"/>
<form name="thelia.customer.modification" class="Thelia\Form\CustomerModification"/>
<form name="thelia.customer.lostpassword" class="Thelia\Form\CustomerLostPasswordForm"/>
<form name="thelia.customer.login" class="Thelia\Form\CustomerLogin"/>
<form name="thelia.admin.login" class="Thelia\Form\AdminLogin"/>

View File

@@ -38,11 +38,16 @@
<default key="_controller">Thelia\Controller\Front\CustomerController::logoutAction</default>
</route>
<route id="customer.password.retrieve.view" path="/password">
<route id="customer.password.retrieve.view" path="/password" methods="get">
<default key="_controller">Thelia\Controller\Front\DefaultController::noAction</default>
<default key="_view">password</default>
</route>
<route id="customer.password.retrieve.process" path="/password" methods="post">
<default key="_controller">Thelia\Controller\Front\CustomerController::newPasswordAction</default>
<default key="_view">password</default>
</route>
<!-- end customer routes -->
<!-- customer address routes -->

View File

@@ -24,11 +24,13 @@ namespace Thelia\Controller\Front;
use Thelia\Core\Event\CustomerCreateOrUpdateEvent;
use Thelia\Core\Event\CustomerLoginEvent;
use Thelia\Core\Event\LostPasswordEvent;
use Thelia\Core\Security\Authentication\CustomerUsernamePasswordFormAuthenticator;
use Thelia\Core\Security\Exception\AuthenticationException;
use Thelia\Core\Security\Exception\UsernameNotFoundException;
use Thelia\Form\CustomerCreation;
use Thelia\Form\CustomerLogin;
use Thelia\Form\CustomerLostPasswordForm;
use Thelia\Form\CustomerModification;
use Thelia\Form\Exception\FormValidationException;
use Thelia\Model\Customer;
@@ -45,6 +47,41 @@ use Thelia\Core\Security\Exception\WrongPasswordException;
class CustomerController extends BaseFrontController
{
use \Thelia\Cart\CartTrait;
public function newPasswordAction()
{
if (! $this->getSecurityContext()->hasCustomerUser()) {
$message = false;
$passwordLost = new CustomerLostPasswordForm($this->getRequest());
try {
$form = $this->validateForm($passwordLost);
$event = new LostPasswordEvent($form->get("email")->getData());
$this->dispatch(TheliaEvents::LOST_PASSWORD, $event);
} catch (FormValidationException $e) {
$message = sprintf("Please check your input: %s", $e->getMessage());
} catch (\Exception $e) {
$message = sprintf("Sorry, an error occured: %s", $e->getMessage());
}
if ($message !== false) {
Tlog::getInstance()->error(sprintf("Error during customer creation process : %s. Exception was %s", $message, $e->getMessage()));
$passwordLost->setErrorMessage($message);
$this->getParserContext()
->addForm($passwordLost)
->setGeneralError($message)
;
}
}
}
/**
* Create a new customer.
* On success, redirect to success_url if exists, otherwise, display the same view again.

View File

@@ -71,6 +71,10 @@ final class TheliaEvents
*/
const CUSTOMER_UPDATEACCOUNT = "action.updateCustomer";
/**
* sent when a customer need a new password
*/
const LOST_PASSWORD = "action.lostPassword";
/**
* Sent before the logout of the administrator.
*/

View File

@@ -14,20 +14,29 @@
<div class="main">
<article class="col-main" role="main" aria-labelledby="main-label">
<h1 id="main-label" class="page-header">{intl l="Password Forgotten"}</h1>
{form name="thelia.customer.lostpassword"}
<form id="form-forgotpassword" action="{url path="/password"}" method="post" role="form">
<form id="form-forgotpassword" action="" method="post" role="form">
<p>{intl l="Please enter your email address below. You will receive a link to reset your password."}</p>
<div class="form-group">
<label for="forgot-email">Please enter your email address</label>
<input type="email" name="forgot-email" id="forgot-email" class="form-control" aria-required="true" autofocus aria-required="true" required value="">
<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}">
<label for="{$label_attr.for}">{$label}</label>
<div class="control-input">
<input type="email" name="{$name}" value="{$value}" id="{$label_attr.for}" class="form-control" aria-required="true" autofocus required>
{if $error}
<span class="help-block"><span class="icon-remove"></span> {$message}</span>
{elseif !$error && $value != ""}
<span class="help-block"><span class="icon-ok"></span> {intl l="You will receive a link to reset your password."}</span>
{/if}
</div>
</div>
{/form_field}
<div class="group-btn">
<a href="{url path="/"}" class="btn btn-cancel">{intl l="Cancel"}</a>
<button type="submit" class="btn btn-forgot">{intl l="Send"}</button>
</div>
</form>
{/form}
</article>
</div>
{/block}