user_external_login

6 user.module user_external_login($account, $edit = array())

Perform standard Drupal login operations for a user object.

The user object must already be authenticated. This function verifies that the user account is not blocked/denied and then performs the login, updates the login timestamp in the database, invokes hook_user('login'), and regenerates the session.

Parameters

$account: An authenticated user object to be set as the currently logged in user.

$edit: The array of form values submitted by the user, if any. This array is passed to hook_user op login.

Return value

boolean TRUE if the login succeeds, FALSE otherwise.

1 call to user_external_login()

File

modules/user/user.module, line 118
Enables the user registration and login system.

Code

function user_external_login($account, $edit = array()) {
  $form = drupal_get_form('user_login');

  $state['values'] = $edit;
  if (empty($state['values']['name'])) {
    $state['values']['name'] = $account->name;
  }

  // Check if user is blocked or denied by access rules.
  user_login_name_validate($form, $state, (array) $account);
  if (form_get_errors()) {
    // Invalid login.
    return FALSE;
  }

  // Valid login.
  global $user;
  $user = $account;
  user_authenticate_finalize($state['values']);
  return TRUE;
}

Comments

Drupal 7

This is different in Drupal 7.

Here's an example from the D7 openid.module:

<?php
        $form_state
['uid'] = $account->uid;
       
user_login_submit(array(), $form_state);
?>

Once you know the Drupal User ID of the otherwise authenticated user, you can pass it as $form_state['uid'] to user_login_submit();

Redirecting after external login

Thanks vordude,
Your code helped me.
I added following to redirect user after login to default user page.
global $base_url;
drupal_goto($base_url.'/?q=user/'.$user->uid);

Login or register to post comments