コード例 #1
0
 /**
  * Finds out if a set of login credentials are valid by asking all observing
  * objects to run their respective authentication routines.
  *
  * @param   array  $credentials  Array holding the user credentials.
  * @param   array  $options      Array holding user options.
  *
  * @return  AuthenticationResponse  Response object with status variable filled in for last plugin or first successful plugin.
  *
  * @see     AuthenticationResponse
  * @since   11.1
  */
 public function authenticate($credentials, $options = array())
 {
     // Get plugins
     $plugins = Helper::getPlugin('authentication');
     // Create authentication response
     $response = new AuthenticationResponse();
     /*
      * Loop through the plugins and check of the credentials can be used to authenticate
      * the user
      *
      * Any errors raised in the plugin should be returned via the AuthenticationResponse
      * and handled appropriately.
      */
     foreach ($plugins as $plugin) {
         $className = 'plg' . $plugin->type . $plugin->name;
         if (class_exists($className)) {
             $plugin = new $className($this, (array) $plugin);
         } else {
             // Bail here if the plugin can't be created
             Log::add(Text::sprintf('JLIB_USER_ERROR_AUTHENTICATION_FAILED_LOAD_PLUGIN', $className), Log::WARNING, 'jerror');
             continue;
         }
         // Try to authenticate
         $plugin->onUserAuthenticate($credentials, $options, $response);
         // If authentication is successful break out of the loop
         if ($response->status === self::STATUS_SUCCESS) {
             if (empty($response->type)) {
                 $response->type = isset($plugin->_name) ? $plugin->_name : $plugin->name;
             }
             break;
         }
     }
     if (empty($response->username)) {
         $response->username = $credentials['username'];
     }
     if (empty($response->fullname)) {
         $response->fullname = $credentials['username'];
     }
     if (empty($response->password)) {
         $response->password = $credentials['password'];
     }
     return $response;
 }