FundacionLQDVI_WebCongresos/www/components/com_alpharegistration/assets/scripts/checkusername.php

59 lines
1.7 KiB
PHP
Raw Normal View History

<?php
define( '_JEXEC', 1 );
if (stristr( $_SERVER['SERVER_SOFTWARE'], 'win32' )) {
define( 'JPATH_BASE', realpath(dirname(__FILE__).'\..\..\..\..' ));
} else define( 'JPATH_BASE', realpath(dirname(__FILE__).'/../../../..' ));
define( 'DS', DIRECTORY_SEPARATOR );
require_once ( JPATH_BASE.DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE.DS.'includes'.DS.'framework.php' );
$mainframe =& JFactory::getApplication('site');
$mainframe->initialise();
jimport( 'joomla.plugin.plugin' );
JPlugin::loadLanguage( 'com_alpharegistration' );
$arg_params = &JComponentHelper::getParams( 'com_alpharegistration' );
if(isset($_POST['username']))
{
$username = $_POST['username'];
// check if already used
$db =& JFactory::getDBO();
$query = "SELECT id FROM #__users WHERE `username`='".$username."' LIMIT 1";
$db->setQuery( $query );
$usralreadyexist = $db->loadResult();
// check if blocked
$notAccepted = 0;
if ( $arg_params->get('usernamefilter', 0) && $arg_params->get('usernameblockedlist', '')!='' )
{
$usernamesblocked = str_replace(' ', '', $arg_params->get('usernameblockedlist'));
$usernamesblocked = preg_quote($usernamesblocked, '#');
$usernamesblocked = str_replace(array(",", '\*'), array('|', '.*'), $usernamesblocked );
$regex = "#^(?:$usernamesblocked)$#i";
$usernametest = strtolower (strval( $username ) );
if(preg_match($regex, $usernametest)) $notAccepted = 1;
}
if( $usralreadyexist )
{
// already in use
echo '<font color="red">'.JText::_( 'ARG_THE_USERNAME_IS_ALREADY_IN_USE' ).'</font>';
}
elseif ( $notAccepted )
{
// username blocked
echo '<font color="red">'.JText::_( 'ARG_THIS_USERNAME_IS_NOT_ACCEPTED' ).'</font>';
}
else
{
echo 'OK';
}
}
?>