Auth.php
00001 <?php
00009 class Dsao_Controller_Action_Helper_Auth
00010 extends Zend_Controller_Action_Helper_Abstract
00011 {
00015 protected $_auth = null;
00016
00020 protected $_user = null;
00021
00027 public function init()
00028 {
00029
00030 if (null === $this->_auth)
00031 {
00032 $this->_auth = Zend_Auth::getInstance();
00033
00034
00035 if (null === $this->_auth->getIdentity())
00036 {
00037
00038 Dsao_Registry::getModel('User_Login')->cookieLogin();
00039 }
00040 }
00041
00042
00043 if ($this->_auth->hasIdentity())
00044 {
00045 $this->_user = @unserialize($this->_auth->getIdentity());
00046 }
00047 else
00048 {
00049 $this->_user = new Dsao_User();
00050 }
00051
00052
00053 if (!is_object($this->_user))
00054 {
00055 Zend_Session::destroy();
00056
00057 throw new Dsao_Exception
00058 ('dsao_controller_action_helper_auth_unserialization_error');
00059 }
00060
00061
00062 Dsao_Registry::set('user', $this->_user);
00063
00064
00065 $this->getActionController()->setUser($this->_user);
00066 }
00067
00073 public function postDispatch()
00074 {
00075
00076 if ($this->_user->getReserialize())
00077 {
00078
00079 $this->_auth->getStorage()->write(serialize($this->_user));
00080 }
00081 }
00082 }