allow to reuse creation customer method for modification. Password is

not mandatory
This commit is contained in:
Manuel Raynaud
2013-07-03 10:33:25 +02:00
parent ad8fa59e9a
commit 8b8ea994ef

View File

@@ -2,6 +2,7 @@
namespace Thelia\Model; namespace Thelia\Model;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Thelia\Core\Event\CustomRefEvent; use Thelia\Core\Event\CustomRefEvent;
use Thelia\Core\Event\TheliaEvents; use Thelia\Core\Event\TheliaEvents;
@@ -39,12 +40,12 @@ class Customer extends BaseCustomer
* @param string $zipcode customer zipcode * @param string $zipcode customer zipcode
* @param int $countryId customer country id (from Country table) * @param int $countryId customer country id (from Country table)
* @param string $email customer email, must be unique * @param string $email customer email, must be unique
* @param string $plainPassword customer plain password, hash is made calling setPassword method * @param string $plainPassword customer plain password, hash is made calling setPassword method. Not mandatory parameter but an exception is thrown if customer is new without password
* @param int $reseller * @param int $reseller
* @param null $sponsor * @param null $sponsor
* @param int $discount * @param int $discount
*/ */
public function createOrUpdate($titleId, $firstname, $lastname, $address1, $address2, $address3, $phone, $cellphone, $zipcode, $countryId, $email, $plainPassword, $reseller = 0, $sponsor = null, $discount = 0 ) public function createOrUpdate($titleId, $firstname, $lastname, $address1, $address2, $address3, $phone, $cellphone, $zipcode, $countryId, $email, $plainPassword = null, $reseller = 0, $sponsor = null, $discount = 0 )
{ {
$this $this
->setCustomerTitleId($titleId) ->setCustomerTitleId($titleId)
@@ -86,8 +87,15 @@ class Customer extends BaseCustomer
public function setPassword($password) public function setPassword($password)
{ {
$this->setAlgo("PASSWORD_BCRYPT"); if ($this->isNew() && ($password === null || trim($password) == "")) {
return parent::setPassword(password_hash($password, PASSWORD_BCRYPT)); throw new InvalidArgumentException("customer password is mandatory on creation");
}
if($password !== null && trim($password) != "") {
$this->setAlgo("PASSWORD_BCRYPT");
return parent::setPassword(password_hash($password, PASSWORD_BCRYPT));
}
} }
public function setDispatcher(EventDispatcherInterface $dispatcher) public function setDispatcher(EventDispatcherInterface $dispatcher)