-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from fxstein/master
+ [#8] Basic skelleton for KunenaImporter authentication plugin
- Loading branch information
Showing
4 changed files
with
192 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} | ||
} |