Mage_Admin_Model_User Class Reference

Inheritance diagram for Mage_Admin_Model_User:

Mage_Core_Model_Abstract Varien_Object

List of all members.

Public Member Functions

 save ()
 saveExtra ($data)
 delete ()
 saveRelations ()
 getRoles ()
 getRole ()
 deleteFromRole ()
 roleUserExists ()
 add ()
 userExists ()
 getCollection ()
 sendNewPasswordEmail ()
 getName ($separator=' ')
 getId ()
 getAclRole ()
 authenticate ($username, $password)
 login ($username, $password)
 reload ()
 loadByUsername ($username)
 hasAssigned2Role ($user)
 findFirstAvailableMenu ($parent=null, $path='', $level=0)
 getStatrupPageUrl ()
 getStartupPageUrl ()

Public Attributes

const XML_PATH_FORGOT_EMAIL_TEMPLATE = 'admin/emails/forgot_email_template'
const XML_PATH_FORGOT_EMAIL_IDENTITY = 'admin/emails/forgot_email_identity'
const XML_PATH_STARTUP_PAGE = 'admin/startup/page'

Protected Member Functions

 _construct ()
 _getEncodedPassword ($pwd)

Protected Attributes

 $_eventPrefix = 'admin_user'
 $_role


Detailed Description

Definition at line 34 of file User.php.


Member Function Documentation

_construct (  )  [protected]

Varien constructor

Reimplemented from Varien_Object.

Definition at line 50 of file User.php.

00051     {
00052         $this->_init('admin/user');
00053     }

_getEncodedPassword ( pwd  )  [protected]

Definition at line 307 of file User.php.

00308     {
00309         return Mage::helper('core')->getHash($pwd, 2);
00310     }

add (  ) 

Definition at line 171 of file User.php.

00172     {
00173         $this->_getResource()->add($this);
00174         return $this;
00175     }

authenticate ( username,
password 
)

Authenticate user name and password and save loaded record

Parameters:
string $username
string $password
Returns:
boolean
Exceptions:
Mage_Core_Exception 

Definition at line 240 of file User.php.

00241     {
00242         $result = false;
00243         try {
00244             $this->loadByUsername($username);
00245             if ($this->getId() && Mage::helper('core')->validateHash($password, $this->getPassword())) {
00246                 if ($this->getIsActive() != '1') {
00247                     Mage::throwException(Mage::helper('adminhtml')->__('This account is inactive.'));
00248                 }
00249                 if (!$this->hasAssigned2Role($this->getId())) {
00250                     Mage::throwException(Mage::helper('adminhtml')->__('Access Denied.'));
00251                 }
00252                 $result = true;
00253             }
00254 
00255             Mage::dispatchEvent('admin_user_authenticate_after', array(
00256                 'username' => $username,
00257                 'password' => $password,
00258                 'user'     => $this,
00259                 'result'   => $result,
00260             ));
00261         }
00262         catch (Mage_Core_Exception $e) {
00263             $this->unsetData();
00264             throw $e;
00265         }
00266 
00267         if (!$result) {
00268             $this->unsetData();
00269         }
00270         return $result;
00271     }

delete (  ) 

Delete user

Returns:
Mage_Admin_Model_User

Reimplemented from Mage_Core_Model_Abstract.

Definition at line 120 of file User.php.

00121     {
00122         $this->_getResource()->delete($this);
00123         return $this;
00124     }

deleteFromRole (  ) 

Definition at line 159 of file User.php.

00160     {
00161         $this->_getResource()->deleteFromRole($this);
00162         return $this;
00163     }

findFirstAvailableMenu ( parent = null,
path = '',
level = 0 
)

Find first menu item that user is able to access

Parameters:
Mage_Core_Model_Config_Element $parent
string $path
integer $level
Returns:
string

Definition at line 320 of file User.php.

