summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitattributes2
-rw-r--r--framework/Web/UI/TPageStatePersister.php (renamed from framework/Web/UI/THiddenFieldPageStatePersister.php)54
2 files changed, 32 insertions, 24 deletions
diff --git a/.gitattributes b/.gitattributes
index d58b5f76..3a77e5fe 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -154,9 +154,9 @@ framework/Web/UI/TAssetManager.php -text
framework/Web/UI/TClientScriptManager.php -text
framework/Web/UI/TControl.php -text
framework/Web/UI/TForm.php -text
-framework/Web/UI/THiddenFieldPageStatePersister.php -text
framework/Web/UI/THtmlWriter.php -text
framework/Web/UI/TPage.php -text
+framework/Web/UI/TPageStatePersister.php -text
framework/Web/UI/TTemplateControl.php -text
framework/Web/UI/TTemplateManager.php -text
framework/Web/UI/TThemeManager.php -text
diff --git a/framework/Web/UI/THiddenFieldPageStatePersister.php b/framework/Web/UI/TPageStatePersister.php
index d4041983..0718c492 100644
--- a/framework/Web/UI/THiddenFieldPageStatePersister.php
+++ b/framework/Web/UI/TPageStatePersister.php
@@ -1,9 +1,9 @@
<?php
-class THiddenFieldPageStatePersister extends TComponent implements IPageStatePersister, IModule
+class TPageStatePersister extends TModule implements IPageStatePersister
{
private $_application;
- private $_id='persister';
+ private $_privateKey=null;
/**
* Initializes the service.
@@ -13,30 +13,15 @@ class THiddenFieldPageStatePersister extends TComponent implements IPageStatePer
*/
public function init($application, $config)
{
+ parent::init($application,$config);
$this->_application=$application;
$application->getService()->setPageStatePersister($this);
}
- /**
- * @return string id of this module
- */
- public function getID()
- {
- return $this->_id;
- }
-
- /**
- * @param string id of this module
- */
- public function setID($value)
- {
- $this->_id=$value;
- }
-
public function save($state)
{
$data=Prado::serialize($state);
- $hmac=$this->computeHMAC($data,$this->getKey());
+ $hmac=$this->computeHMAC($data,$this->getPrivateKey());
if(extension_loaded('zlib'))
$data=gzcompress($hmac.$data);
else
@@ -57,15 +42,38 @@ class THiddenFieldPageStatePersister extends TComponent implements IPageStatePer
{
$hmac=substr($data,0,32);
$state=substr($data,32);
- if($hmac===$this->computeHMAC($state,$this->getKey()))
+ if($hmac===$this->computeHMAC($state,$this->getPrivateKey()))
return Prado::unserialize($state);
}
- throw new Exception('viewstate data is corrupted.');
+ throw new TInvalidDataValueException('pagestatepersister_viewstate_corrupted.');
+ }
+
+ protected function generatePrivateKey()
+ {
+ $v1=rand();
+ $v2=rand();
+ $v3=rand();
+ return md5("$v1$v2$v3");
+ }
+
+ public function getPrivateKey()
+ {
+ if(empty($this->_privateKey))
+ {
+ if(($this->_privateKey=$this->_application->getGlobalState('prado:pagestatepersister:privatekey'))===null)
+ {
+ $this->_privateKey=$this->generatePrivateKey();
+ $this->_application->setGlobalState('prado:pagestatepersister:privatekey',$this->_privateKey,null);
+ }
+ }
+ return $this->_privateKey;
}
- private function getKey()
+ public function setPrivateKey($value)
{
- return 'abcdefe';
+ if(strlen($value)<8)
+ throw new TConfigurationException('pagestatepersister_privatekey_invalid');
+ $this->_privateKey=$value;
}
private function computeHMAC($data,$key)