Hi there,
Im trying to execute some codes when users login. Im using hook_user and defined a function as follows.

function firstsignin_user($op, &$edit, &$account, $category = NULL) {
			var_dump($op);
	if(empty($account->access) && $op=="login") {
	}
	return;			
}

But the login op doesn't get fired at all. I did a var_dump of op to see which op gets fired i see only view,load, register. Why the login op is not being fired? im using drpal 5.7

Comments

ndmaque’s picture

im a newbie, i'm want to interfere when the op='login' but it never seems to happen

if you found the answer pls post back

redndahead’s picture

Anyone enter a bug report?

j_ten_man’s picture

I've had no issues with the login $op. Not sure why it's not working...

jamestombs’s picture

I assume that your module is called firstsignin.module?

This is the code I use, to register each login for every user and it works perfectly.

function loginhistory_user($op, &$edit, &$account, $category = NULL) {
	switch ($op) {
		// Successful Login
		case 'login':
			db_query("INSERT INTO {login_history} (uid, timestamp) VALUES (%d, %d)", $account->uid, $account->login);
			break;
	}
}

You could do the same and add an if statment for the access after the case 'login' or before the switch ($op) {

James T
Action Medical Research - www.action.org.uk

James T
Action Medical Research - www.action.org.uk

redndahead’s picture

I was using a print statement to see what was in the $op var. This wasn't working so I never saw login. Using drupal_set_message() fixed this for me. Now I see it. Sorry for the confusion.

lyricnz’s picture

FYI, this is proably because:

a) your webserver is buffering output from "print"

b) after login, drupal redirects to a different page, which resets this buffer

If you really want to see the output from print, you can call flush() - however this will prevent the post-login redirect from functioning (since HTTP can't redirect if the page output has started)

markj’s picture

I'm unable to get watchdog() to fire (or anything else) at login:

case 'login':
watchdog('user', 'I am just logging in now.');
break;

Doesn't work. I can get case 'load' to work in my module no problem. I'm using Drupal 6.9.

Can anyone get the login op to fire?

greenbeans’s picture

Not working for me either. What the heck is going on?

case 'login':
  echo 'logging in';
  exit();
  break;

Doesn't get called. The same code for other ops does. In Drupal 6.17.

fuerst’s picture

Check for a drupal_goto() call in one of the moduls you use or for other methods of redirection (e.g. when using Rules) when logging in. drupal_goto() calls exit which just stops code execution. After the redirect the user is already logged in and that means the login operation of your module's hook_user() will never be called.

blairski’s picture

I had this problem as well and it was because of the drupal_goto().

We are using the login destination module, which uses drupal_goto() when someone logins, rendering the 'login' operation useless when using hook_user

dotpex’s picture

Set module weight to -1