00321     {
00322         if ($parent == null) {
00323             $parent = Mage::getConfig()->getNode('adminhtml/menu');
00324         }
00325         foreach ($parent->children() as $childName=>$child) {
00326             $aclResource = 'admin/' . $path . $childName;
00327             if (Mage::getSingleton('admin/session')->isAllowed($aclResource)) {
00328                 if (!$child->children) {
00329                     return (string)$child->action;
00330                 } else if ($child->children) {
00331                     $action = $this->findFirstAvailableMenu($child->children, $path . $childName . '/', $level+1);
00332                     return $action ? $action : (string)$child->action;
00333                 }
00334             }
00335         }
00336     }

getAclRole (  ) 

Get user ACL role

Returns:
string

Definition at line 227 of file User.php.

00228     {
00229         return 'U' . $this->getUserId();
00230     }

getCollection (  ) 

Reimplemented from Mage_Core_Model_Abstract.

Definition at line 183 of file User.php.

00183                                     {
00184         return Mage::getResourceModel('admin/user_collection');
00185     }

getId (  ) 

Retrieve model object identifier

Returns:
mixed

Reimplemented from Mage_Core_Model_Abstract.

Definition at line 217 of file User.php.

00218     {
00219         return $this->getUserId();
00220     }

getName ( separator = ' '  ) 

Definition at line 212 of file User.php.

00213     {
00214         return $this->getFirstname() . $separator . $this->getLastname();
00215     }

getRole (  ) 

Get admin role model

Returns:
Mage_Admin_Model_Roles

Definition at line 147 of file User.php.

00148     {
00149         if (null === $this->_role) {
00150             $this->_role = Mage::getModel('admin/roles');
00151             $roles = $this->getRoles();
00152             if ($roles && isset($roles[0]) && $roles[0]) {
00153                 $this->_role->load($roles[0]);
00154             }
00155         }
00156         return $this->_role;
00157     }

getRoles (  ) 

Definition at line 137 of file User.php.

00138     {
00139         return $this->_getResource()->getRoles($this);
00140     }

getStartupPageUrl (  ) 

Find admin start page url

Returns:
string

Definition at line 355 of file User.php.

00356     {
00357         $startupPage = Mage::getStoreConfig(self::XML_PATH_STARTUP_PAGE);
00358         $aclResource = 'admin/' . $startupPage;
00359         if (Mage::getSingleton('admin/session')->isAllowed($aclResource)) {
00360             $nodePath = 'adminhtml/menu/' . join('/children/', split('/', $startupPage)) . '/action';
00361             if ($url = Mage::getConfig()->getNode($nodePath)) {
00362                 return $url;
00363             }
00364         }
00365         return $this->findFirstAvailableMenu();
00366     }

getStatrupPageUrl (  ) 

Find admin start page url

Deprecated:
Please use getStartupPageUrl() method instead
See also:
getStartupPageUrl()
Returns:
string

Definition at line 345 of file User.php.

00346     {
00347         return $this->getStartupPageUrl();
00348     }

hasAssigned2Role ( user  ) 

Definition at line 302 of file User.php.

00303     {
00304         return $this->getResource()->hasAssigned2Role($user);
00305     }

loadByUsername ( username  ) 

Definition at line 296 of file User.php.

00297     {
00298         $this->setData($this->getResource()->loadByUsername($username));
00299         return $this;
00300     }

login ( username,
password 
)

Login user

Parameters:
string $login
string $password
Returns:
Mage_Admin_Model_User

Definition at line 280 of file User.php.

00281     {
00282         if ($this->authenticate($username, $password)) {
00283             $this->getResource()->recordLogin($this);
00284         }
00285         return $this;
00286     }

reload (  ) 

Definition at line 288 of file User.php.

00289     {
00290         $id = $this->getId();
00291         $this->setId(null);
00292         $this->load($id);
00293         return $this;
00294     }

roleUserExists (  ) 

Definition at line 165 of file User.php.

00166     {
00167         $result = $this->_getResource()->roleUserExists($this);
00168         return ( is_array($result) && count($result) > 0 ) ? true : false;
00169     }

