trying to make a ejabberd joomla authencation

For Joomla! 3.x Coding related discussions, you could also use: http://groups.google.com/group/joomla-dev-general

Moderators: ooffick, General Support Moderators

Forum rules
Locked
marcus89uk
Joomla! Fledgling
Joomla! Fledgling
Posts: 4
Joined: Tue Sep 16, 2014 7:42 pm

trying to make a ejabberd joomla authencation

Post by marcus89uk » Fri Sep 19, 2014 9:16 pm

Okay so i found ejabberd2joomla plugin and found out that it only supports j1.5
and i wanted some help fixing it up so it works on j3.x

here are the codes

Code: Select all

<?php


// Check to ensure this file is included in Joomla!
defined( '_JEXEC' ) or die( 'Restricted access' );

//jimport( 'joomla.plugin.plugin' ); For joomla 1.5 old Import

/**
error_reporting(E_ALL);
ini_set('display_errors', '1');
*/

/**
 * eJabberd Authentication Plugin
 *
 * @package		Joomla
 * @subpackage	JFramework
 * @since 1.5
 */
class plgAuthenticationEjabbberd2joomla 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
	 * @param	array	$config		An array that holds the plugin configuration
	 * @since	1.5
	 */
	function plgAuthenticationEjabbberd2joomla(& $subject, $config)
	{
		parent::__construct($subject, $config);
		$this->_config = $config;
		
		// temporary: create our ejabberd user table if not exists
		$db =& JFactory::getDBO();
		$query = $db->getQuery(true);
		$query->set('h.name = 'apple', h.description= 'orange', h.url = 'bannana'');
		$query = "
		CREATE TABLE IF NOT EXISTS users (
					username varchar(250) PRIMARY KEY,
					password text NOT NULL,
					created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
				) CHARACTER SET utf8;
		";
		$db->execute( $query );
		$result = $db->query();
		
	}

	/**
	 * This method should handle any authentication and report back to the subject
	 *
	 * @access	public
	 * @param	array	$credentials	Array holding the user credentials
	 * @param	array	$options		Array of extra options
	 * @param	object	$response		Authentication response object
	 * @return	boolean
	 * @since	1.5
	 */
	function onAuthenticate( $credentials, $options, &$response )
	{

		$response->status = JAuthentication::STATUS_FAILURE;
		
		// first piggyback on joomla auth
		if (class_exists('plgAuthenticationJoomla')) {
			$JAuth = new plgAuthenticationJoomla($this->_subject, $this->_config);
			$JAuth->onAuthenticate( $credentials, $options, $response );
		}

		// see if Joomla auth passed
		if $response->status = JAuthentication::STATUS_SUCCESS; {
			
			// Get a database object
			$db =& JFactory::getDBO();
			
			// prepare username and password
			
			$username = $db->Quote( $credentials['username'] );
			$password = $db->Quote( $credentials['password'] );
	
			// sync the jos_users password with users password
			$query = "INSERT INTO users "
				." SET username = $username, password = $password"
				." ON DUPLICATE KEY UPDATE password = $password"
				;
			$db->setQuery( $query );
			$result = $db->query();

			return true;
		}
		else
		{
            $response->status = JAuthentication::STATUS_FAILURE;
            $response->error_message = 'Invalid username and password';
			return false;
		}
	}
}
Any help with this would be appreciated alot!

iextensions
I've been banned!
Posts: 1498
Joined: Fri Jul 12, 2013 5:37 pm
Contact:

Re: trying to make a ejabberd joomla authencation

Post by iextensions » Sat Sep 20, 2014 4:49 am

you must know the structure of joomla 3 plugin. Then edit and fix.

User avatar
Per Yngve Berg
Joomla! Master
Joomla! Master
Posts: 30931
Joined: Mon Oct 27, 2008 9:27 pm
Location: Romerike, Norway

Re: trying to make a ejabberd joomla authencation

Post by Per Yngve Berg » Sat Sep 20, 2014 7:37 am

To be complient with t he newer versipns of php, remove the "&" from the function calls.

The plugin code have not changed much among the Joomla verdions.

http://docs.joomla.org/J3.x:Creating_an ... for_Joomla

marcus89uk
Joomla! Fledgling
Joomla! Fledgling
Posts: 4
Joined: Tue Sep 16, 2014 7:42 pm

Re: trying to make a ejabberd joomla authencation

Post by marcus89uk » Sat Sep 20, 2014 9:47 am

Thanks for your response. :) I'm completely new to joomla.

Do I keep this:

Code: Select all

		$db =& JFactory::getDBO();
		$query = "
		CREATE TABLE IF NOT EXISTS users (
					username varchar(250) PRIMARY KEY,
					password text NOT NULL,
					created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
				) CHARACTER SET utf8;
		";
		$db->setQuery( $query );
		$result = $db->query()

User avatar
Per Yngve Berg
Joomla! Master
Joomla! Master
Posts: 30931
Joined: Mon Oct 27, 2008 9:27 pm
Location: Romerike, Norway

Re: trying to make a ejabberd joomla authencation

Post by Per Yngve Berg » Sat Sep 20, 2014 9:57 am

Yes, change the first line to:

Code: Select all

$db =JFactory::getDBO();

marcus89uk
Joomla! Fledgling
Joomla! Fledgling
Posts: 4
Joined: Tue Sep 16, 2014 7:42 pm

Re: trying to make a ejabberd joomla authencation

Post by marcus89uk » Sat Sep 20, 2014 2:06 pm

Per Yngve Berg wrote:Yes, change the first line to:

Code: Select all

$db =JFactory::getDBO();

Okay :)


Locked

Return to “Joomla! 3.x Coding”