allow to create a customer in bakcoffice

This commit is contained in:
Manuel Raynaud
2013-10-28 16:55:07 +01:00
parent 1e65ad8cf3
commit 7a2469cdc8
5 changed files with 124 additions and 1 deletions

View File

@@ -114,6 +114,10 @@
<default key="_controller">Thelia\Controller\Admin\CustomerController::deleteAction</default>
</route>
<route id="admin.customer.create" path="/admin/customer/create">
<default key="_controller">Thelia\Controller\Admin\CustomerController::createAction</default>
</route>
<!-- end Customer rule management -->
<!-- address management -->

View File

@@ -29,10 +29,12 @@ use Thelia\Core\Event\Customer\CustomerCreateOrUpdateEvent;
use Thelia\Core\Event\Customer\CustomerEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Core\Security\AccessManager;
use Thelia\Form\CustomerCreateForm;
use Thelia\Form\CustomerUpdateForm;
use Thelia\Form\Exception\FormValidationException;
use Thelia\Model\CustomerQuery;
use Thelia\Core\Translation\Translator;
use Thelia\Tools\Password;
/**
* Class CustomerController
@@ -102,7 +104,7 @@ class CustomerController extends BaseAdminController
}
if ($message !== false) {
\Thelia\Log\Tlog::getInstance()->error(sprintf("Error during customer login process : %s.", $message));
\Thelia\Log\Tlog::getInstance()->error(sprintf("Error during customer update process : %s.", $message));
$customerUpdateForm->setErrorMessage($message);
@@ -117,6 +119,56 @@ class CustomerController extends BaseAdminController
));
}
public function createAction()
{
if (null !== $response = $this->checkAuth(AdminResources::CUSTOMER, AccessManager::CREATE)) return $response;
$message = null;
$customerCreateForm = new CustomerCreateForm($this->getRequest());
try {
$form = $this->validateForm($customerCreateForm);
$data = $form->getData();
$data["password"] = Password::generateRandom();
$event = $this->createEventInstance($form->getData());
$this->dispatch(TheliaEvents::CUSTOMER_CREATEACCOUNT, $event);
$successUrl = $customerCreateForm->getSuccessUrl();
$successUrl = str_replace('_ID_', $event->getCustomer()->getId(), $successUrl);
$this->redirect($successUrl);
}catch (FormValidationException $e) {
$message = sprintf("Please check your input: %s", $e->getMessage());
} catch (PropelException $e) {
$message = $e->getMessage();
} catch (\Exception $e) {
$message = sprintf("Sorry, an error occured: %s", $e->getMessage()." ".$e->getFile());
}
if ($message !== false) {
\Thelia\Log\Tlog::getInstance()->error(sprintf("Error during customer creation process : %s.", $message));
$customerCreateForm->setErrorMessage($message);
$this->getParserContext()
->addForm($customerCreateForm)
->setGeneralError($message)
;
}
return $this->render("customers", array("display_customer" => 20));
}
public function deleteAction()
{
if (null !== $response = $this->checkAuth(AdminResources::CUSTOMER, AccessManager::DELETE)) return $response;

View File

@@ -79,6 +79,7 @@ class Customer extends BaseCustomer implements UserInterface
$address = new Address();
$address
->setLabel("default")
->setCompany($company)
->setTitleId($titleId)
->setFirstname($firstname)

View File

@@ -0,0 +1,54 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Tools;
/**
* Class Password
* @package Thelia\Tools
* @author Manuel Raynaud <mraynaud@openstudio.fr>
*/
class Password
{
private static function randgen($letter, $length) {
return substr(str_shuffle($letter), 0, $length);
}
/**
* generate a Random password with defined length
*
* @param int $length
* @return mixed
*/
public static function generateRandom($length = 8){
$letter = "abcdefghijklmnopqrstuvwxyz";
$letter .= "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$letter .= "0123456789";
return self::randgen($letter, $length);
}
}

View File

@@ -166,6 +166,18 @@
<input type="hidden" name="{$name}" value="{url path='/admin/customer/update/_ID_'}" />
{/form_field}
{form_field form=$form field="password"}
<input type="hidden" name="{$name}" value="random" />
{/form_field}
{form_field form=$form field="password_confirm"}
<input type="hidden" name="{$name}" value="random" />
{/form_field}
{form_field form=$form field="agreed"}
<input type="hidden" name="{$name}" value="on" />
{/form_field}
{form_field form=$form field='company'}
<div class="form-group {if $error}has-error{/if}">
<label for="{$label_attr.for}" class="control-label">{intl l="{$label}"} : </label>