Here is a function for auto login. Its useful when we want to make a user as logged in from clicking our
URL from e-mail.

You will need to add a menu callback in your module's hook_menu for the URL you wish to send out.

function alternate_user_login($encoded_uid = NULL) {
  global $user;
  $uid = base64_decode($encoded_uid);
  // Check if the user is already logged in. The back button is often the culprit here.
  if ($user->uid) {
    drupal_goto('');
  }
  $account = user_load(array('uid' => $uid));
  $user = $account;
  // And proceed with normal login, going to user page.
  $edit = array();
  user_module_invoke('login', $edit, $user);
  sess_regenerate();
  drupal_goto('user/'.$user->uid.'/edit');
}

Comments

jcharlesberry’s picture

Hello, can you point out a how-to page/tutorial on this or give some directions? We have a content type that we need to be only accessible from authenticated users through an email like you are saying here. Thanks in advance!