Example #1
0
	/**
	 * @param cbautoactionsActionTable $trigger
	 * @param UserTable $user
	 */
	public function execute( $trigger, $user )
	{
		$params					=	$trigger->getParams()->subTree( 'loginlogout' );

		cbimport( 'cb.authentication' );

		$cbAuthenticate			=	new CBAuthentication();

		$isHttps				=	( isset( $_SERVER['HTTPS'] ) && ( ! empty( $_SERVER['HTTPS'] ) ) && ( $_SERVER['HTTPS'] != 'off' ) );
		$returnUrl				=	'http' . ( $isHttps ? 's' : '' ) . '://' . $_SERVER['HTTP_HOST'];

		if ( ( ! empty( $_SERVER['PHP_SELF'] ) ) && ( ! empty( $_SERVER['REQUEST_URI'] ) ) ) {
			$returnUrl			.=	$_SERVER['REQUEST_URI'];
		} else {
			$returnUrl			.=	$_SERVER['SCRIPT_NAME'];

			if ( isset( $_SERVER['QUERY_STRING'] ) && ( ! empty( $_SERVER['QUERY_STRING'] ) ) ) {
				$returnUrl		.=	'?' . $_SERVER['QUERY_STRING'];
			}
		}

		$returnUrl				=	cbUnHtmlspecialchars( preg_replace( '/[\\\"\\\'][\\s]*javascript:(.*)[\\\"\\\']/', '""', preg_replace( '/eval\((.*)\)/', '', htmlspecialchars( urldecode( $returnUrl ) ) ) ) );

		if ( preg_match( '/index.php\?option=com_comprofiler&task=confirm&confirmCode=|index.php\?option=com_comprofiler&view=confirm&confirmCode=|index.php\?option=com_comprofiler&task=login|index.php\?option=com_comprofiler&view=login/', $returnUrl ) ) {
			$returnUrl			=	'index.php';
		}

		$redirect				=	$trigger->getSubstituteString( $params->get( 'redirect', null, GetterInterface::STRING ), array( 'cbautoactionsClass', 'escapeURL' ) );

		if ( $redirect ) {
			$returnUrl			=	$redirect;
		}

		$message				=	$trigger->getSubstituteString( CBTxt::T( $params->get( 'message', null, GetterInterface::RAW ) ), false );

		if ( $params->get( 'mode', 1, GetterInterface::BOOLEAN ) ) {
			$messagesToUser		=	array();
			$alertMessages		=	array();

			if ( $params->get( 'method', 1, GetterInterface::BOOLEAN ) ) {
				$credentials	=	$trigger->getSubstituteString( $params->get( 'username', null, GetterInterface::STRING ) );
				$method			=	0;
			} else {
				$credentials	=	$trigger->getSubstituteString( $params->get( 'email', null, GetterInterface::STRING ) );
				$method			=	1;
			}

			$resultError		=	$cbAuthenticate->login( $credentials, false, 0, 1, $returnUrl, $messagesToUser, $alertMessages, $method );

			if ( $redirect ) {
				cbRedirect( $redirect, ( $resultError ? $resultError : ( $message ? $message : ( $alertMessages ? stripslashes( implode( '<br />', $alertMessages ) ) : null ) ) ), ( $resultError ? 'error' : 'message' ) );
			}
		} else {
			$resultError		=	$cbAuthenticate->logout( $returnUrl );

			if ( $redirect ) {
				cbRedirect( $redirect, ( $resultError ? $resultError : ( $message ? $message : CBTxt::T( 'LOGOUT_SUCCESS', 'You have successfully logged out' ) ) ), ( $resultError ? 'error' : 'message' ) );
			}
		}
	}
