Registering a user through CB API with CBSubs

9 years 1 month ago - 9 years 1 month ago #261807 by danmoore82
I'm building a custom registration module using cb 1.9 with cbsubs 3.

I've built custom registration forms for cb before which worked fine using the api function at www.joomlapolis.com/support/tutorials/120-api-usage/18362-registering-a-user-through-cb-api. The problem is I'm not sure how to hook in the cbsubs aspect in this function.

When you register from the standard cb reg form it writes a row to the cb subscriptions table then takes you directly to index.php/option=com_comprofiler with the payment options. Using the API to register it doesn't add that subscription row. This is what I need to figure out at this point.

I would definitely like to keep this within the cb api if there's a way to do it, otherwise I'll have to just do the registration through normal queries which will be a pain and not very good practice.

Are there any triggers or methods I can hook into here to do this?

Please Log in to join the conversation.

9 years 1 month ago - 9 years 1 month ago #261848 by danmoore82
Replied by danmoore82 on topic Registering a user through CB API with CBSubs
Here's where I'm at at this point...

You can successfully register using the custom api form.

I would like to redirect to the payments page after registration but it's obviously not as simple as just redirecting to index.php?option=com_comprofiler&task=pluginclass&user=[userid]&plugin=cbpaidsubscriptions.

So now I'm looking for a trigger/method that will simply do this redirect instead of having to hack something together as I'm sure there has to be something somewhere I can tap into in order to this, correct?

*** UPDATE ***
So I can just do a redirect to /index.php?option=com_comprofiler&task=pluginclass&plugin=cbpaidsubscriptions&do=displayplans and basically achieve what I need I think.

This will probably get me through the initial part of the build, but the next phase is showing a user's subscription data in a custom modal. The UI of this site really doesn't incorporate a user profile, rather most of the info and account controls are built into a custom fixed top bar so it's not a standard out of the box CB type site.

Please Log in to join the conversation.

9 years 1 month ago - 9 years 1 month ago #261852 by danmoore82
Replied by danmoore82 on topic Registering a user through CB API with CBSubs
One unexpected issue has popped up with the custom login form I've built.

For some reason, no matter what I do I just get a blank white page after logging in. The user successfully logs in but it doesn't redirect properly.

Here's my method:
    public static function loginUser($username, $password, $remember) {
        // INCLUDE CB API
        global $_CB_framework, $mainframe, $_CB_database, $ueConfig, $_PLUGINS;

        if (defined('JPATH_ADMINISTRATOR')) {
            if (!file_exists(JPATH_ADMINISTRATOR . '/components/com_comprofiler/plugin.foundation.php')) {
                echo 'CB not installed!';
                return;
            }

            include_once(JPATH_ADMINISTRATOR . '/components/com_comprofiler/plugin.foundation.php');
        } else {
            if (!file_exists($mainframe->getCfg('absolute_path') . '/administrator/components/com_comprofiler/plugin.foundation.php')) {
                echo 'CB not installed!';
                return;
            }

            include_once($mainframe->getCfg('absolute_path') . '/administrator/components/com_comprofiler/plugin.foundation.php');
        }
        cbimport('cb.database');
        cbimport('cb.html');
        cbimport('cb.plugins');

        // GET CB USER
        $myId = $_CB_framework->myId();
        $cbUser =& CBuser::getInstance( $myId );

        if ( ! $cbUser ) {
            $cbUser =& CBuser::getInstance( null );
        }

        $user =& $cbUser->getUserData();

        cbimport( 'cb.authentication' );

        $cbAuthenticate		=	new CBAuthentication();

        $messagesToUser		=	array();
        $alertmessages		=	array();
        $redirect_url		=	'/index.php?option=com_comprofiler';
        $resultError		=	$cbAuthenticate->login( $username, $password, $remember, 1, $redirect_url, $messagesToUser, $alertmessages, 0 );

        if ( $resultError ) {
            $user->_error	=	$resultError;
            echo $user->_error;
        } else {
            return ( count( $alertmessages ) > 0 ? stripslashes( implode( '<br />', $alertmessages ) ) : true );
        }

        return false;
    }

** UPDATE **
Never mind I guess, for some reason it now works lol, no idea why.

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.095 seconds

Facebook Twitter LinkedIn