Skip to content

Commit

Permalink
Merge pull request #9 from fxstein/master
Browse files Browse the repository at this point in the history
+ [#8] Basic skelleton for KunenaImporter authentication plugin
  • Loading branch information
mahagr committed Jul 8, 2011
2 parents 278ee3b + c2473fa commit ab21560
Show file tree
Hide file tree
Showing 4 changed files with 192 additions and 0 deletions.
3 changes: 3 additions & 0 deletions administrator/components/com_kunenaimporter/CHANGELOG.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
6-July-2011 Matias
+ [#5] phpBB3 support: migrate attachments

8-July-2011 fxstein
+ [#8] Basic skelleton for KunenaImporter authentication plugin

5-July-2011 Matias
^ [#1] Convert component to PHP5

Expand Down
16 changes: 16 additions & 0 deletions plugins/authentication/kunenaimporter-j15.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<install version="1.5" type="plugin" group="auth">
<name>Authentication - Joomla</name>
<author>Joomla! Project</author>
<creationDate>November 2005</creationDate>
<copyright>Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.</copyright>
<license>http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL</license>
<authorEmail>[email protected]</authorEmail>
<authorUrl>www.joomla.org</authorUrl>
<version>1.5</version>
<description>Handles Joomlas default user authentication</description>
<files>
<filename plugin="joomla">joomla.php</filename>
</files>
<params/>
</install>
20 changes: 20 additions & 0 deletions plugins/authentication/kunenaimporter-j16.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<extension version="1.6" type="plugin" group="auth">
<name>plg_authentication_joomla</name>
<author>Joomla! Project</author>
<creationDate>November 2005</creationDate>
<copyright>Copyright (C) 2005 - 2011 Open Source Matters. All rights reserved.</copyright>
<license>GNU General Public License version 2 or later; see LICENSE.txt</license>
<authorEmail>[email protected]</authorEmail>
<authorUrl>www.joomla.org</authorUrl>
<version>1.6.0</version>
<description>PLG_AUTH_JOOMLA_XML_DESCRIPTION</description>
<files>
<filename plugin="joomla">joomla.php</filename>
<filename>index.html</filename>
</files>
<languages>
<language tag="en-GB">en-GB.plg_authentication_joomla.ini</language>
<language tag="en-GB">en-GB.plg_authentication_joomla.sys.ini</language>
</languages>
</extension>
153 changes: 153 additions & 0 deletions plugins/authentication/kunenaimporter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
<?php
/**
* @version $Id$
* Kunena Forum Importer Component
* @package com_kunenaimporter
*
* Imports forum data into Kunena
*
* @Copyright (C) 2009 - 2010 Kunena Team All rights reserved
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
* @link http://www.kunena.com
*
*/

// No direct access
defined('_JEXEC') or die;

jimport('joomla.plugin.plugin');

/**
* Kunena Importer Authentication plugin
*
* @package KunenaImporter.Plugin
* @subpackage Authentication.KunenaImporter
* @since 1.6
*/
class plgAuthenticationKunenaMigrator extends JPlugin
{
/**
* This method should handle any authentication and report back to the subject for Joomla 1.5
*
* @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 )
{
jimport('joomla.user.helper');

// Joomla does not like blank passwords
if (empty($credentials['password']))
{
$response->status = JAUTHENTICATE_STATUS_FAILURE;
$response->error_message = 'Empty password not allowed';
return false;
}

// Initialize variables
$conditions = '';

// Get a database object
$db =& JFactory::getDBO();

$query = 'SELECT `id`, `password`, `gid`'
. ' FROM `#__users`'
. ' WHERE username=' . $db->Quote( $credentials['username'] )
;
$db->setQuery( $query );
$result = $db->loadObject();


if($result)
{
$parts = explode( ':', $result->password );
$crypt = $parts[0];
$salt = @$parts[1];
$testcrypt = JUserHelper::getCryptedPassword($credentials['password'], $salt);

if ($crypt == $testcrypt) {
$user = JUser::getInstance($result->id); // Bring this in line with the rest of the system
$response->email = $user->email;
$response->fullname = $user->name;
$response->status = JAUTHENTICATE_STATUS_SUCCESS;
$response->error_message = '';
} else {
$response->status = JAUTHENTICATE_STATUS_FAILURE;
$response->error_message = 'Invalid password';
}
}
else
{
$response->status = JAUTHENTICATE_STATUS_FAILURE;
$response->error_message = 'User does not exist';
}
}

/**
* This method should handle any authentication and report back to the subject for Joomla 1.6
*
* @access public
* @param array Array holding the user credentials
* @param array Array of extra options
* @param object Authentication response object
* @return boolean
* @since 1.6
*/
function onUserAuthenticate($credentials, $options, &$response)
{
jimport('joomla.user.helper');

$response->type = 'Joomla';
// Joomla does not like blank passwords
if (empty($credentials['password'])) {
$response->status = JAUTHENTICATE_STATUS_FAILURE;
$response->error_message = JText::_('JGLOBAL_AUTH_EMPTY_PASS_NOT_ALLOWED');
return false;
}

// Initialise variables.
$conditions = '';

// Get a database object
$db = JFactory::getDbo();
$query = $db->getQuery(true);

$query->select('id, password');
$query->from('#__users');
$query->where('username=' . $db->Quote($credentials['username']));

$db->setQuery($query);
$result = $db->loadObject();

if ($result) {
$parts = explode(':', $result->password);
$crypt = $parts[0];
$salt = @$parts[1];
$testcrypt = JUserHelper::getCryptedPassword($credentials['password'], $salt);

if ($crypt == $testcrypt) {
$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 = JAUTHENTICATE_STATUS_SUCCESS;
$response->error_message = '';
} else {
$response->status = JAUTHENTICATE_STATUS_FAILURE;
$response->error_message = JText::_('JGLOBAL_AUTH_INVALID_PASS');
}
} else {
$response->status = JAUTHENTICATE_STATUS_FAILURE;
$response->error_message = JText::_('JGLOBAL_AUTH_NO_USER');
}
}
}

0 comments on commit ab21560

Please sign in to comment.