save (  ) 

Save user

Returns:
Mage_Admin_Model_User

Reimplemented from Mage_Core_Model_Abstract.

Definition at line 60 of file User.php.

00061     {
00062         $this->_beforeSave();
00063         $data = array(
00064             'firstname' => $this->getFirstname(),
00065             'lastname'  => $this->getLastname(),
00066             'email'     => $this->getEmail(),
00067             'modified'  => now(),
00068             'extra'     => serialize($this->getExtra())
00069         );
00070 
00071         if($this->getId() > 0) {
00072             $data['user_id'] = $this->getId();
00073         }
00074 
00075         if( $this->getUsername() ) {
00076             $data['username'] = $this->getUsername();
00077         }
00078 
00079         if ($this->getPassword()) {
00080             $data['password'] = $this->_getEncodedPassword($this->getPassword());
00081         }
00082 
00083         if ($this->getNewPassword()) {
00084             $data['password'] = $this->_getEncodedPassword($this->getNewPassword());
00085         }
00086         elseif ($this->getPassword()) {
00087             $data['new_password'] = $this->getPassword();
00088         }
00089 
00090         if ( !is_null($this->getIsActive()) ) {
00091             $data['is_active'] = intval($this->getIsActive());
00092         }
00093 
00094         $this->addData($data);
00095         $this->_getResource()->save($this);
00096         $this->_afterSave();
00097         return $this;
00098     }

saveExtra ( data  ) 

Save admin user extra data (like configuration sections state)

Parameters:
array $data
Returns:
Mage_Admin_Model_User

Definition at line 106 of file User.php.

00107     {
00108         if (is_array($data)) {
00109             $data = serialize($data);
00110         }
00111         $this->_getResource()->saveExtra($this, $data);
00112         return $this;
00113     }

saveRelations (  ) 

Save user roles

Returns:
Mage_Admin_Model_User

Definition at line 131 of file User.php.

00132     {
00133         $this->_getResource()->_saveRelations($this);
00134         return $this;
00135     }

sendNewPasswordEmail (  ) 

Send email with new user password

Returns:
Mage_Admin_Model_User

Definition at line 192 of file User.php.

00193     {
00194         $translate = Mage::getSingleton('core/translate');
00195         /* @var $translate Mage_Core_Model_Translate */
00196         $translate->setTranslateInline(false);
00197 
00198         Mage::getModel('core/email_template')
00199             ->setDesignConfig(array('area' => 'adminhtml', 'store' => $this->getStoreId()))
00200             ->sendTransactional(
00201                 Mage::getStoreConfig(self::XML_PATH_FORGOT_EMAIL_TEMPLATE),
00202                 Mage::getStoreConfig(self::XML_PATH_FORGOT_EMAIL_IDENTITY),
00203                 $this->getEmail(),
00204                 $this->getName(),
00205                 array('user' => $this, 'password' => $this->getPlainPassword()));
00206 
00207         $translate->setTranslateInline(true);
00208 
00209         return $this;
00210     }

userExists (  ) 

Definition at line 177 of file User.php.

00178     {
00179         $result = $this->_getResource()->userExists($this);
00180         return ( is_array($result) && count($result) > 0 ) ? true : false;
00181     }


Member Data Documentation

$_eventPrefix = 'admin_user' [protected]

Reimplemented from Mage_Core_Model_Abstract.

Definition at line 40 of file User.php.

$_role [protected]

Definition at line 45 of file User.php.

const XML_PATH_FORGOT_EMAIL_IDENTITY = 'admin/emails/forgot_email_identity'

Definition at line 37 of file User.php.

const XML_PATH_FORGOT_EMAIL_TEMPLATE = 'admin/emails/forgot_email_template'

Definition at line 36 of file User.php.

const XML_PATH_STARTUP_PAGE = 'admin/startup/page'

Definition at line 38 of file User.php.


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

Generated on Sat Jul 4 17:22:41 2009 for Magento by  doxygen 1.5.8