You are here

fbconnect_test.module in Facebook Connect 6.2

Same filename and directory in other branches
  1. 8.2 tests/fbconnect_test.module
  2. 7.2 tests/fbconnect_test.module

@todo.

File

tests/fbconnect_test.module
View source
<?php

/**
 * @file
 * @todo.
 */

/**
 * @todo.
 */
function fbconnect_test_menu() {
  $menu['fbconnect-test/init-fb-session'] = array(
    'access callback' => TRUE,
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'fbconnect_test_fb_session',
    ),
  );
  return $menu;
}

/**
 * @todo.
 */
function fbconnect_test_fb_session() {
  $form['fbuid'] = array(
    '#type' => 'textfield',
    '#title' => 'FB UID',
    '#required' => TRUE,
  );
  $form['access_token'] = array(
    '#type' => 'textfield',
    '#title' => 'Access Token',
    '#required' => TRUE,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => 'Submit',
  );
  if ($session = fbconnect_facebook_client()
    ->getSession()) {
    $form['fbuid']['#default_value'] = $session['uid'];
    $form['access_token']['#default_value'] = $session['access_token'];
  }
  return $form;
}

/**
 * @todo.
 */
function fbconnect_test_fb_session_submit($form, &$form_state) {
  $session = array(
    'uid' => $form_state['values']['fbuid'],
    'access_token' => $form_state['values']['access_token'],
    'expires' => time() + 3600,
  );
  ksort($session);

  // Generate the base string.
  $base_string = '';
  foreach ($session as $key => $value) {
    $base_string .= $key . '=' . $value;
  }
  $base_string .= fbconnect_facebook_client()
    ->getApiSecret();
  $session['sig'] = md5($base_string);
  if (!fbconnect_facebook_client()
    ->setSession($session)
    ->getSession()) {
    drupal_set_message('bad session', 'error');
  }
}