signup with code

I would like to use a link to the sign up that contains a code. (This code is generated when a new user has been referred by an existing user and we use it to take a specific action upon account creation.)

I need a way so that after the new user has registered via social login, the code can still be retrieved. In other words, a way of preserving the code that is in the link to the signup page so that it isn't lost when the user connects with their social network and can then be associated afterwards with their account.

Thank you.

Answers

  • Hi,
    You could add your signup code as an extra parameter to the plugin's callback_uri.
    This callback is usually set in the javascript on your page.
    Regards
  • Hi Frederic,

    I looked here and found the following code to change oneall's callback:
    https://docs.oneall.com/services/implementation-guide/social-login/
    _oneall.push([\'social_login\', \'set_callback_uri\', your_callback_script]);

    I am trying the following code but it's not changing the callback.

    In the page:
    [oa_social_login]
    [social_login_callback_add_code]//

    Shortcode php echoing javascript (tested the php -> javascript echoing and that method is working):
    <?php
    //SOCIAL LOGIN CHANGE callback to include code from link to process after login/registration
    function social_login_callback_add_code() {
    if ( !empty( htmlspecialchars( $_GET["code"] ) ) ) {//there is a code
    $friend_code = htmlspecialchars( $_GET["code"] );
    $new_callback = 'http://employwe.com/bonus/?code=' . $friend_code;
    echo '<script type="text/javascript">
    /* Replace #your_callback_uri# with the url to your own callback script */
    var your_callback_script = ' . $new_callback . ';

    /* Embeds the buttons into the container oa_social_login_container */
    var _oneall = _oneall || [];
    _oneall.push([\'social_login\', \'set_callback_uri\', your_callback_script]);
    ';
    }
    }
    add_shortcode( 'social_login_callback_add_friend_code', 'social_login_callback_add_code' );
    ?>
  • Hi,
    If you use your shortcode, you need to add the code parameter in the shortcode [... code="xxxx"]. (which you are probably doing but did not include in your post)
    Also, adding oa_social_login will display the regular icons, without your callback.
    So, you could use only your shortcode, but include the line
    return oa_social_login_render_login_form ('shortcode'); to display icons.
    Then add an argument with the callback, such as:
    oa_social_login_render_login_form ('shortcode', array ('callback_uri => 'your callback with code'));
    Not tested, just ideas from your description that we probable misunderstood!
  • edited November 2015
    Thank you for that suggestion. Still not working but hopefully we're getting closer.

    Now we have:

    In the page calling shortcode:
    [social_login_callback_add_code]

    For the new shortcode, I replaced this line "_oneall.push([\'social_login\', \'set_callback_uri\', your_callback_script]);" with your suggested "oa_social_login_render_login_form ('shortcode', array ('callback_uri => 'your callback with code'));"
    After that we are outputting with "return oa_social_login_render_login_form ('shortcode');". By the way, the return is working because the OneAll login icon is showing up fine and works. (It's just that the callback URL isn't changed.)

    So new shortcode is:
    //SOCIAL LOGIN CHANGE callback to include code from link to process after login/registration
    function social_login_callback_add_code() {
    if ( !empty( htmlspecialchars( $_GET["code"] ) ) ) {//there is a code
    $code = htmlspecialchars( $_GET["code"] );

    /* Javascript to put Code extracted using php into OneAll icon */
    echo '
    oa_social_login_render_login_form (\'shortcode\', array (\'callback_uri\' => \'http://example.com/?code=' . $code . '\'));

    ';
    }
    return oa_social_login_render_login_form ('shortcode');
    }
    add_shortcode( 'social_login_callback_add_code', 'social_login_callback_add_code' );
  • Hi,
    After a quick glance, 2 calls to oa_social_login_render_login_form seems odd, especially the second one which is without the custom callback.
    But, we will test it out and let you know.
  • OK, let me know what you find. Thank you.
  • Hi,
    The following code works, however, it is a rough solution.
    To use the existing shortcode, with your signup code option, like this:
    [oa_social_login code="1234"]
    then, in user_interface.php, modify lines ~430 into:
    function oa_social_login_shortcode_handler ($args)
    {
     if (is_array($args) and array_key_exists('code', $args)) 
     {
       $args['callback_uri'] = "http://your-site/?code=". $args['code'] ."&amp;oa_social_login_source=shortcode"; 
     }
     if (!is_user_logged_in ())
     {
       return oa_social_login_render_login_form ('shortcode', $args);
     }
     return '';
    }
    add_shortcode ('oa_social_login', 'oa_social_login_shortcode_handler');
    where code is the signup code. You can change those accordingly. Also, this modifies the existing shortcode handler, you could add your own.

    If you need to add JS code inside the callback uri, then you will have further modify user_interface.php, line 951 (because of single quotes required for login window).

    Hope this helps.
  • I'm a little confused. Am I still using the shortcode we had before?

    Entered the new solution.

    [oa_social_login code="1234"] doesn't render the login icon...
  • So it did render then icon... I was logged in before. But it didn't change the callback URL... checking further...
  • OK, we're getting somewhere. When I removed the redirect link in OneAll settings (below) and changed it to Default -- it did work.

    Widget & Shortcode Settings
    Redirect users to this page after they have logged in with Social Login embedded by Widget/Shortcode:
    Redirect users back to the current page (Default)
    Redirect users to the homepage of my blog
    Redirect users to their account dashboard
    Redirect users to the following url:
  • When I output the same thing using php->script it's not working. It's just redirecting back to the current page.


    I see this on 951 but I don't understand what you mean by single quotes and where that is:

    "//Build Callback URI
    if (array_key_exists ('callback_uri', $args) AND !empty ($args ['callback_uri']))
    {
    $callback_uri = "'" . $args ['callback_uri'] . "'";
    }
    else
    {
    $callback_uri = "(window.location.href + ((window.location.href.split('?')[1] ? '&': '?') + \"oa_social_login_source=" . $source . "\"))";
    }

    //No providers selected
    if (count ($providers) == 0)
    {
    $output = '
    [Social Login] ' . __ ('Please enable at least one social network!', 'oa_social_login') . '
    ';
    }"
  • The following is working after adding your code to line 430:

    In the page call to shortcode:
    [social_login_callback_add_code]

    Shortcode in php file echoing HTML and using "do_shortcode":
    //SOCIAL LOGIN CHANGE callback to include code from link to process after login/registration
    function social_login_callback_add_code() {
    if ( !empty( htmlspecialchars( $_GET["code"] ) ) ) {//there is a code
    $code = htmlspecialchars( $_GET["code"] );

    /* HTML to put Code extracted using php into OneAll icon */
    echo do_shortcode( '[oa_social_login code="'. $code . '"]' );
    echo $code;
    } else {
    return oa_social_login_render_login_form ( 'shortcode' );
    }
    }
    add_shortcode( 'social_login_callback_add_code', 'social_login_callback_add_code' );

    Thank you Frederic for making the code to put in line 430!
  • When I put back - after removing it for testing - the general redirect , intended for users not using OneAll Social Login (just entering username and password manually), it is overriding what we did with the Shortcode and URI. How can we make the URI able to maintain itself and not get disregarded?
  • Hi,
    How do you set that general redirect (for users not using OneAll)?
    You can always look into the filter for registration redirect, to inspect and preserve the signup code.

Welcome!

Please sign in to your OneAll account to ask a new question or to contribute to the discussions.

Please click on the link below to connect to the forum with your OneAll account.