You are here

linkedin_auth.pages.inc in LinkedIn Integration 6

Same filename and directory in other branches
  1. 7 linkedin_auth/linkedin_auth.pages.inc

File

linkedin_auth/linkedin_auth.pages.inc
View source
<?php

/*
 * @file Pages callbacks and form builder functions for Linkedin Profile module
 */

/* Implementation of hook_linkedin_admin_page
 * Add our settings to the main Linkedin settings page
 */
function linkedin_auth_linkedin_admin_page() {
  $form = array();
  $form['linkedin_auth'] = array(
    '#description' => t('Let users login using their LinkedIn account once they have tied it to their local account'),
    '#title' => t('LinkedIn authentication'),
    '#type' => 'fieldset',
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['linkedin_auth']['linkedin_auth_login_link_on_block'] = array(
    '#type' => 'checkbox',
    '#title' => 'Display LinkedIn login link on login block form',
    '#default_value' => variable_get('linkedin_auth_login_link_on_block', '0'),
  );
  $form['linkedin_auth']['linkedin_auth_login_link_on_page'] = array(
    '#type' => 'checkbox',
    '#title' => 'Display LinkedIn login link on login page form',
    '#default_value' => variable_get('linkedin_auth_login_link_on_page', '0'),
  );
  $form['linkedin_auth']['linkedin_auth_login_block'] = array(
    '#type' => 'checkbox',
    '#title' => 'Provides a seperate "Linkedin login block"',
    '#default_value' => variable_get('linkedin_auth_login_block', '0'),
  );
  $form['linkedin_auth']['linkedin_auth_register_if_not_found'] = array(
    '#type' => 'checkbox',
    '#title' => t('Allow users to register using LinkedIn. Will bypass user mail verification or administrator approval.'),
    '#default_value' => variable_get('linkedin_auth_bypass_register_checks', 1),
  );
  return $form;
}

/**
 * Menu callback.
 * Called when user perform linkedin registration
 */
function linkedin_auth_register_page($form_state = array()) {
  $user_reg_mode = variable_get('user_register', 1);
  if ($user_reg_mode == 0) {
    drupal_access_denied();
    return;
  }
  $form = drupal_retrieve_form('user_register', $form_state);
  drupal_prepare_form('user_register', $form, $form_state);
  $form['name']['#default_value'] = $data['name'];
  $form['#redirect'] = isset($_REQUEST['destination']) ? $_REQUEST['destination'] : '';

  //  Only remove standard register submit, but play nicely wth other modules.
  $key = array_keys($form['#submit'], 'user_register_submit');
  unset($form['#submit'][$key[0]]);
  $form['#submit'][] = 'linkedin_auth_register_form_submit';
  return $form;
}
function linkedin_auth_register_form_submit($form, &$form_state) {
  user_external_login_register($form_state['values']['name'], 'linkedin');
  global $user;
  $account = user_save($user, $form_state['values']);
  if (!$account) {
    drupal_set_message(t("Error saving user account."), 'error');
    drupal_goto();
  }
  linkedin_access_token($account);
}

Functions

Namesort descending Description
linkedin_auth_linkedin_admin_page
linkedin_auth_register_form_submit
linkedin_auth_register_page Menu callback. Called when user perform linkedin registration