From 6fe4168f98dbab7addb11b67bd0f72799698b46f Mon Sep 17 00:00:00 2001
From: Chris Pliakas <cpliakas@266779.no-reply.drupal.org>
Date: Mon, 14 Mar 2011 14:14:51 -0400
Subject: [PATCH] Issue #137919 by cpliakas: Added code that invokes the login operation for hook_user().

---
 webserver_auth.module |   17 +++++++++++++++++
 1 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/webserver_auth.module b/webserver_auth.module
index be53dcb..6864019 100644
--- a/webserver_auth.module
+++ b/webserver_auth.module
@@ -45,6 +45,16 @@ function webserver_auth_init() {
   }
   else {
     if (!empty($authname)) {
+
+      // Captures UID associated with session.
+      if ($sid = session_id()) {
+        $sql = "SELECT uid FROM {sessions} WHERE sid = '%s'";
+        $sess_uid = db_result(db_query($sql, $sid));
+      }
+      else {
+        $sess_uid = FALSE;
+      }
+
       // User is logged into webserver via HTTP authentication.
       // Try to log into Drupal. 
       $user = user_external_load($authname);
@@ -54,6 +64,13 @@ function webserver_auth_init() {
         // webserver_auth_user() and any other _user() hooks.
         user_external_login_register($authname, 'webserver_auth');
       }
+
+      // If the user ID in the session does not match the global user ID, we
+      // are assuming that the user is loggin in.
+      if (!$sess_uid || $sess_uid != $user->uid) {
+        $edit = array('name' => $authname);
+        user_module_invoke('login', $edit, $user);
+      }
     }
   }
 }
-- 
1.7.4.1

