Public Member Functions | |
__construct () | |
login ($username, $password, $request=null) | |
refreshAcl ($user=null) | |
isAllowed ($resource, $privilege=null) | |
isLoggedIn () | |
isFirstPageAfterLogin () | |
Protected Member Functions | |
_getRequestUri ($request=null) | |
Protected Attributes | |
$_isFirstPageAfterLogin |
Definition at line 35 of file Session.php.
__construct | ( | ) |
Class constructor
Reimplemented from Varien_Object.
Definition at line 49 of file Session.php.
00050 { 00051 $this->init('admin'); 00052 }
_getRequestUri | ( | $ | request = null |
) | [protected] |
Custom REQUEST_URI logic
Mage_Core_Controller_Request_Http | $request |
Definition at line 188 of file Session.php.
00189 { 00190 if (Mage::getSingleton('adminhtml/url')->useSecretKey()) { 00191 return Mage::getSingleton('adminhtml/url')->getUrl('*/*/*', array('_current' => true)); 00192 } elseif ($request) { 00193 return $request->getRequestUri(); 00194 } else { 00195 return null; 00196 } 00197 }
isAllowed | ( | $ | resource, | |
$ | privilege = null | |||
) |
Check current user permission on resource and privilege
Mage.getSingleton('admin/session')->isAllowed('admin/catalog') Mage.getSingleton('admin/session')->isAllowed('catalog')
string | $resource | |
string | $privilege |
Definition at line 136 of file Session.php.
00137 { 00138 $user = $this->getUser(); 00139 $acl = $this->getAcl(); 00140 00141 if ($user && $acl) { 00142 if (!preg_match('/^admin/', $resource)) { 00143 $resource = 'admin/'.$resource; 00144 } 00145 00146 try { 00147 return $acl->isAllowed($user->getAclRole(), $resource, $privilege); 00148 } catch (Exception $e) { 00149 try { 00150 if (!$acl->has($resource)) { 00151 return $acl->isAllowed($user->getAclRole(), null, $privilege); 00152 } 00153 } catch (Exception $e) { } 00154 } 00155 } 00156 return false; 00157 }
isFirstPageAfterLogin | ( | ) |
Check if it is the first page after successfull login
Definition at line 174 of file Session.php.
00175 { 00176 if (is_null($this->_isFirstPageAfterLogin)) { 00177 $this->_isFirstPageAfterLogin = $this->getData('is_first_visit', true); 00178 } 00179 return $this->_isFirstPageAfterLogin; 00180 }
isLoggedIn | ( | ) |
login | ( | $ | username, | |
$ | password, | |||
$ | request = null | |||
) |
Try to login user in admin
string | $username | |
string | $password | |
Mage_Core_Controller_Request_Http | $request |
Definition at line 62 of file Session.php.
00063 { 00064 if (empty($username) || empty($password)) { 00065 return; 00066 } 00067 00068 try { 00069 /* @var $user Mage_Admin_Model_User */ 00070 $user = Mage::getModel('admin/user'); 00071 $user->login($username, $password); 00072 if ($user->getId()) { 00073 00074 if (Mage::getSingleton('adminhtml/url')->useSecretKey()) { 00075 Mage::getSingleton('adminhtml/url')->renewSecretUrls(); 00076 } 00077 $session = Mage::getSingleton('admin/session'); 00078 $session->setIsFirstVisit(true); 00079 $session->setUser($user); 00080 $session->setAcl(Mage::getResourceModel('admin/acl')->loadAcl()); 00081 if ($requestUri = $this->_getRequestUri($request)) { 00082 Mage::dispatchEvent('admin_session_user_login_success', array('user'=>$user)); 00083 header('Location: ' . $requestUri); 00084 exit; 00085 } 00086 } 00087 else { 00088 Mage::throwException(Mage::helper('adminhtml')->__('Invalid Username or Password.')); 00089 } 00090 } 00091 catch (Mage_Core_Exception $e) { 00092 Mage::dispatchEvent('admin_session_user_login_failed', array('user_name'=>$username, 'exception' => $e)); 00093 if ($request && !$request->getParam('messageSent')) { 00094 Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); 00095 $request->setParam('messageSent', true); 00096 } 00097 } 00098 00099 return $user; 00100 }
refreshAcl | ( | $ | user = null |
) |
Refresh ACL resources stored in session
Mage_Admin_Model_User | $user |
Definition at line 108 of file Session.php.
00109 { 00110 if (is_null($user)) { 00111 $user = $this->getUser(); 00112 } 00113 if (!$user) { 00114 return $this; 00115 } 00116 if (!$this->getAcl() || $user->getReloadAclFlag()) { 00117 $this->setAcl(Mage::getResourceModel('admin/acl')->loadAcl()); 00118 } 00119 if ($user->getReloadAclFlag()) { 00120 $user->unsetData('password'); 00121 $user->setReloadAclFlag('0')->save(); 00122 } 00123 return $this; 00124 }
$_isFirstPageAfterLogin [protected] |
Definition at line 43 of file Session.php.