You are here

function account_sync_sso_login in Account Sync 7.2

Same name and namespace in other branches
  1. 6 account_sync_sso/account_sync_sso.module \account_sync_sso_login()

Login the specified user.

1 string reference to 'account_sync_sso_login'
account_sync_sso_menu in account_sync_sso/account_sync_sso.module
Implements hook_menu().

File

account_sync_sso/account_sync_sso.module, line 73
Handle single sign-on functionality for the account sync module

Code

function account_sync_sso_login($username, $timestamp, $hashed_pass) {
  global $user;
  $target = account_sync_target_path(func_get_args(), 3);
  if ($user->uid) {

    // A user is already logged in, so ignore the attempt and go to the
    // target url.
    drupal_goto($target);
  }
  if ($account = account_sync_validate_login($username, $timestamp, $hashed_pass)) {

    // All checks passed, so lets log in the user.
    $user = $account;
    watchdog('user', 'Account sync sso: Session opened for %name.', array(
      '%name' => $user->name,
    ));
    $user->login = time();
    $query = db_update('users')
      ->fields(array(
      'login' => $user->login,
    ))
      ->condition('name', $user->name)
      ->condition('pass', $user->pass)
      ->execute();

    // Regenerate the session ID to prevent against session fixation attacks.
    drupal_session_regenerate();
    $edit = array();
    user_module_invoke('user_login', $edit, $user);
    drupal_goto($target);
  }
}