/** * Register a profile automatically if it not exists. * * @param string $result result row of authentication * @return void */ public function registerProfile($signal) { if (!Centurion_Auth::getInstance()->getProfile()) { $identity = Centurion_Auth::getInstance()->getIdentity(); Centurion_Db::getSingleton('user/profile')->insert(array('nickname' => $identity->username, 'user_id' => $identity->id)); } }
/** * Returns an instance of Centurion_Auth * * Singleton pattern implementation. * * @return Centurion_Auth Provides a fluent interface */ public static function getInstance() { if (null === self::$_instance) { self::$_instance = new self(); } return self::$_instance; }
public function deleteAction($rowset = null) { if ($this->_getParam('id', 0) === Centurion_Auth::getInstance()->getIdentity()->id) { Zend_Controller_Action_HelperBroker::getStaticHelper('redirector')->gotoSimple('unauthorized', 'error', 'admin'); } else { parent::deleteAction($rowset); } }
public function testAuthenticate() { //$adapter = new Centurion_Auth_Adapter_DbTable($dbAdapter, 'auth_user', 'password'); Centurion_Auth::getInstance()->setStorage(new Zend_Auth_Storage_NonPersistent()); $validator = new Auth_Form_Validator_Login(array('dbAdapter' => Zend_Db_Table_Abstract::getDefaultAdapter(), 'tableName' => 'auth_user', 'loginColumn' => 'username', 'passwordColumn' => 'password', 'authAdapter' => 'Centurion_Auth_Adapter_DbTable', 'checkColumn' => 'is_active = 1')); $this->assertTrue($validator->isValid('admincenturion', array('login' => 'admin'))); $this->assertFalse($validator->isValid('admin', array('login' => 'admin'))); }
public function logInAsAnnonymous() { $user = Centurion_Db::getSingleton('auth/user')->findOneById(2); if ($user == null) { throw new PHPUnit_Framework_Exception('Can not log as annonymous. User does not exists'); } Centurion_Auth::getInstance()->clearIdentity(); Centurion_Auth::getInstance()->getStorage()->write($user); }
private function _redirectIfAuthenticated() { if (Centurion_Auth::getInstance()->hasIdentity()) { if ($this->_hasParam('next') && '' != $this->_getParam('next')) { $this->getHelper('redirector')->gotoUrlAndExit($this->_getParam('next')); } else { $this->getHelper('redirector')->gotoUrlAndExit('/'); } } }
/** * Returns true if and only if $value passes all validations in the chain * * Validators are run in the order in which they were added to the chain (FIFO). * * @param mixed $value * @return boolean */ public function isValid($value, $context = null) { $adapter = new $this->_authAdapter($this->_dbAdapter, $this->_tableName, $this->_loginColumn, $this->_passwordColumn, $this->_saltingMechanism); $adapter->setIdentity($context['login']); $adapter->setCredential($value); if (null !== $this->_checkColumn) { $adapter->getDbSelect()->where($this->_checkColumn); } try { $result = Centurion_Auth::getInstance()->authenticate($adapter); } catch (Zend_Auth_Exception $e) { $this->_error(self::DB_INVALID); return false; } if ($result->isValid()) { Centurion_Signal::factory('pre_login')->send(null, $adapter); $result = $adapter->getResultRowObject(null); Centurion_Auth::getInstance()->clearIdentity(); Centurion_Auth::getInstance()->getStorage()->write($result); //Zend_Session::writeClose(false); Centurion_Signal::factory('post_login')->send(null, $result); return true; } $this->_error(self::NOT_MATCH); return false; }
/** * Convert a rowset to Zend_Navigation array format. * * @param Centurion_Db_Table_Rowset_Abstract $menus * @return array */ private function _navigation(Centurion_Db_Table_Rowset_Abstract $menus, $identity = null) { $navigations = array(); if ($identity == null) { $identity = Centurion_Auth::getInstance()->getIdentity(); if (null === $identity) { return $navigations; } } foreach ($menus as $menu) { $pages = null; if (!$menu->isLeafNode()) { $pages = $this->_navigation($menu->getChildren()); } $navigationData = $menu->getNavigationData($identity); if (null === $navigationData) { continue; } if (isset($navigationData['uri']) && $navigationData['uri'] === '#' && count($pages) > 0) { if (isset($pages[0]['uri'])) { $navigationData['uri'] = $pages[0]['uri']; } else { $navigationData['route'] = $pages[0]['route']; $navigationData['module'] = $pages[0]['module']; $navigationData['action'] = $pages[0]['action']; $navigationData['controller'] = $pages[0]['controller']; $navigationData['params'] = $pages[0]['params']; } } else { //No href, so it will be display with span tag $navigationData['uri'] = ''; } if (null !== $pages) { $navigationData['pages'] = $pages; } array_push($navigations, $navigationData); } return $navigations; }
/** * * @return Centurion_Auth */ public function getUser() { return Centurion_Auth::getInstance(); }
public function switchAction() { $name = $this->_getParam('name'); Centurion_Auth::getInstance()->getIdentity()->name; parent::switchAction(); }
/** * Returns true if and only if an identity is available from storage * * @return boolean */ public function hasValidIdentityYet() { return Centurion_Auth::getInstance()->hasIdentity(); }