function login($username = null, $passwd2 = null)
{
    global $_POST, $_CB_framework, $ueConfig;
    checkCBPostIsHTTPS();
    if (count($_POST) == 0) {
        HTML_comprofiler::loginForm('com_comprofiler', $_POST, null);
        return;
    }
    $spoofCheckOk = false;
    if (cbSpoofCheck('login', 'POST', 2)) {
        $spoofCheckOk = true;
    } else {
        if (is_callable("josSpoofCheck") && is_callable("josSpoofValue")) {
            $validate = josSpoofValue();
            if (cbGetParam($_POST, $validate)) {
                josSpoofCheck(1);
                $spoofCheckOk = true;
            }
        }
    }
    if (!$spoofCheckOk) {
        echo _UE_SESSION_EXPIRED . ' ' . _UE_PLEASE_REFRESH;
        return;
    }
    $messagesToUser = array();
    $alertmessages = array();
    if (!$username || !$passwd2) {
        $username = trim(cbGetParam($_POST, 'username', ''));
        $passwd2 = trim(cbGetParam($_POST, 'passwd', '', _CB_ALLOWRAW));
        if (checkJversion() >= 1) {
            $username = stripslashes($username);
            $passwd2 = stripslashes($passwd2);
        }
    }
    $rememberMe = cbGetParam($_POST, 'remember');
    $return = trim(stripslashes(cbGetParam($_POST, 'return', null)));
    if (cbStartOfStringMatch($return, 'B:')) {
        $return = base64_decode(substr($return, 2));
        $arrToClean = array('B' => get_magic_quotes_gpc() ? addslashes($return) : $return);
        $return = cbGetParam($arrToClean, 'B', '');
    }
    if (!(cbStartOfStringMatch($return, $_CB_framework->getCfg('live_site')) || cbStartOfStringMatch($return, 'index.php'))) {
        $return = '';
    }
    $message = trim(cbGetParam($_POST, 'message', 0));
    $loginType = isset($ueConfig['login_type']) ? $ueConfig['login_type'] : 0;
    // Do the login including all authentications and event firing:
    cbimport('cb.authentication');
    $cbAuthenticate = new CBAuthentication();
    $resultError = $cbAuthenticate->login($username, $passwd2, $rememberMe, $message, $return, $messagesToUser, $alertmessages, $loginType);
    if (count($messagesToUser) > 0) {
        if ($resultError) {
            echo "<div class=\"message\">" . $resultError . "</div>";
        }
        echo "\n<div>" . stripslashes(implode("</div>\n<div>", $messagesToUser)) . "</div>\n";
        if (in_array(cbGetParam($_POST, 'loginfrom'), array('loginform', 'regform', 'loginmodule'))) {
            HTML_comprofiler::loginForm('com_comprofiler', $_POST, $resultError);
        }
    } elseif ($resultError) {
        if (in_array(cbGetParam($_POST, 'loginfrom'), array('loginform', 'regform', 'loginmodule'))) {
            HTML_comprofiler::loginForm('com_comprofiler', $_POST, $resultError);
        } else {
            echo "<div class=\"message\">" . $resultError . "</div>";
        }
    } else {
        cbRedirect(cbSef($return, false), count($alertmessages) > 0 ? stripslashes(implode('\\n', $alertmessages)) : '');
    }
}
 static function registerForm($option, $emailpass, $user, $postvars, $regErrorMSG = null, $stillDisplayLoginModule = false)
 {
     global $_CB_framework, $_CB_database, $ueConfig, $_PLUGINS;
     $results = $_PLUGINS->trigger('onBeforeRegisterFormDisplay', array(&$user, $regErrorMSG));
     if ($_PLUGINS->is_errors()) {
         echo "<script type=\"text/javascript\">alert(\"" . $_PLUGINS->getErrorMSG() . "\"); window.history.go(-1); </script>\n";
         exit;
     }
     if ($regErrorMSG) {
         $_CB_framework->enqueueMessage($regErrorMSG, 'error');
     }
     $cbTemplate = HTML_comprofiler::_cbTemplateLoad();
     outputCbTemplate(1);
     outputCbJs(1);
     initToolTip(1);
     $output = 'htmledit';
     $layout = isset($ueConfig['reg_layout']) ? $ueConfig['reg_layout'] : 'flat';
     $formatting = isset($ueConfig['use_divs']) && !$ueConfig['use_divs'] ? $layout == 'flat' ? 'tabletrs' : 'table' : 'divs';
     $tabbed = in_array($layout, array('tabbed', 'stepped')) ? true : false;
     $translatedRegistrationTitle = CBTxt::T('UE_REGISTRATION', 'Sign up');
     if ($translatedRegistrationTitle) {
         $_CB_framework->setPageTitle($translatedRegistrationTitle);
         $_CB_framework->appendPathWay($translatedRegistrationTitle);
     }
     $tabs = new cbTabs(0, 1, null, $tabbed ? true : false);
     $tabcontent = $tabs->getEditTabs($user, $postvars, $output, $formatting, 'register', $layout == 'tabbed' ? 1 : ($layout == 'stepped' ? 2 : 0));
     $topIcons = null;
     $bottomIcons = null;
     if (isset($ueConfig['reg_show_icons_explain']) && $ueConfig['reg_show_icons_explain'] > 0) {
         $icons = getFieldIcons(1, true, true, '', '', true);
         if (in_array($ueConfig['reg_show_icons_explain'], array(1, 3))) {
             $topIcons = $icons;
         }
         if (in_array($ueConfig['reg_show_icons_explain'], array(2, 3))) {
             $bottomIcons = $icons;
         }
     }
     cbValidator::loadValidation();
     $moduleContent = null;
     if (isset($ueConfig['reg_show_login_on_page']) && $ueConfig['reg_show_login_on_page'] == 1 && ($stillDisplayLoginModule || !$regErrorMSG)) {
         $moduleFile = $_CB_framework->getCfg('absolute_path') . '/modules/' . (checkJversion() > 0 ? 'mod_cblogin/' : null) . 'mod_cblogin.php';
         if (file_exists($moduleFile)) {
             define('_UE_LOGIN_FROM', 'loginform');
             $query = 'SELECT *' . "\n FROM " . $_CB_database->NameQuote('#__modules') . "\n WHERE " . $_CB_database->NameQuote('module') . " = " . $_CB_database->Quote('mod_cblogin') . "\n AND " . $_CB_database->NameQuote('published') . " = 1" . "\n ORDER BY " . $_CB_database->NameQuote('ordering');
             $_CB_database->setQuery($query, 0, 1);
             $module = null;
             $_CB_database->loadObject($module);
             if ($module) {
                 $moduleContent = JModuleHelper::renderModule($module, array('style' => 'xhtml'));
             } else {
                 $moduleContent = CBTxt::T('Error: CB Login module not created (required).');
             }
         } else {
             $moduleContent = CBTxt::T('Error: CB Login module not installed (required).');
         }
     }
     $headerMessage = isset($ueConfig['reg_intro_msg']) ? CBTxt::T($ueConfig['reg_intro_msg']) : null;
     $footerMessage = isset($ueConfig['reg_conclusion_msg']) ? CBTxt::T($ueConfig['reg_conclusion_msg']) : null;
     $registrationForm = '<form action="' . $_CB_framework->viewUrl('saveregisters', true, null, 'html', checkCBPostIsHTTPS(true) ? 1 : 0) . '" method="post" id="cbcheckedadminForm" name="adminForm" enctype="multipart/form-data" class="cb_form form-auto cbValidation">' . '<input type="hidden" name="id" value="0" />' . '<input type="hidden" name="gid" value="0" />' . '<input type="hidden" name="emailpass" value="' . htmlspecialchars($emailpass) . '" />' . cbGetSpoofInputTag('registerForm') . cbGetRegAntiSpamInputTag();
     $return = $_PLUGINS->callTemplate($cbTemplate, 'RegisterForm', 'drawProfile', array(&$user, $tabcontent, $registrationForm, $headerMessage, CBTxt::Th('LOGIN_REGISTER_TITLE', 'Welcome. Please log in or sign up:'), CBTxt::Th('REGISTER_TITLE', 'Join us!'), CBTxt::Th('UE_REGISTER', 'Sign up'), $moduleContent, $topIcons, $bottomIcons, $footerMessage, $formatting, $results), $output) . cbPoweredBy();
     echo $return;
     $_PLUGINS->trigger('onAfterRegisterFormDisplay', array($user, $tabcontent));
     $_CB_framework->setMenuMeta();
 }
    static function registerForm($option, $emailpass, &$user, &$postvars, $regErrorMSG = null, $stillDisplayLoginModule = false)
    {
        global $_CB_framework, $_CB_database, $ueConfig, $_PLUGINS;
        $results = $_PLUGINS->trigger('onBeforeRegisterFormDisplay', array(&$user, $regErrorMSG));
        if ($_PLUGINS->is_errors()) {
            echo "<script type=\"text/javascript\">alert(\"" . $_PLUGINS->getErrorMSG() . "\"); window.history.go(-1); </script>\n";
            exit;
        }
        $cbTemplate = HTML_comprofiler::_cbTemplateLoad();
        outputCbTemplate(1);
        outputCbJs(1);
        initToolTip(1);
        $output = 'htmledit';
        $formatting = isset($ueConfig['use_divs']) && $ueConfig['use_divs'] ? 'divs' : 'tabletrs';
        // gets registration tabs from plugins (including the contacts tab core plugin for username, password, etc:
        $tabs = new cbTabs(0, 1, null, false);
        // do not output unused JS code in registration page (IE7 and Safari bugs on that)
        //$tabcontent							=	$tabs->getEditTabs( $user, $postvars, $output, 'tabletrs', 'register', false );
        $tabcontent = $tabs->getEditTabs($user, $postvars, $output, $formatting, 'register', false);
        // outputs the site terms and conditions link and approval checkbox: Not yet a CB field		//TBD
        if ($ueConfig['reg_enable_toc']) {
            global $_CB_OneTwoRowsStyleToggle;
            $class = 'sectiontableentry' . $_CB_OneTwoRowsStyleToggle;
            $_CB_OneTwoRowsStyleToggle = $_CB_OneTwoRowsStyleToggle == 1 ? 2 : 1;
            if ($formatting == 'divs') {
                $tabcontent .= "\t<div class=\"" . $class . " cb_form_line cbclearboth\" id=\"cbfr_termsc\">\n" . '<div class="cb_field"><div id="cbfv_termsc">';
            } else {
                $tabcontent .= "\t<tr class=\"" . $class . "\" id=\"cbfr_termsc\">\n" . "\t\t<td>&nbsp;</td>\n<td class='fieldCell'>";
            }
            $tabcontent .= "<div class=\"cbSnglCtrlLbl\"><input type='checkbox' name='acceptedterms' id='acceptedterms' class='required' value='1' mosReq='0' mosLabel='" . htmlspecialchars(_UE_TOC) . "' /> <label for='acceptedterms'>" . sprintf(_UE_TOC_LINK, "<a href='" . cbSef(htmlspecialchars($ueConfig['reg_toc_url'])) . "' target='_BLANK'> ", "</a>") . '</label>' . getFieldIcons($_CB_framework->getUi(), 1, null, null, null) . "</div>";
            if ($formatting == 'divs') {
                $tabcontent .= "</div></div></div>\n";
            } else {
                $tabcontent .= "</td>\n" . "\t</tr>\n";
            }
        }
        $_CB_framework->setPageTitle(_UE_REGISTRATION);
        $_CB_framework->appendPathWay(_UE_REGISTRATION);
        // starts outputing:
        // $cbSpoofField					=	cbSpoofField();
        $cbSpoofString = cbSpoofString(null, 'registerForm');
        // $regAntiSpamFieldName			=	cbGetRegAntiSpamFieldName();
        $regAntiSpamValues = cbGetRegAntiSpams();
        // <script type="text/javascript" src="includes/js/mambojavascript.js"></script>
        ob_start();
        if (defined('_CB_VALIDATE_NEW')) {
            cbimport('cb.validator');
            cbValidator::renderGenericJs();
            $cbjavascript = ob_get_contents();
            ob_end_clean();
            $_CB_framework->outputCbJQuery($cbjavascript, array('metadata', 'validate'));
        } else {
            // old way:
            ?>
var cbDefaultFieldBackground;
function cbFrmSubmitButton() {
	var me = this.elements;
<?php 
            $version = checkJversion();
            if ($version == 1) {
                // var r = new RegExp("^[a-zA-Z](([\.\-a-zA-Z0-9@])?[a-zA-Z0-9]*)*$", "i");
                ?>
	var r = new RegExp("[\<|\>|\"|\'|\%|\;|\(|\)|\&]", "i");
<?php 
            } elseif ($version == -1) {
                ?>
	var r = new RegExp("[^A-Za-z0-9]", "i");
<?php 
            } else {
                ?>
	var r = new RegExp("[\<|\>|\"|\'|\%|\;|\(|\)|\&|\+|\-]", "i");
<?php 
            }
            ?>
	var errorMSG = '';
	var iserror=0;
	if (cbDefaultFieldBackground === undefined && typeof(me['username'])!='undefined') cbDefaultFieldBackground = ((me['username'].style.getPropertyValue) ? me['username'].style.getPropertyValue("backgroundColor") : me['username'].style.backgroundColor);
<?php 
            echo $tabs->fieldJS;
            ?>
	if (typeof(me['username'])!='undefined' && me['username'].value == "") {
		errorMSG += "<?php 
            echo CBTxt::html_entity_decode(_REGWARN_UNAME);
            ?>
\n";
		me['username'].style.backgroundColor = "red";
		iserror=1;
	} else if (typeof(me['username'])!='undefined' && ( r.exec(me['username'].value) || (me['username'].value.length < 3))) {
		errorMSG += "<?php 
            printf(CBTxt::html_entity_decode(_VALID_AZ09), CBTxt::html_entity_decode(_PROMPT_UNAME), 2);
            ?>
\n";
		me['username'].style.backgroundColor = "red";
		iserror=1;
	} else if (typeof(me['username'])!='undefined' && me['username'].style.backgroundColor.slice(0,3)=="red") { me['username'].style.backgroundColor = cbDefaultFieldBackground;
<?php 
            if ($emailpass != "1") {
                ?>
	}
	if (typeof(me['password'])!='undefined' && me['password'].value.length < 6) {
		errorMSG += "<?php 
                printf(CBTxt::html_entity_decode(_VALID_AZ09), CBTxt::html_entity_decode(_REGISTER_PASS), 6);
                ?>
\n";
		me['password'].style.backgroundColor = "red";
		iserror=1;
	} else if (typeof(me['password'])!='undefined' && (me['password'].value != "") && (me['password'].value != me['password__verify'].value)){
		errorMSG += "<?php 
                echo CBTxt::html_entity_decode(_REGWARN_VPASS2);
                ?>
\n";
		me['password'].style.backgroundColor = "red"; me['password__verify'].style.backgroundColor = "red";
		iserror=1;
	} else if (typeof(me['password'])!='undefined') {
		if (me['password'].style.backgroundColor.slice(0,3)=="red") me['password'].style.backgroundColor = cbDefaultFieldBackground;
		if (me['password__verify'].style.backgroundColor.slice(0,3)=="red") me['password__verify'].style.backgroundColor = cbDefaultFieldBackground;
<?php 
            }
            ?>
	}
<?php 
            if ($ueConfig['reg_enable_toc']) {
                ?>
	if(!me['acceptedterms'].checked) {
		errorMSG += "<?php 
                echo CBTxt::html_entity_decode(_UE_TOC_REQUIRED);
                ?>
\n";
		iserror=1;
	}
<?php 
            }
            ?>
	// loop through all input elements in form
	var fieldErrorMessages = new Array;
	for (var i=0; i < me.length; i++) {
		// check if element is mandatory; here mosReq="1"
		var myenabled = (typeof(me[i].getAttribute('mosNoReq')) == 'undefined' ) || (me[i].getAttribute('mosNoReq') != 1);
		var mytyp = me[i].getAttribute('type');
		var myact = myenabled && mytyp != 'reset' && mytyp != 'button' && mytyp != 'submit' && mytyp != 'image';
		if ( myact && (typeof(me[i].getAttribute('mosReq')) != "undefined") && ( me[i].getAttribute('mosReq') == 1) ) {
			if (me[i].type == 'radio' || me[i].type == 'checkbox') {
				var rOptions = me[me[i].getAttribute('name')];
				var rChecked = 0;
				if(rOptions.length > 1) {
					for (var r=0; r < rOptions.length; r++) {
						if ( (typeof(rOptions[r].getAttribute('mosReq')) != "undefined") && ( rOptions[r].getAttribute('mosReq') == 1) ) {
							if (rOptions[r].checked) {
								rChecked=1;
							}
						}
					}
				} else {
					if (me[i].checked) {
						rChecked=1;
					}
				}
				if (rChecked==0) {
					for (var k=0; k < me.length; k++) {
						if (me[i].getAttribute('name') == me[k].getAttribute('name')) {
							if (me[k].checked) {
								rChecked=1;
								break;
							}
						}
					}
				}
				if (rChecked==0) {
					var alreadyFlagged = false;
					for (var j = 0, n = fieldErrorMessages.length; j < n; j++) {
						if (fieldErrorMessages[j] == me[i].getAttribute('name')) {
							alreadyFlagged = true;
							break
						}
					}
					if ( ! alreadyFlagged ) {
						fieldErrorMessages.push(me[i].getAttribute('name'));
						// add up all error messages
						errorMSG += me[i].getAttribute('mosLabel') + ' : <?php 
            echo CBTxt::html_entity_decode(_UE_REQUIRED_ERROR);
            ?>
\n';
						// notify user by changing background color, in this case to red
						me[i].style.backgroundColor = "red";
						iserror=1;
					}
				} else if (me[i].style.backgroundColor.slice(0,3)=="red") me[i].style.backgroundColor = cbDefaultFieldBackground;
			}
			if (me[i].value == '') {
				// add up all error messages
				errorMSG += me[i].getAttribute('mosLabel') + ' : <?php 
            echo CBTxt::html_entity_decode(_UE_REQUIRED_ERROR);
            ?>
\n';
				// notify user by changing background color, in this case to red
				me[i].style.backgroundColor = "red";
				iserror=1;
			} else if (me[i].style.backgroundColor.slice(0,3)=="red") me[i].style.backgroundColor = cbDefaultFieldBackground;
		}
	}
	if(iserror==1) {
		alert(errorMSG);
		return false;
	} else {
		return true;
	}
}
$('#cbcheckedadminForm').submit( cbFrmSubmitButton );
<?php 
            $cbjavascript = ob_get_contents();
            ob_end_clean();
            $_CB_framework->outputCbJQuery($cbjavascript);
            // end of old
        }
        if ($regErrorMSG) {
            echo "<div class='error'>" . $regErrorMSG . "</div>\n";
        }
        // output results of plugins event "onBeforeRegisterFormDisplay":
        if (is_array($results)) {
            echo implode('', $results);
        }
        $introMessage = isset($ueConfig['reg_intro_msg']) ? stripslashes(getLangDefinition($ueConfig['reg_intro_msg'])) : null;
        $conclusionMessage = isset($ueConfig['reg_conclusion_msg']) ? stripslashes(getLangDefinition($ueConfig['reg_conclusion_msg'])) : null;
        $https_post = checkCBPostIsHTTPS(true);
        $urlRegister = cbSef("index.php?option=" . $option);
        if ($https_post) {
            if (substr($urlRegister, 0, 5) != 'http:' && substr($urlRegister, 0, 6) != 'https:') {
                $urlRegister = $_CB_framework->getCfg('live_site') . '/' . $urlRegister;
            }
            $urlRegister = str_replace('http://', 'https://', $urlRegister);
        }
        $regFormTag = '<form action="' . $urlRegister . '" method="post" id="cbcheckedadminForm" name="adminForm" class="cb_form" enctype="multipart/form-data">
		<input type="hidden" name="id" value="0" />
		<input type="hidden" name="gid" value="0" />
		<input type="hidden" name="emailpass" value="' . $emailpass . '" />
		<input type="hidden" name="option" value="' . $option . '" />
		<input type="hidden" name="task" value="saveregisters" />
		' . cbGetSpoofInputTag(null, $cbSpoofString) . '
		' . cbGetRegAntiSpamInputTag($regAntiSpamValues) . "\n";
        $topIcons = null;
        $bottomIcons = null;
        if (!isset($ueConfig['reg_show_icons_explain']) || $ueConfig['reg_show_icons_explain'] > 0) {
            $icons = getFieldIcons(1, true, true, '', '', true);
            if (in_array($ueConfig['reg_show_icons_explain'], array(1, 3))) {
                $topIcons = $icons;
            }
            if (in_array($ueConfig['reg_show_icons_explain'], array(2, 3))) {
                $bottomIcons = $icons;
            }
        }
        $moduleContent = null;
        if (isset($ueConfig['reg_show_login_on_page']) && $ueConfig['reg_show_login_on_page'] == 1 && ($stillDisplayLoginModule || !$regErrorMSG)) {
            $params = null;
            $login_module_file = $_CB_framework->getCfg('absolute_path') . '/modules/' . (checkJversion() > 0 ? 'mod_cblogin/' : '') . 'mod_cblogin.php';
            if (file_exists($login_module_file)) {
                define('_UE_LOGIN_FROM', 'regform');
                $_CB_database->setQuery("SELECT params from #__modules WHERE module = 'mod_cblogin' ORDER BY ordering", 0, 1);
                $raw_params = $_CB_database->loadResult();
                $params = new cbParamsBase($raw_params);
                // needed for login module
                // $params of login module is needed for the include( $login_module_file ) below !!
                ob_start();
                include $login_module_file;
                $moduleContent = ob_get_contents();
                ob_end_clean();
            }
        }
        // renders using template viewer:
        echo HTML_comprofiler::_cbTemplateRender($cbTemplate, $user, 'RegisterForm', 'drawProfile', array(&$user, $tabcontent, $regFormTag, $introMessage, _LOGIN_REGISTER_TITLE, _REGISTER_TITLE, _UE_REGISTER, $moduleContent, $topIcons, $bottomIcons, $conclusionMessage, $formatting), $output);
        // finally small javascript to focus on first field on registration form if there is no introduction text and it's a text field:
        if (!(isset($ueConfig['reg_intro_msg']) && $ueConfig['reg_intro_msg'] || isset($ueConfig['reg_show_login_on_page']) && $ueConfig['reg_show_login_on_page'] == 1 || $regErrorMSG)) {
            $_CB_framework->outputCbJQuery('$("#cbcheckedadminForm input[type!=\'hidden\']:first").filter("[type=\'text\'],textarea,[type=\'password\']").focus();');
        }
    }
