Example #1
0
	/**
	* Check if facebook is enabled, and perform appropriate action based on
	* 	authentication state (fb and vb) of the user
	*/
	public function load_facebook()
	{
		global $vbulletin, $show;

		// check if facebook and session is enabled
		if (is_facebookenabled())
		{
			// is user is logged into facebook?
			if ($show['facebookuser'] = vB_Facebook::instance()->userIsLoggedIn())
			{
				// is user logged into vB?
				if (!empty($vbulletin->userinfo['userid']))
				{
					// if vb user is not associated with the current facebook account (or no facebook account at all),
					// redirect to the register association page, if doing facebook redirect
					if ($vbulletin->userinfo['fbuserid'] != vB_Facebook::instance()->getLoggedInFbUserId())
					{
						if (do_facebook_redirect())
						{
							exec_header_redirect('register.php' . $vbulletin->session->vars['sessionurl_q']);
						}

						// if not doing facebook redirect and not on the reg page,
						// pretend the user is not logged into facebook at all so user can browse
						else if (THIS_SCRIPT != 'register')
						{
							$show['facebookuser'] = false;
						}
					}
				}

				// user is not logged into vb, but logged into facebook
				else
				{
					// check if there is an associated vb account, if so attempt to log that user in
					if (vB_Facebook::instance()->getVbUseridFromFbUserid())
					{
						// make sure user is trying to login
						if (do_facebook_redirect())
						{
							// need to load the style here to display
							// the login welcome message properly
							$this->load_style();

							require_once(DIR . '/includes/functions_login.php');
							if (verify_facebook_authentication())
							{
								// create new session
								process_new_login('fbauto', false, '');

								// do redirect
								do_login_redirect();
							}
						}
						// if user is not trying to login with FB connect,
						// pretend like the user is not logged in to FB
						else if (THIS_SCRIPT != 'register')
						{
							$show['facebookuser'] = false;
						}
					}

					// otherwise, fb account is not associated with any vb user
					else
					{
						// redirect to the registration page to create a vb account
						if (do_facebook_redirect())
						{
							exec_header_redirect('register.php' . $vbulletin->session->vars['sessionurl_q']);
						}

						// if not doing redirect and not trying to register,
						// pretend user is not logged into facebook so they can still browse the site
						else if (THIS_SCRIPT != 'register')
						{
							$show['facebookuser'] = false;
						}
					}
				}
			}
		}
	}
Example #2
0
 /**
  * Check if facebook is enabled, and perform appropriate action based on
  * 	authentication state (fb and vb) of the user
  */
 public function load_facebook()
 {
     global $vbulletin, $show;
     $vbulletin->input->clean_array_gpc('r', array('dofbredirect' => TYPE_BOOL));
     $dofbredirect = ($vbulletin->GPC_exists['dofbredirect'] and $vbulletin->GPC['dofbredirect'] == 1);
     // check if facebook and session is enabled
     if (is_facebookenabled()) {
         // is user is logged into facebook?
         if ($show['facebookuser'] = vB_Facebook::instance()->userIsLoggedIn()) {
             // is user logged into vB?
             if (!empty($vbulletin->userinfo['userid'])) {
                 // if vb user is not associated with the current facebook account (or no facebook account at all),
                 // redirect to the register association page, if doing facebook redirect
                 if ($vbulletin->userinfo['fbuserid'] != vB_Facebook::instance()->getLoggedInFbUserId()) {
                     if (do_facebook_redirect()) {
                         exec_header_redirect('register.php' . $vbulletin->session->vars['sessionurl_q']);
                     } else {
                         if (THIS_SCRIPT != 'register') {
                             $show['facebookuser'] = false;
                             if ($dofbredirect) {
                                 standard_error(fetch_error('facebook_connect_fail'));
                             }
                         }
                     }
                 }
             } else {
                 // check if there is an associated vb account, if so attempt to log that user in
                 if (vB_Facebook::instance()->getVbUseridFromFbUserid()) {
                     // make sure user is trying to login
                     if (do_facebook_redirect()) {
                         // need to load the style here to display
                         // the login welcome message properly
                         $this->load_style();
                         require_once DIR . '/includes/functions_login.php';
                         if (verify_facebook_authentication()) {
                             // create new session
                             process_new_login('fbauto', false, '');
                             // do redirect
                             do_login_redirect();
                         }
                     } else {
                         if (THIS_SCRIPT != 'register') {
                             $show['facebookuser'] = false;
                             if ($dofbredirect) {
                                 standard_error(fetch_error('facebook_connect_fail'));
                             }
                         }
                     }
                 } else {
                     // redirect to the registration page to create a vb account
                     if (do_facebook_redirect()) {
                         exec_header_redirect('register.php' . $vbulletin->session->vars['sessionurl_q']);
                     } else {
                         if (THIS_SCRIPT != 'register') {
                             $show['facebookuser'] = false;
                             if ($dofbredirect) {
                                 standard_error(fetch_error('facebook_connect_fail'));
                             }
                         }
                     }
                 }
             }
         }
     }
 }