Mage_Api_Model_Session Class Reference

Inheritance diagram for Mage_Api_Model_Session:

Mage_Core_Model_Session_Abstract Mage_Core_Model_Session_Abstract_Varien Varien_Object

List of all members.

Public Member Functions

 start ($sessionName=null)
 init ($namespace, $sessionName=null)
 getSessionId ()
 setSessionId ($sessId=null)
 revalidateCookie ()
 clear ()
 login ($username, $apiKey)
 refreshAcl ($user=null)
 isAllowed ($resource, $privilege=null)
 isSessionExpired ($user)
 isLoggedIn ($sessId=false)

Public Attributes

 $sessionIds = array()

Protected Member Functions

 _renewBySessId ($sessId)

Protected Attributes

 $_currentSessId = null


Detailed Description

Definition at line 34 of file Session.php.


Member Function Documentation

_renewBySessId ( sessId  )  [protected]

Renew user by session ID if session not expired

Parameters:
string $sessId
Returns:
boolean

Definition at line 192 of file Session.php.

00193     {
00194         $user = Mage::getModel('api/user')->loadBySessId($sessId);
00195         if (!$user->getId() || !$user->getSessid()) {
00196             return false;
00197         }
00198 
00199         if ($user->getSessid() == $sessId && !$this->isSessionExpired($user)) {
00200             $this->setUser($user);
00201             $this->setAcl(Mage::getResourceModel('api/acl')->loadAcl());
00202 
00203             $user->getResource()->recordLogin($user)
00204                 ->recordSession($user);
00205 
00206             return true;
00207         }
00208         return false;
00209     }

clear (  ) 

Alias for unsetAll

Returns:
Mage_Core_Model_Session_Abstract_Varien

Reimplemented from Mage_Core_Model_Session_Abstract_Varien.

Definition at line 73 of file Session.php.

00073                             {
00074         if ($sessId = $this->getSessionId()) {
00075             try {
00076                 Mage::getModel('api/user')->logoutBySessId($sessId);
00077             } catch (Exception $e) {
00078                 return false;
00079             }
00080         }
00081         return true;
00082     }

getSessionId (  ) 

Retrieve session Id

Returns:
string

Reimplemented from Mage_Core_Model_Session_Abstract_Varien.

Definition at line 55 of file Session.php.

00056     {
00057         return $this->_currentSessId;
00058     }

init ( namespace,
sessionName = null 
)

Init session

Parameters:
string $namespace
string $sessionName
Returns:
Mage_Core_Model_Session_Abstract

Reimplemented from Mage_Core_Model_Session_Abstract.

Definition at line 47 of file Session.php.

00048     {
00049         if (is_null($this->_currentSessId)) {
00050             $this->start();
00051         }
00052         return $this;
00053     }

isAllowed ( resource,
privilege = null 
)

Check current user permission on resource and privilege

Parameters:
string $resource
string $privilege
Returns:
bool

Definition at line 136 of file Session.php.

00137     {
00138         $user = $this->getUser();
00139         $acl = $this->getAcl();
00140 
00141         if ($user && $acl) {
00142             try {
00143                 if ($acl->isAllowed($user->getAclRole(), 'all', null)){
00144                     return true;
00145                 }
00146             } catch (Exception $e) {}
00147 
00148             try {
00149                 return $acl->isAllowed($user->getAclRole(), $resource, $privilege);
00150             } catch (Exception $e) {
00151                 return false;
00152             }
00153         }
00154         return false;
00155     }

isLoggedIn ( sessId = false  ) 

Definition at line 172 of file Session.php.

00173     {
00174         $userExists = $this->getUser() && $this->getUser()->getId();
00175 
00176         if (!$userExists && $sessId !== false) {
00177             return $this->_renewBySessId($sessId);
00178         }
00179 
00180         if ($userExists) {
00181             Mage::register('isSecureArea', true, true);
00182         }
00183         return $userExists;
00184     }

isSessionExpired ( user  ) 

Check session expiration

Returns:
boolean

Definition at line 162 of file Session.php.

00163     {
00164         if (!$user->getId()) {
00165             return true;
00166         }
00167         $timeout = strtotime( now() ) - strtotime( $user->getLogdate() );
00168         return $timeout > Mage::getStoreConfig('api/config/session_timeout');
00169     }

login ( username,
apiKey 
)

Definition at line 84 of file Session.php.

00085     {
00086         if (empty($username) || empty($apiKey)) {
00087             return;
00088         }
00089 
00090         $user = Mage::getModel('api/user')
00091             ->setSessid($this->getSessionId())
00092             ->login($username, $apiKey);
00093 
00094         if ( $user->getId() && $user->getIsActive() != '1' ) {
00095             Mage::throwException(Mage::helper('api')->__('Your Account has been deactivated.'));
00096         } elseif (!Mage::getModel('api/user')->hasAssigned2Role($user->getId())) {
00097             Mage::throwException(Mage::helper('api')->__('Access Denied.'));
00098         } else {
00099             if ($user->getId()) {
00100                 $this->setUser($user);
00101                 $this->setAcl(Mage::getResourceModel('api/acl')->loadAcl());
00102             } else {
00103                 Mage::throwException(Mage::helper('api')->__('Unable to login.'));
00104             }
00105         }
00106 
00107         return $user;
00108     }

refreshAcl ( user = null  ) 

Definition at line 110 of file Session.php.

00111     {
00112         if (is_null($user)) {
00113             $user = $this->getUser();
00114         }
00115         if (!$user) {
00116             return $this;
00117         }
00118         if (!$this->getAcl() || $user->getReloadAclFlag()) {
00119             $this->setAcl(Mage::getResourceModel('api/acl')->loadAcl());
00120         }
00121         if ($user->getReloadAclFlag()) {
00122             $user->unsetData('api_key');
00123             $user->setReloadAclFlag('0')->save();
00124         }
00125         return $this;
00126     }

revalidateCookie (  ) 

Revalidate cookie

Returns:
Mage_Core_Model_Session_Abstract_Varien

Reimplemented from Mage_Core_Model_Session_Abstract_Varien.

Definition at line 68 of file Session.php.

00069     {
00070         // In api we don't use cookies
00071     }

setSessionId ( id = null  ) 

Specify session identifier

Parameters:
string|null $id
Returns:
Mage_Core_Model_Session_Abstract

No reason use crypt key for session

Reimplemented from Mage_Core_Model_Session_Abstract.

Definition at line 60 of file Session.php.

00061     {
00062         if (!is_null($sessId)) {
00063             $this->_currentSessId = $sessId;
00064         }
00065         return $this;
00066     }

start ( sessionName = null  ) 

Conigure and start session

Parameters:
string $sessionName
Returns:
Mage_Core_Model_Session_Abstract_Varien

Reimplemented from Mage_Core_Model_Session_Abstract_Varien.

Definition at line 39 of file Session.php.

00040     {
00041 //        parent::start($sessionName=null);
00042         $this->_currentSessId = md5(time() . $sessionName);
00043         $this->sessionIds[] = $this->getSessionId();
00044         return $this;
00045     }


Member Data Documentation

$_currentSessId = null [protected]

Definition at line 37 of file Session.php.

$sessionIds = array()

Definition at line 36 of file Session.php.


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:23:33 2009 for Magento by  doxygen 1.5.8