Files
PrestaShop/controllers/front/IdentityController.php
2012-01-02 10:09:36 +00:00

128 lines
4.2 KiB
PHP

<?php
/*
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision: 6844 $
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class IdentityControllerCore extends FrontController
{
public $auth = true;
public $php_self = 'identity';
public $authRedirection = 'identity';
public $ssl = true;
public function init()
{
parent::init();
$this->customer = $this->context->customer;
}
/**
* Start forms process
* @see FrontController::postProcess()
*/
public function postProcess()
{
if (isset($_POST['years']) && isset($_POST['months']) && isset($_POST['days']))
$this->customer->birthday = (int)($_POST['years']).'-'.(int)($_POST['months']).'-'.(int)($_POST['days']);
if (Tools::isSubmit('submitIdentity'))
{
if (!@checkdate(Tools::getValue('months'), Tools::getValue('days'), Tools::getValue('years')) &&
!(Tools::getValue('months') == '' && Tools::getValue('days') == '' && Tools::getValue('years') == ''))
$this->errors[] = Tools::displayError('Invalid date of birth');
else
{
$this->customer->birthday = (empty($_POST['years']) ? '' : (int)($_POST['years']).'-'.(int)($_POST['months']).'-'.(int)($_POST['days']));
$_POST['old_passwd'] = trim($_POST['old_passwd']);
if (empty($_POST['old_passwd']) || (Tools::encrypt($_POST['old_passwd']) != $this->context->cookie->passwd))
$this->errors[] = Tools::displayError('Your password is incorrect.');
else if ($_POST['passwd'] != $_POST['confirmation'])
$this->errors[] = Tools::displayError('Password and confirmation do not match');
else
{
$prev_id_default_group = $this->customer->id_default_group;
$this->errors = $this->customer->validateController();
}
if (!count($this->errors))
{
$this->customer->id_default_group = (int)($prev_id_default_group);
$this->customer->firstname = Tools::ucfirst(Tools::strtolower($this->customer->firstname));
if (Tools::getValue('passwd'))
$this->context->cookie->passwd = $this->customer->passwd;
if ($this->customer->update())
{
$this->context->cookie->customer_lastname = $this->customer->lastname;
$this->context->cookie->customer_firstname = $this->customer->firstname;
$this->context->smarty->assign('confirmation', 1);
}
else
$this->errors[] = Tools::displayError('Cannot update information');
}
}
}
else
$_POST = array_map('stripslashes', $this->customer->getFields());
return $this->customer;
}
/**
* Assign template vars related to page content
* @see FrontController::initContent()
*/
public function initContent()
{
if ($this->customer->birthday)
$birthday = explode('-', $this->customer->birthday);
else
$birthday = array('-', '-', '-');
/* Generate years, months and days */
$this->context->smarty->assign(array(
'years' => Tools::dateYears(),
'sl_year' => $birthday[0],
'months' => Tools::dateMonths(),
'sl_month' => $birthday[1],
'days' => Tools::dateDays(),
'sl_day' => $birthday[2],
'errors' => $this->errors,
'genders' => Gender::getGenders(),
));
$this->context->smarty->assign('newsletter', (int)Module::getInstanceByName('blocknewsletter')->active);
$this->setTemplate(_PS_THEME_DIR_.'identity.tpl');
parent::initContent();
}
public function setMedia()
{
parent::setMedia();
$this->addCSS(_THEME_CSS_DIR_.'identity.css');
}
}