PDA

View Full Version : accessing logged user data


brute f
04-03-2006, 08:55 PM
Hi,

I'm trying to get my drupal module to work on vbdrupal.

getting logged user id from $user->uid doesnt seem to work and i'm not able to find a correct way to access user id. I can see that $user is an object. but $user->name is empty, $user->uid is 0 ....

could someone please tell me how to do this or where to find information on this.

sifuhall
04-04-2006, 09:19 AM
First lets eliminate the obvious.

Have you made $user global inside your function?

brute f
04-05-2006, 12:26 AM
First lets eliminate the obvious.

Have you made $user global inside your function?

yes, it's global. the module works fine on drupal 4.6.5 but for some reason $user->uid returns 0 on vbdrupal 1.3.2.

That's a bit strange, since it is 0, and not null. something has set it to 0 when modules hook_show() is called. i've tested this with users that have id's 1-5 and all of them have $user->uid 0.

I haven't had a change to check what print_r($user) does. incase the uid is stored in some other variable in $user object..

elmuerte
04-05-2006, 02:31 AM
$user->uid should contain the user id unless it's an anonymous user.

brute f
04-05-2006, 02:38 AM
$user->uid should contain the user id unless it's an anonymous user.

is there some way to make logged user anonymous? ($user-uid has been set to 0 for my test users after i've logged in with them)
if there is, is there some variable the holds the real uid?

sifuhall
04-05-2006, 09:01 AM
just out of curiosity if you print_r the $user what do you get?

elmuerte
04-05-2006, 09:30 AM
iirc if the user is not linked to a drupal role it will also be 0

brute f
04-06-2006, 11:22 AM
this is print_r for the $user object of test user. it's logged in
stdClass Object ( [uid] => 0 [roles] => Array ( [1] => anonymous ) [session] => messages|a:0:{} )

when i try the same when logged as Administrator i get correct user data ($user object with uid 1 etc)

so it really seems that the user isnt linked to drupal role. i checked the user info edit page on vbulletin admin but couldnt find anything named like that..

Is it possible to make all users linked to drupal role automatically? the site i'm deploying this module on, has currently 2000-3000 active users, and more to come within following months. It definetly wont be me who's manually linking all those ppl to drupal roles after they're created vbdrupal accounts...

elmuerte
04-06-2006, 03:19 PM
"administer -> access control" -> "Roles"

You assign roles on vbulletin usergroup collections

brute f
04-06-2006, 07:02 PM
i created role "drupal" and set it to vbulletin usergroup 2 (registered users) and now it works.

thanks for the help