Topic-icon Sweepstakes Workflow with Facebook Auth Dialog Box?

Active Subscriptions:

None
Bump for a point in the right direction... :)
The topic has been locked.
Support Specialist
14 years 3 months ago #19416 by alzander
Ryan,
Yes, I think there's a better way to do it. Actually been thinking about it for a day, but will need to investigate, and think about it more. The "all three content types must appear on the same URL." isn't necessary a worry. The FB Page may only start of by loading a specific page from your site, but you can redirect the user wherever you want.

Without any code, my immediate response is simply to have a quick check in the /libraries/canvas.php file. Something like:
If (user isn't logged in)
redirect to Page A;
else if (hasn't filled out form) // we know the user is logged in here
redirect to Page B;
else // User is logged in and has filled out form
redirect to Page C;

We already do a redirect in the code for the Reveal page or non-reveal page... so a redirect isn't a big deal. The main questions are:
1) Do you have a way to check if the user has filled out the form?
2) Are you planning to try to automatically log the user in if they aren't currently, but have already registered? This makes it more complex, so, for now, I may recommend not doing this until we get it working without it.

Hopefully the pseudo-code example above helps with some ideas (or possibly implementation if interested)... and let us know the other info as well.

Thanks,
Alex
The topic has been locked.
Active Subscriptions:

None
Thanks Alex! The challenge here is showing the correct content when a user navigates back to the tab page. Here is my current workflow:

Landing on the tab shows Content-A (user is logged out). If you click the Register button on Content-A, this creates an account using facebook credentials and the page refreshes (same url). On this page, I'm changing the content of the page using ACL. So the registration button hides and a new form module appears because they are registered. The registered user now fills out the form and enters the sweepstakes. They are then redirected to a new URL which prompts them to invite friends, using the Requests feature. If they invite people, then it redirects them to another URL which confirms the invitations have been sent. All of this works great!

The trick is when / if they come back to the tab. If they are logged out, they see the Register button (Content-A)... Not ideal, but acceptable. But if they click the register button (or if they are still logged in), they will then see the entry form again (Content-B). This is what I want to prevent. They shouldn't see the entry form again (Content-B), they should see the invite page (Content-C) or possibly a different page that could show the winners (Content-D).

The entry form can capture the joomla user ID, I'm just not sure how I could utilize that to show different content on the Reveal page. Long post, sorry for all that, I hope this makes sense, let me know if anything needs clarification!
The topic has been locked.
Active Subscriptions:

None
Sorry, I re-read what you wrote and I think I understand what you're saying. After a user fills out the form, the users ID is stored in the entry form db, so if we can query that, then we should be able to display the correct content. That should take care of #1.

And #2 would be nice (automatically log people in if possible). But I agree with you, we'd need to get #1 working first.
The topic has been locked.
Support Specialist
14 years 3 months ago #19562 by alzander
Correct about your interpretation of what we're saying. Simply querying the database for the form submission is better than changing the user's group. Changing their access level can cause different results in other extensions. This is much more targeted.

I'd definitely start with this step, get it working, and then we can discuss adding auto-login functionality. That should actually only be about 4 lines of code that you'd need to add, but you'd need to have the check for the form-submission already working to get auto-login to redirect to the properly location based on whether it's filled out or not.

Hope that helps, and sorry for the 3 day non-response. We'll get you going though :)
Alex
The topic has been locked.
Active Subscriptions:

None
Cool, I'll really appreciate the thought, I'll try to work on that later this week.

I was just doing some browser testing and it looks like I'm having an issue with using IE9 in a facebook tab. Essentially, JFBC gets stuck at the user registration and doesn't complete the redirect. Here is the scenario:

1. Load facebook tab in IE 9, click the "Register" button provided by JFBC

2. Facebook Application Pop up appears.

3a. If the user is already registered in Joomla, the application pop up appears with a white background and the user is logged in, but the pop up never closes and the page doesn't refresh. I can see my domain's URL in the address bar.

3b. If the user is not registered in Joomla, the Registration pop up appears and displays the correct dialog. But after I approve the app, the pop up window gets a white background and I can see the domains URL in the address bar.

Not sure what is happening. The log in procedure seems to work OK on the site in IE 9, but when it's used on Facebook. If you want, I can add you as a developer so you can see the process.
The topic has been locked.
Active Subscriptions:

None
Hey Alex,

So I think the Registration button I mentioned in my last post was due to facebooks Javascript file being loaded twice (SH404SEF re-enabled the plugins when I upgraded). I'll do some more testing to confirm.

Regarding the database query... I've taken a stab at it, but I'm not savvy with PHP and it isn't coded correct. Could you provide any advice on how to tweak this to make it work?

