Joomla.it Forum

Non solo Joomla... => Sviluppo => : Fenicexx 15 Dec 2012, 09:57:32

: Plugin di autenticazione
: Fenicexx 15 Dec 2012, 09:57:32

Ciao,
sto seguendo il tutorial [size=78%]http://docs.joomla.org/Tutorial:Creating_an_Authentication_Plugin_for_J oomla_1.5[/size] ovviamente il codice presente non funziona con joomla 2.5.x. il risultato che mi da è una pagina bianca ho provato ad inserire la riga:


:
ini_set('display_errors',true);

e non restituisce alcun risultato.


Questo è il codice presente nel tutorial:

:
<?php
/**
 * @version    $Id: myauth.php 7180 2007-04-23 16:51:53Z jinx $
 * @package    Joomla.Tutorials
 * @subpackage Plugins
 * @license    GNU/GPL
 */
 
// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die();
 
jimport('joomla.event.plugin');
 
/**
 * Example Authentication Plugin.  Based on the example.php plugin in the Joomla! Core installation
 *
 * @package    Joomla.Tutorials
 * @subpackage Plugins
 * @license    GNU/GPL
 */
class plgAuthenticationMyauth extends JPlugin
{
    
/**
     * Constructor
     *
     * For php4 compatability we must not use the __constructor as a constructor for plugins
     * because func_get_args ( void ) returns a copy of all passed arguments NOT references.
     * This causes problems with cross-referencing necessary for the observer design pattern.
     *
     * @param object $subject The object to observe
     * @since 1.5
     */
    
function plgAuthenticationMyauth(& $subject) {
        
parent::__construct($subject);
    }
 
    
/**
     * This method should handle any authentication and report back to the subject
     * This example uses simple authentication - it checks if the password is the reverse
     * of the username (and the user exists in the database).
     *
     * @access    public
     * @param     array     $credentials    Array holding the user credentials ('username' and 'password')
     * @param     array     $options        Array of extra options
     * @param     object    $response       Authentication response object
     * @return    boolean
     * @since 1.5
     */
    
function onAuthenticate$credentials$options, &$response )
    {
        
/*
         * Here you would do whatever you need for an authentication routine with the credentials
         *
         * In this example the mixed variable $return would be set to false
         * if the authentication routine fails or an integer userid of the authenticated
         * user if the routine passes
         */
        
$db =& JFactory::getDBO();
        
$query 'SELECT `id`'
            
' FROM #__users'
            
' WHERE username=' $db->quote$credentials['username'] );
        
$db->setQuery$query );
        
$result $db->loadResult();
 
        if (!
$result) {
            
$response->status JAUTHENTICATE_STATUS_FAILURE;
            
$response->error_message 'User does not exist';
        }
 
        
// to authenticate, the username must exist in the database, and the password should be equal
        // to the reverse of the username (so user joeblow would have password wolbeoj)
        
if($result && ($credentials['username'] == strrev$credentials['password'] )))
        {
            
$email JUser::getInstance($result); // Bring this in line with the rest of the system
            
$response->email $email->email;
            
$response->status JAUTHENTICATE_STATUS_SUCCESS;
        }
        else
        {
            
$response->status JAUTHENTICATE_STATUS_FAILURE;
            
$response->error_message 'Invalid username and password';
        }
    }
}
?>
: Re:Plugin di autenticazione
: simone83 17 Dec 2012, 09:56:29
Prova a guardare il plugin di autenticazione di joomla 2.5 invece di quel tutorial che penso non vada bene adesso. Molto probabilmente non vanno piu bene i metodi di settaggio delle variabili

ad esempio per settare le variabili in caso di successo joomla fa cosi

               
:
$user = JUser::getInstance($result->id); // Bring this in line with the rest of the system
                $response->email = $user->email;
                $response->fullname = $user->name;
                if (JFactory::getApplication()->isAdmin()) {
                    $response->language = $user->getParam('admin_language');
                }
                else {
                    $response->language = $user->getParam('language');
                }
                $response->status = JAuthentication::STATUS_SUCCESS;
                $response->error_message = '';