Unnessecarily doing stuff upon each pageload

ronnqvist - April 20, 2007 - 15:50
Project:Webserver authentication
Version:4.7.x-1.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:ronnqvist
Status:active
Description

Since this is an authentication module it's really unnecessary for it to do a lot of thinking upon each page load, even when the user is already logged in. Wrapping most of webserver_auth_init() in if (!$user->uid) is my fix:

function webserver_auth_init() {
  global $user, $domain, $account;
  if (!$user->uid) {

   [SNIP]

  }
}

The reason why I need this very much is because I've made another module which is called upon hook_user('load') and would be called upon each and every page load, due to user_external_load($name) calling it.

#1

moshe weitzman - April 24, 2007 - 01:06
Status:needs review» active

that makes sense but there was some reason i did it that way. i think in some cases you want to login as another user and we won't be able to change users if we never execute this code. note end of this comment:

//do nothing because user is already logged into Drupal, and hasn't presented different credentials vis web server

#2

ronnqvist - April 24, 2007 - 11:29

OK... problem solved, wrap the code in this instead.
if ($user->name != $_SERVER["REMOTE_USER"]) {
(Of course you might want to do the trimming stuff to $_SERVER["REMOTE_USER"] first, but this worked for me.)

#3

geste - May 2, 2007 - 17:39

With respect to Moshe's point #1....

In my circumstance, I never want to allow anybody to log in to Drupal as any ID other than what they are showing in REMOTE_USER. Although it was tricky at first to get my REMOTE_USER account promoted to admin.

After it was all set I simply removed login block. There's probably a gotcha here somewhere :)

#4

ronnqvist - June 12, 2007 - 12:59

geste, I think you might have misunderstood Moshe here a little bit. I think he was talking about that if one wanted to log in as a different user, Drupal wouldn't recognise that change of user. My later patch fixes that however.

 
 

Drupal is a registered trademark of Dries Buytaert.