public function isValid($value) { $this->_setValue($value); if ($this->_current_user == $value) { return true; } $m_users = new GD_Model_UsersMapper(); $existing_user = $m_users->getUserByName($value, false); if (is_null($existing_user)) { return true; } else { $this->_error(self::ISUNIQUE); return false; } }
/** * Check that the user has an identity (is logged in) and that they have * sufficient access to the resource (page) requested. * * (non-PHPdoc) * @see Zend_Controller_Plugin_Abstract::preDispatch() */ public function preDispatch(Zend_Controller_Request_Abstract $request) { // If we are on the error controller, return immediately to prevent // any database errors happening on error page if ($request->controller == "error") { return; } // First determine what role we have (admin, member or guest) if ($this->_auth->hasIdentity()) { $username = Zend_Auth::getInstance()->getIdentity(); $userMapper = new GD_Model_UsersMapper(); $user = $userMapper->getUserByName($username); if ($user->isAdmin()) { $role = 'admin'; } else { $role = 'member'; } } else { $role = 'guest'; } // Set the initial request - these will be unmodified if access allowed $controller = $request->controller; $action = $request->action; $module = $request->module; $resource = $controller; if (!$this->_acl->has($resource)) { $resource = null; } // Use Zend_Acl to check access permissions if (!$this->_acl->isAllowed($role, $resource, $action)) { if (!$this->_auth->hasIdentity()) { $module = $this->_noauth['module']; $controller = $this->_noauth['controller']; $action = $this->_noauth['action']; } else { $module = $this->_noacl['module']; $controller = $this->_noacl['controller']; $action = $this->_noacl['action']; } } // If the module/controller/action has changed, change the request if ($request->controller != $controller || $request->action != $action || $request->module != $module) { $request->setModuleName($module); $request->setControllerName($controller); $request->setActionName($action); } }
/** * Handy dandy function to get the GD_Model_User object from the currently * logged in Zend_Auth identity. Returns null on failure. * * @return GD_Model_User|null */ public static function GetLoggedInUser() { if (!isset(self::$_currentUser) || is_null(self::$_currentUser) || !self::$_currentUser instanceof GD_Model_User) { $auth = Zend_Auth::getInstance(); $username = $auth->getIdentity(); if (is_null($username)) { return null; } $users = new GD_Model_UsersMapper(); self::$_currentUser = $users->getUserByName($username, true); return self::$_currentUser; } else { return self::$_currentUser; } }