Esempio n. 4
0
function login($username = null, $password = null, $secretKey = null)
{
    global $_POST, $_CB_framework, $_PLUGINS, $ueConfig;
    checkCBPostIsHTTPS();
    $_PLUGINS->loadPluginGroup('user');
    if (count($_POST) == 0) {
        HTML_comprofiler::loginForm('com_comprofiler', $_POST);
        return;
    }
    $loginType = isset($ueConfig['login_type']) ? (int) $ueConfig['login_type'] : 0;
    if ($loginType == 4) {
        $_CB_framework->enqueueMessage(CBTxt::Th('UE_NOT_AUTHORIZED', 'You are not authorized to view this page!'), 'error');
        return;
    }
    $spoofCheckOk = false;
    if (cbSpoofCheck('login', 'POST', 2)) {
        $spoofCheckOk = true;
    }
    if (!$spoofCheckOk) {
        $_CB_framework->enqueueMessage(CBTxt::Th('UE_SESSION_EXPIRED', 'Session expired or cookies are not enabled in your browser. Please press "reload page" in your browser, and enable cookies in your browser.') . ' ' . CBTxt::Th('UE_PLEASE_REFRESH', 'Please refresh/reload page before filling-in.'), 'error');
        return;
    }
    $messagesToUser = array();
    $alertmessages = array();
    if (!$username || !$password || !$secretKey) {
        $username = trim(cbGetParam($_POST, 'username', ''));
        $password = trim(cbGetParam($_POST, 'passwd', '', _CB_ALLOWRAW));
        $secretKey = trim(cbGetParam($_POST, 'secretkey', ''));
        if (checkJversion() >= 1) {
            $username = stripslashes($username);
            $password = stripslashes($password);
            $secretKey = stripslashes($secretKey);
        }
    }
    $rememberMe = cbGetParam($_POST, 'remember');
    $return = trim(stripslashes(cbGetParam($_POST, 'return', null)));
    if (cbStartOfStringMatch($return, 'B:')) {
        $return = base64_decode(substr($return, 2));
        $arrToClean = array('B' => get_magic_quotes_gpc() ? addslashes($return) : $return);
        $return = cbGetParam($arrToClean, 'B', '');
    }
    if (!(cbStartOfStringMatch($return, $_CB_framework->getCfg('live_site')) || cbStartOfStringMatch($return, 'index.php'))) {
        $return = '';
    }
    $message = trim(cbGetParam($_POST, 'message', 0));
    // Do the login including all authentications and event firing:
    cbimport('cb.authentication');
    $cbAuthenticate = new CBAuthentication();
    $resultError = $cbAuthenticate->login($username, $password, $rememberMe, $message, $return, $messagesToUser, $alertmessages, $loginType, $secretKey);
    if (count($messagesToUser) > 0) {
        $_PLUGINS->trigger('onAfterUserLoginFailed', array($username, $password, $rememberMe, $secretKey, &$return, &$alertmessages, &$messagesToUser, &$resultError));
        if (in_array(cbGetParam($_POST, 'loginfrom'), array('loginform', 'regform', 'loginmodule'))) {
            HTML_comprofiler::loginForm('com_comprofiler', $_POST, $resultError, $messagesToUser, $alertmessages);
        } else {
            $_CB_framework->enqueueMessage($resultError, 'error');
            if (is_array($messagesToUser) && $messagesToUser) {
                $return = '<div class="cb_template cb_template_' . selectTemplate('dir') . '">' . '<div>' . implode('</div><div>', $messagesToUser) . '</div>' . '</div>';
                echo $return;
            }
        }
    } elseif ($resultError) {
        $_PLUGINS->trigger('onAfterUserLoginFailed', array($username, $password, $rememberMe, $secretKey, &$return, &$alertmessages, &$messagesToUser, &$resultError));
        if (in_array(cbGetParam($_POST, 'loginfrom'), array('loginform', 'regform', 'loginmodule'))) {
            HTML_comprofiler::loginForm('com_comprofiler', $_POST, $resultError, $messagesToUser, $alertmessages);
        } else {
            $_CB_framework->enqueueMessage($resultError, 'error');
        }
    } else {
        $_PLUGINS->trigger('onAfterUserLoginSuccess', array($username, $password, $rememberMe, $secretKey, &$return, &$alertmessages, &$messagesToUser, &$resultError));
        cbRedirect(cbSef($return, false), count($alertmessages) > 0 ? stripslashes(implode('\\n', $alertmessages)) : '');
    }
}