authenticationId)) { // try mapping the application's concept of authentication id to this module's authorization id self::authenticationId2authorizationId($authSpace->authenticationId); } /* Variant of "Authenticate #2" ( see "Authenticate Where?" http://framework.zend.com/wiki/x/fUw ) * This point in the flow of execution also enables us to examine the module's * interpretation of the authentication id. * If anonymous use has been disabled in this module's settings in "modules.ini", * and the user was not recognized by this module's authenticationId2authorizationId(), then */ if (empty($config->allowAnonymousUse) && empty(self::$_authorizationId)) { return $config->authenticate; // allow front controller plugin to redirect in preDispatch() // Reader excercise: redirect to something with a "prettier" explanation message } if (!$config->acl) { // ACL has been enabled in "modules.ini" for this module return; } } ///////////////////////////// // ==> SECTION: auth <== /** * This method is responsible for mapping the ZFDemo's authentication ids to forum module authorization ids. * Each module can maintain its own set of ids used for authorization, * thus allowing integration of diverse modules. */ public static function authenticationId2authorizationId($authenticationId) { self::loadModels(); // getByUsername returns null if lookup fails if (self::$_user = ZFDemoModel_Users::getByUsername($authenticationId['username'])) { self::$_username = self::$_user->username; self::$_authorizationId = self::$_user->user_id; } } public static function getAuthorizationId() { return self::$_authorizationId; } public static function getRole() { return self::$_user ? self::$_user->role : null; } /** * Based on tutorial section, choose which set of model classes to load. * One set uses only PDO, while the other set uses Zend_Db_Table*. */ protected static function loadModels() { static $loaded = false; if (!$loaded) { $loaded = true; $config = Zend_Registry::get('config'); // application-wide configuration ini $ds = DIRECTORY_SEPARATOR; // Use raw SQL with PDO, or use the ZF Row/Table gateway components for model classes $prefix = 'forum' . $ds . 'models' . $ds . $config->db->modelSet . $ds; require_once $prefix . 'Users.php'; require_once $prefix . 'Posts.php'; require_once $prefix . 'Topics.php'; require_once $prefix . 'Attachments.php'; } } ///////////////////////////// // ==> SECTION: mvc <== /** * prepare module for use by module's controllers */ public static function moduleInit($view) { $view->username = self::$_username; self::loadModels(); // make sure forum model classes are ready to use } }