Example #2
0
 public function logoutUser()
 {
     cbimport('cb.authentication');
     $cbAuthenticate = new CBAuthentication();
     $redirect_url = KunenaRoute::current();
     $resultError = $cbAuthenticate->logout($redirect_url);
     return $resultError ? $resultError : null;
 }
	/**
	 * Logs in a user
	 *
	 * @param UserTable $user
	 */
	private function login( $user )
	{
		$cbAuthenticate			=	new CBAuthentication();
		$messagesToUser			=	array();
		$alertMessages			=	array();
		$redirectUrl			=	null;
		$resultError			=	$cbAuthenticate->login( $user->get( 'username' ), false, 0, 1, $redirectUrl, $messagesToUser, $alertMessages, 1 );

		if ( $resultError || ( count( $messagesToUser ) > 0 ) ) {
			$error				=	null;

			if ( $resultError ) {
				$error			.=	$resultError;
			}

			if ( count( $messagesToUser ) > 0 ) {
				if ( $resultError ) {
					$error		.=	'<br />';
				}

				$error			.=	stripslashes( implode( '<br />', $messagesToUser ) );
			}

			cbRedirect( $this->_returnUrl, CBTxt::T( 'FAILED_TO_LOGIN_PROVIDER_ACCOUNT', 'Failed to login with [provider] account. Error: [error]', array( '[provider]' => $this->_providerName, '[error]' => $error ) ), 'error' );
			return;
		} else {
			$redirect			=	null;

			if ( ( ! $user->get( 'lastvisitDate' ) ) || ( $user->get( 'lastvisitDate' ) == '0000-00-00 00:00:00' ) ) {
				$redirect		=	$this->params->get( $this->_provider . '_firstlogin', true, GetterInterface::STRING );
			}

			if ( ! $redirect ) {
				$redirect		=	$this->params->get( $this->_provider . '_login', true, GetterInterface::STRING );
			}

			if ( ! $redirect ) {
				$redirect		=	$this->_returnUrl;
			}

			$message			=	( count( $alertMessages ) > 0 ? stripslashes( implode( '<br />', $alertMessages ) ) : null );

			cbRedirect( $redirect, $message, 'message' );
		}
	}
Example #4
0
function logout() {
	global $_POST, $_CB_framework, $_CB_database, $_PLUGINS;

	$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', '' );
	}
	$message				=	trim( cbGetParam( $_POST, 'message', 0 ) );

	if ($return || $message) {
	    $spoofCheckOk		=	false;
	    if ( cbSpoofCheck( 'logout', '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;
	    }
	}

	// Do the logout including all authentications and event firing:
	cbimport( 'cb.authentication' );
	$cbAuthenticate		=	new CBAuthentication();
	$resultError		=	$cbAuthenticate->logout( $return );

	if ( $resultError ) {
		echo "<script type=\"text/javascript\">alert('".addslashes($_PLUGINS->getErrorMSG())."');</script>\n";
		echo "<div class=\"message\">".$_PLUGINS->getErrorMSG()."</div>";;
		return;
	}

	cbRedirect( cbSef( ( $return ? $return : 'index.php' ), false ), ( $message ? stripslashes( _LOGOUT_SUCCESS ) : '' ) );
}
Example #5
0
function logout()
{
    global $_CB_framework, $_POST, $_PLUGINS;
    $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', '');
    }
    $message = trim(cbGetParam($_POST, 'message', 0));
    if ($return || $message) {
        $spoofCheckOk = false;
        if (cbSpoofCheck('logout', '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;
        }
    }
    $_PLUGINS->loadPluginGroup('user');
    // Do the logout including all authentications and event firing:
    cbimport('cb.authentication');
    $cbAuthenticate = new CBAuthentication();
    $resultError = $cbAuthenticate->logout($return);
    if ($resultError) {
        $resultError = $_PLUGINS->getErrorMSG();
        $_PLUGINS->trigger('onAfterUserLogoutFailed', array(&$resultError));
        $_CB_framework->enqueueMessage($resultError);
        return;
    }
    $messageToUser = stripslashes(CBTxt::Th('LOGOUT_SUCCESS', 'You have successfully logged out'));
    $_PLUGINS->trigger('onAfterUserLogoutSuccess', array(&$return, &$message, &$messageToUser));
    cbRedirect(cbSef($return ? $return : 'index.php', false), $message ? $messageToUser : '');
}