You are here

function openid_connect_connect_form_submit in OpenID Connect / OAuth client 7

Submit callback for the connect account form.

Connect the current user's Drupal account to an external provider.

File

includes/openid_connect.forms.inc, line 105
Forms for OpenID Connect.

Code

function openid_connect_connect_form_submit(&$form, &$form_state) {
  list($op, $client_name) = explode('__', $form_state['triggering_element']['#name'], 2);
  if ($op === 'disconnect') {
    openid_connect_disconnect_account($form_state['account'], $client_name);
    $client = openid_connect_get_client($client_name);
    drupal_set_message(t('Account successfully disconnected from @client.', array(
      '@client' => $client
        ->getLabel(),
    )));
    return;
  }
  global $user;
  if ($user->uid !== $form_state['account']->uid) {
    drupal_set_message(t("You cannot connect another user's account."), 'error');
    return;
  }
  openid_connect_save_destination();
  $client = openid_connect_get_client($client_name);
  $scopes = openid_connect_get_scopes();
  $_SESSION['openid_connect_op'] = $op;
  $_SESSION['openid_connect_connect_uid'] = $user->uid;
  $client
    ->authorize($scopes);
}