Help with login & user profiles

apsone - November 10, 2009 - 17:13

Hello, Recently started using drupal for a multi role community. I've managed to get the roles set up on the user form so the user picks a type of user they are, with set permissions in the admin. Just wondering if its possible if to have different profile layouts for the different types of user, so when they login it checks the role type n loads that profile type? any help or direction would be really appreciated thanks alot! - Josh

I'm working on this very same

rschwab - November 10, 2009 - 19:14

I'm working on this very same problem. While I haven't finished yet and don't have any results, here is how I plan on tackling this one:

First I'm going to use either profile permission or profile role so that in the back-end everything is set up. When a user of a particular role or who has a particular permission goes to edit their profile, they will only see the appropriate fields.

Next is the profile view. For that I'm going to modify my user-profile.tpl.php with some if statements to decide which fields to display. Now as I'm typing this out I'm thinking that profile role will probably be easier to incorporate, since RIDs get passed to the page via the $user object. And I think the same should be true of the $account object, which is actually what we'll need for this situation. If user 1 is viewing the profile of user 2, user 1's info is in the $user object, and user 2's info is in the $account object.

- Ryan

Code

rschwab - November 10, 2009 - 22:23

For anyone who stumbles on this looking for help, here is the code I'm using to accomplish this. This goes in the top of my user-profile.tpl.php file:

<?php
profile_load_profile
($account);

// Check if profile is for a client or regular user
$userisclient = 0;
foreach (
$account->roles as $role) {
    if (
$role == 'client') $userisclient = 1;
}

// If the user is not a client, use the following for profile view
if ($userisclient == 0) {
// Non-client profile stuff goes here
}

// If the user is a client, use the full profile below
if ($userisclient == 1) {
// Client profile stuff goes here
}
?>

- Ryan

..

apsone - November 11, 2009 - 02:06

Hi ryan, thanks for replying :)

I understand your script checks the users role as they login and redirects them to a certain profile? is it possible to have 3 or 4 different profile types to go with different roles and if so how could i firstly set up each profile page (where) and then directed it.. would it just be a case of adding userisclient == 3, userisclient == 4 etc? thanks!

Josh

There is probably a more

rschwab - November 11, 2009 - 20:01

There is probably a more elegant way to do it by passing roles as variables to the page with template.php - but yeah I'm just putting each profile type in my user-profile.tpl.php (this is the file drupal will use to print $content into the page for profiles). In the beginning I set a variable and default it to 0. Then I go through the roles the account has and set my variable accordingly. So then in the above code where I say "profile stuff goes here" would be the html for the profile. Here is an example:

<?php
// If the user is not a client, use the following for profile view
if ($userisclient == 0) {
// Non-client profile stuff goes here ?>

<strong>Username: </strong><?php print(check_plain($profile->name)); ?><br />
<strong>Hometown: </strong><?php print(check_plain($profile->hometown)); ?><br />
<?php } ?>

So the profile html for every profile is all going on the one page, and then php is sprinkled in to decide which parts to show for each account.

- Ryan

hey

apsone - November 12, 2009 - 19:00

Hi ryan!! i get yaa! quite clever really! would you mind sending me the files youve edited? so i could have a look? would that be ok? my email is jo5hu8@gmail.com, really appreciate your help! josh

 
 

Drupal is a registered trademark of Dries Buytaert.