From line 144 in canvas.php...
    private function setupPageTab()
    {
        $app =& JFactory::getApplication();
        $jSession =& JFactory::getSession();

        // First, check if reveal page is setup
        $pageInfo = $jSession->get('jfbcCanvasPageInfo');
        $revealPage = $this->configModel->getSetting('canvas_tab_reveal_article_id', '');
        if ($revealPage && !$pageInfo['liked'] && ((JRequest::getCmd('option') != 'com_content') || (JRequest::getCmd('view') != 'article') ||
                (JRequest::getInt('id') != $revealPage))
        )
        {
            $uri =& JURI::getInstance();
            $uri->delVar('jfbcCanvasBreakout');
            $jSession->set('jfbcCanvasOrigDestination', $uri->toString());
            $app->redirect('index.php?option=com_content&view=article&tmpl=component&id=' . $revealPage);
        }
        
		elseif
		{
			// Get Current Users Joomla ID
			$user =& JFactory::getUser($id);
		
			// Search Database for Joomla Users ID
			$db = JFactory::getDbo();
            $query = $db->getQuery(true);
            $query->select('user_id');
            $query->from('#__sweepstakesDB');
            $query->where('user_id = ' . $user);
            $db->setQuery($query);
			$result = $db->loadResult();
			
			//Match User Name & Redirect
			
			$result = $user
			{
				$uri =& JURI::getInstance();
				$uri->delVar('jfbcCanvasBreakout');
				$jSession->set('jfbcCanvasOrigDestination', $uri->toString());
				$app->redirect(' {Content-C} ');
			}
	
		
		}
		
		else
        {
            $tabTemplate = $this->configModel->getSetting('canvas_tab_template');
            $this->setTemplate($tabTemplate);
        }
    }
The topic has been locked.
Active Subscriptions:

None
Hey Alex,

I've gotten a lot further, but when I place this code in canvas.php, the browser says the page isn't redirecting properly and I need to clear my cookies before I can see the website again (I think it's a problem with the cache buster on the redirect). Any advice on how to tweak this?
    private function setupPageTab()
    {
        $app =& JFactory::getApplication();
        $jSession =& JFactory::getSession();

        // First, check if reveal page is setup
        $pageInfo = $jSession->get('jfbcCanvasPageInfo');
        $revealPage = $this->configModel->getSetting('canvas_tab_reveal_article_id', '');
        if ($revealPage && !$pageInfo['liked'] && ((JRequest::getCmd('option') != 'com_content') || (JRequest::getCmd('view') != 'article') ||
                (JRequest::getInt('id') != $revealPage))
        )
        {
            $uri =& JURI::getInstance();
            $uri->delVar('jfbcCanvasBreakout');
            $jSession->set('jfbcCanvasOrigDestination', $uri->toString());
            $app->redirect('index.php?option=com_content&view=article&tmpl=component&id=' . $revealPage);
        }
        else

        {
            // Get Current Users Joomla ID            
            $user =& JFactory::getUser();        

            // Search Database for Joomla Users ID
            $db = JFactory::getDbo();
            $query = $db->getQuery(true);
            $query->select('user_id');
            $query->from('#__sweep');
            $query->where('user_id = ' . $user->id);
            $db->setQuery($query);
            $result = $db->loadResult();            

            // Try to Match User ID & Redirect
            if ($result)
            {
                $uri =& JURI::getInstance();
                $uri->delVar('jfbcCanvasBreakout');
                $jSession->set('jfbcCanvasOrigDestination', $uri->toString());
                $app->redirect('index.php?option=com_content&view=article&tmpl=component&id=XXX');
            }

            // User ID Not Found
            else
            {                
                $tabTemplate = $this->configModel->getSetting('canvas_tab_template');
                $this->setTemplate($tabTemplate);
            }
        }
    }
The topic has been locked.
Support Specialist
14 years 3 months ago #19982 by alzander
Ryan,
Sorry for the delay. Your code above definitely has a redirect issue. Basically, you're query of the database would be done on every page load, so when the redirect occurs, when that new page is loaded, the redirect would again be loaded. You'll need to add a check to make sure that the user is only redirected once. The below modification should work for you:
// Try to Match User ID & Redirect 
 $redirectDone = $jSession->get('rideproRedirectDone', false); // see if the redirect has been done, default is 'false'
            if ($result && !$redirectDone) 
            { 
                  $jSession->set('rideproRedirectDone', true); // set the redirect value to true
Hope that makes sense, but if you still have issues, let us know. Again, sorry for the delays in responding to this!

Alex
The topic has been locked.
Active Subscriptions:

None
Thanks Alex! I updated the code with your redirect check and it seemed to work correctly on the first page refresh (except I got the wrong template... might have been a URL issue, but I am running RocketTheme/Gantry templates.)

But when I refreshed the page again, it started redirecting me back to {Content-B}. Did I understand your directions correctly?
 // Try to Match User ID & Redirect 

 $redirectDone = $jSession->get('rideproRedirectDone', false); // see if the redirect has been done, default is 'false'

            if ($result && !$redirectDone) 

            { 

                $jSession->set('rideproRedirectDone', true); // set the redirect value to true
				$uri =& JURI::getInstance();
				$uri->delVar('jfbcCanvasBreakout');
                $jSession->set('jfbcCanvasOrigDestination', $uri->toString());
                $app->redirect('index.php?option=com_content&Itemid=XXX&id=XXX&lang=en&view=article');

            }				  

            // User ID Not Found
            else
            {                
                $tabTemplate = $this->configModel->getSetting('canvas_tab_template');
                $this->setTemplate($tabTemplate);
            }
The topic has been locked.