//IdentityController : Refacto done

This commit is contained in:
mDeflotte
2011-09-29 13:48:39 +00:00
parent 7cd1100bb7
commit 5b2db9603b
+41 -25
View File
@@ -32,51 +32,59 @@ class IdentityControllerCore extends FrontController
public $authRedirection = 'identity'; public $authRedirection = 'identity';
public $ssl = true; public $ssl = true;
public function process() public function init()
{ {
$customer = $this->context->customer; parent::init();
$this->customer = $this->context->customer;
}
if (sizeof($_POST)) /**
* Start forms process
* @see FrontController::postProcess()
*/
public function postProcess()
{
if (count($_POST))
{ {
$exclusion = array('secure_key', 'old_passwd', 'passwd', 'active', 'date_add', 'date_upd', 'last_passwd_gen', 'newsletter_date_add', 'id_default_group'); $exclusion = array('secure_key', 'old_passwd', 'passwd', 'active', 'date_add', 'date_upd', 'last_passwd_gen', 'newsletter_date_add', 'id_default_group');
$fields = $customer->getFields(); $fields = $this->customer->getFields();
foreach ($fields AS $key => $value) foreach ($fields as $key => $value)
if (!in_array($key, $exclusion)) if (!in_array($key, $exclusion))
$customer->{$key} = key_exists($key, $_POST) ? trim($_POST[$key]) : 0; $this->customer->{$key} = key_exists($key, $_POST) ? trim($_POST[$key]) : 0;
} }
if (isset($_POST['years']) AND isset($_POST['months']) AND isset($_POST['days'])) if (isset($_POST['years']) && isset($_POST['months']) && isset($_POST['days']))
$customer->birthday = (int)($_POST['years']).'-'.(int)($_POST['months']).'-'.(int)($_POST['days']); $this->customer->birthday = (int)($_POST['years']).'-'.(int)($_POST['months']).'-'.(int)($_POST['days']);
if (Tools::isSubmit('submitIdentity')) if (Tools::isSubmit('submitIdentity'))
{ {
if (!@checkdate(Tools::getValue('months'), Tools::getValue('days'), Tools::getValue('years')) AND if (!@checkdate(Tools::getValue('months'), Tools::getValue('days'), Tools::getValue('years')) &&
!(Tools::getValue('months') == '' AND Tools::getValue('days') == '' AND Tools::getValue('years') == '')) !(Tools::getValue('months') == '' && Tools::getValue('days') == '' && Tools::getValue('years') == ''))
$this->errors[] = Tools::displayError('Invalid date of birth'); $this->errors[] = Tools::displayError('Invalid date of birth');
else else
{ {
$customer->birthday = (empty($_POST['years']) ? '' : (int)($_POST['years']).'-'.(int)($_POST['months']).'-'.(int)($_POST['days'])); $this->customer->birthday = (empty($_POST['years']) ? '' : (int)($_POST['years']).'-'.(int)($_POST['months']).'-'.(int)($_POST['days']));
$_POST['old_passwd'] = trim($_POST['old_passwd']); $_POST['old_passwd'] = trim($_POST['old_passwd']);
if (empty($_POST['old_passwd']) OR (Tools::encrypt($_POST['old_passwd']) != $this->context->cookie->passwd)) if (empty($_POST['old_passwd']) || (Tools::encrypt($_POST['old_passwd']) != $this->context->cookie->passwd))
$this->errors[] = Tools::displayError('Your password is incorrect.'); $this->errors[] = Tools::displayError('Your password is incorrect.');
elseif ($_POST['passwd'] != $_POST['confirmation']) else if ($_POST['passwd'] != $_POST['confirmation'])
$this->errors[] = Tools::displayError('Password and confirmation do not match'); $this->errors[] = Tools::displayError('Password and confirmation do not match');
else else
{ {
$prev_id_default_group = $customer->id_default_group; $prev_id_default_group = $this->customer->id_default_group;
$this->errors = $customer->validateController(); $this->errors = $this->customer->validateController();
} }
if (!sizeof($this->errors)) if (!count($this->errors))
{ {
$customer->id_default_group = (int)($prev_id_default_group); $this->customer->id_default_group = (int)($prev_id_default_group);
$customer->firstname = Tools::ucfirst(Tools::strtolower($customer->firstname)); $this->customer->firstname = Tools::ucfirst(Tools::strtolower($this->customer->firstname));
if (Tools::getValue('passwd')) if (Tools::getValue('passwd'))
$this->context->cookie->passwd = $customer->passwd; $this->context->cookie->passwd = $this->customer->passwd;
if ($customer->update()) if ($this->customer->update())
{ {
$this->context->cookie->customer_lastname = $customer->lastname; $this->context->cookie->customer_lastname = $this->customer->lastname;
$this->context->cookie->customer_firstname = $customer->firstname; $this->context->cookie->customer_firstname = $this->customer->firstname;
$this->context->smarty->assign('confirmation', 1); $this->context->smarty->assign('confirmation', 1);
} }
else else
@@ -85,10 +93,18 @@ class IdentityControllerCore extends FrontController
} }
} }
else else
$_POST = array_map('stripslashes', $customer->getFields()); $_POST = array_map('stripslashes', $this->customer->getFields());
if ($customer->birthday) return $this->customer;
$birthday = explode('-', $customer->birthday); }
/**
* Assign template vars related to page content
* @see FrontController::process()
*/
public function process()
{
if ($this->customer->birthday)
$birthday = explode('-', $this->customer->birthday);
else else
$birthday = array('-', '-', '-'); $birthday = array('-', '-', '-');