// Context part 31

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@8087 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
tDidierjean
2011-08-17 10:07:12 +00:00
parent b8706ddd8a
commit cb3d802346
57 changed files with 200 additions and 165 deletions
+7 -1
View File
@@ -168,10 +168,12 @@ class CookieCore
/**
* Check customer informations saved into cookie and return customer validity
*
* @deprecated as of version 1.5 use Customer::isLogged() instead
* @return boolean customer validity
*/
public function isLogged($withGuest = false)
{
Tools::displayAsDeprecated();
if (!$withGuest AND $this->is_guest == 1)
return false;
@@ -184,10 +186,12 @@ class CookieCore
/**
* Check employee informations saved into cookie and return employee validity
*
* @deprecated as of version 1.5 use Employee::isLoggedBack() instead
* @return boolean employee validity
*/
public function isLoggedBack()
{
Tools::displayAsDeprecated();
/* Employee is valid only if it can be load and if cookie password is the same as database one */
return ($this->id_employee
AND Validate::isUnsignedId($this->id_employee)
@@ -198,6 +202,7 @@ class CookieCore
/**
* Delete cookie
* As of version 1.5 don't call this function, use Customer::logout() or Employee::logout() instead;
*/
public function logout()
{
@@ -210,7 +215,8 @@ class CookieCore
/**
* Soft logout, delete everything links to the customer
* but leave there affiliate's informations
* but leave there affiliate's informations.
* As of version 1.5 don't call this function, use Customer::mylogout() instead;
*/
public function mylogout()
{
+21 -1
View File
@@ -73,7 +73,7 @@ class CustomerCore extends ObjectModel
public $passwd;
/** @var datetime Password */
public $last_passwd_gen;
public $last_passwd_gen;
/** @var boolean Status */
public $active = true;
@@ -620,4 +620,24 @@ class CustomerCore extends ObjectModel
return false;
}
/**
* Logout
*/
public function logout()
{
if (isset(Context::getContext()->cookie))
Context::getContext()->cookie->logout();
$this->logged = 0;
}
/**
* Soft logout, delete everything links to the customer
* but leave there affiliate's informations
*/
public function mylogout()
{
if (isset(Context::getContext()->cookie))
Context::getContext()->cookie->mylogout();
$this->logged = 0;
}
}
+27
View File
@@ -68,6 +68,8 @@ class EmployeeCore extends ObjectModel
/** @var boolean show screencast */
public $show_screencast = 1;
public $remote_addr;
protected $fieldsRequired = array('lastname', 'firstname', 'email', 'passwd', 'id_profile', 'id_lang');
protected $fieldsSize = array('lastname' => 32, 'firstname' => 32, 'email' => 128, 'passwd' => 32, 'bo_color' => 32, 'bo_theme' => 32);
protected $fieldsValidate = array('lastname' => 'isName', 'firstname' => 'isName', 'email' => 'isEmail', 'id_lang' => 'isUnsignedInt',
@@ -209,4 +211,29 @@ class EmployeeCore extends ObjectModel
$this->passwd = Tools::encrypt($passwd);
return true;
}
/**
* Check employee informations saved into cookie and return employee validity
*
* @return boolean employee validity
*/
public function isLoggedBack()
{
/* Employee is valid only if it can be load and if cookie password is the same as database one */
return ($this->id
AND Validate::isUnsignedId($this->id)
AND Employee::checkPassword($this->id, $this->passwd)
AND (!isset($this->remote_addr) OR $this->remote_addr == ip2long(Tools::getRemoteAddr()) OR !Configuration::get('PS_COOKIE_CHECKIP'))
);
}
/**
* Logout
*/
public function logout()
{
if (isset(Context::getContext()->cookie))
Context::getContext()->cookie->logout();
$this->id = null;
}
}
+6 -6
View File
@@ -132,7 +132,7 @@ class FrontControllerCore
$link = new Link($protocol_link, $protocol_content);
$this->context->link = $link;
if ($this->auth AND !$this->context->cookie->isLogged($this->guestAllowed))
if ($this->auth AND !$this->context->customer->isLogged($this->guestAllowed))
Tools::redirect('index.php?controller=authentication'.($this->authRedirection ? '&back='.$this->authRedirection : ''));
/* Theme is missing or maintenance */
@@ -144,14 +144,14 @@ class FrontControllerCore
if (($newDefault = $this->geolocationManagement($this->context->country)) && Validate::isLoadedObject($newDefault))
$this->context->country = $newDefault;
if (isset($_GET['logout']) OR ($this->context->cookie->logged AND Customer::isBanned((int)$this->context->cookie->id_customer)))
if (isset($_GET['logout']) OR ($this->context->customer->logged AND Customer::isBanned($this->context->customer->id)))
{
$this->context->cookie->logout();
$this->context->customer->logout();
Tools::redirect(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : NULL);
}
elseif (isset($_GET['mylogout']))
{
$this->context->cookie->mylogout();
$this->context->customer->mylogout();
Tools::redirect(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : NULL);
}
@@ -290,8 +290,8 @@ class FrontControllerCore
// Deprecated
$this->context->smarty->assign(array(
'id_currency_cookie' => (int)$currency->id,
'logged' => $this->context->cookie->isLogged(),
'customerName' => ($this->context->cookie->logged ? $this->context->cookie->customer_firstname.' '.$this->context->cookie->customer_lastname : false)
'logged' => $this->context->customer->isLogged(),
'customerName' => ($this->context->customer->logged ? $this->context->cookie->customer_firstname.' '.$this->context->cookie->customer_lastname : false)
));
// TODO for better performances (cache usage), remove these assign and use a smarty function to get the right media server in relation to the full ressource name
+3 -1
View File
@@ -284,8 +284,10 @@ class ToolsCore
*
* @return string iso code
*/
public static function setCookieLanguage($cookie)
public static function setCookieLanguage($cookie = null)
{
if (!$cookie)
$cookie = Context::getContext()->cookie;
/* If language does not exist or is disabled, erase it */
if ($cookie->id_lang)
{