Managing Users and their Profiles in Drupal 6 Social Networking

Exclusive offer: get 50% off this eBook here
Drupal 6 Social Networking

Drupal 6 Social Networking — Save 50%

Build a social or community web site, with friends lists, groups, custom user profiles, and much more

$23.99    $12.00
by Michael Peacock | February 2009 | Content Management Drupal Open Source

With our social networking site ready to accept user content, and our roles set up to allow groups of users to contribute to and use our network in different ways, it is time to focus more on our users–specifically, managing users and the settings associated with them, and providing them with tools and options to improve their experience on the site.

In this article by Michael Peacock, you will learn:

  • How to install the needed modules
  • How to add extra fields to user profiles
  • About users, roles, and permissions

What are we going to do and why?

Before we get started, let's have a closer look at what we will be doing, and why. Our users can interact with the web site, and they can have their own blog. Apart from this, there are very few provisions for the users to tell everyone else about themselves, and expand their profiles with something more personal. With a site like ours, it would be useful to know more about our users including:

  • Their pet dinosaur's name
  • Breed of dinosaur
  • Their pet dinosaur's birthday
  • The dinosaur's hobbies and so on
  • Their web address (if they have one)
  • Location / City / Area
  • More information about the user themselves

This can be added to user profiles using the Profile module, which is a core module within Drupal, and simply needs to be enabled and configured.

Many web sites allow users to upload an image to be associated with their accounts, which could be either a small photo of themselves, or a small image known as an avatar. Drupal allows this, but it has some drawbacks which can be fixed using Gravatar. Gravatar is a social avatar service, whereby users set up their avatars, and other web sites automatically pick up their avatars by sending a request to the Gravatar service with the users' emails. This is convenient for our users, as it saves them having to upload their avatars to our site, and reduces the amount of data stored on our site as well as the data being sent and received from our site. This module needs to be downloaded, installed and configured for our users to make use of its features. With the upload module enabled, users can upload their own avatars directly to the site, if they choose to do so. This is because not all users would be members of Gravatar, nor would they all wish to sign up to a third-party service.

With the rise in the number of web sites and social networks that users of the Internet are members of, having to log in to different web sites on a daily basis can put off users if they have to sign up to another web site. OpenID helps prevent this as users need to remember only one username and password. It works by allowing users to login by providing a web address, instead of their usernames and passwords. This web site is their identity with an OpenID provider (maybe it is their own web site or another social network—MySpace and other social networking web sites are OpenID providers). When they log in with these identities, they will be taken to these web sites to log in before being returned to our site. If they have already logged in into their OpenIDs, they will return to the web site as new users. More information on OpenID is available from http://openid.net/. This is a core module which just needs to be enabled.

There are two important points to be noted about OpenID. Firstly, it is decentralized, which means log in details are not tied to a specific provider, and secondly, it is offered as an alternative log in method—users without an OpenID (or those who don't know they have an OpenID!) can still log in or sign up as normal.

Users have their own blogs which they can use, but they are not personalized blogs. By installing the blog theme module, we can allow our users to select different themes for use in their blogs. This way, visitors to one particular user's blog (for example 'Bob') will see the theme that Bob chose.

Once users get to know each other more, they become more interested in each other's posts and topics, and may wish to look up a specific user's posts and contributions. The Tracker module allows users to track one another's contributions to the site. This is a core module, which just needs to be enabled and set up.

Now that we have a better idea of what we are going to do, let's get started!

Install the modules

To make things easier for us, let's install and enable all the relevant modules first. This saves us having to do this again and again at a later stage.

The modules which we require are:

We need to download the relevant modules (ensuring we download ones which are compatible with Drupal 6.x), and extract the ZIP files into the /sites/all/modules folder.

As we have not downloaded and installed any new modules on our Drupal installation yet, we will need to create the folder modules within the /sites/all/ directory. The reason there are sites/all and a sites/default directories is because Drupal can support multiple web sites running off one installation, and this defines which modules are available to which of the installations. Core modules are located elsewhere, which is why we don't have a modules folder already in this location containing the core modules.

Now all the modules just have to be enabled via the Site Building | Modules section of the Administration area.

Users, roles, and permissions

Let's have a more detailed look at users, roles, and permissions and also how they work.

These are all areas of the administration area, within the User management section.

The other options within this section (Access rules, Gravatar, Profiles and User settings) will be looked at later in this article.

Users

When a visitor signs up for our site, a user account is created for him/her. From the Users area, we can view a list of existing users, create new ones and edit them. Within the context of editing a user, not only can we edit their details, such as their usernames or passwords, but we can also suspend their user accounts or delete their user accounts permanently from our social network.

We want our site to become popular, which means that we want to have lots of users. When we get lots of users, it will become more difficult to navigate through their list, and this is when searching, sorting, and filtering them come in handy—which is what we are going to look at now.

For each user, the user list displays:

  • The username
  • The status of the user account (active or blocked)
  • Roles associated with the account
  • Length of time the user has been a member for
  • The time passed since the user was last active on our site
  • A link to edit the user

Viewing / searching / sorting / filtering

Clicking the username will take us to their user profile. We can sort the list of users by clicking the heading in any of the columns to sort the list by that column. One particular use of doing this is that we can see all blocked users, ????so we can quickly reactivate an account should we need to, or see who the newest members are.

We can also filter the accounts displayed using the Show only users where panel.

This allows us to filter the list based on whether the account is active or not, or against specific roles assigned to users.

Creating a user

At the top of the users page, we have the Add user link.

This takes us to the new user page, where we are required to fill out the Username, E-mail address, Password, and Confirm Password again for the user. We can also opt to notify the users of their new accounts, which will send them an email informing them that they have a new account with the Dino Space social network.

Editing

To edit an account, we just need to click the edit link which corresponds to the account, which takes us to the edit page.

We can edit the user's Username, E-mail address, Password, account Status and settings pertaining to modules, which give users additional settings too.

Careful!
If you edit these settings, the users may not be able to log in to their accounts. If you change a user's Username without his/her request, you should let him/her know through email.

Suspending / blocking a user

Within the edit page, we have an option entitled Status, which can be set to either Blocked or Active.

This would allow us to block a user from accessing our site, for instance if they had been posting inappropriate material repeatedly, even after being contacted and asked to stop.

Why block? Why not just delete?
If we were to just delete a user who was posting inappropriate material, or doing something we didn't want, then he/she could just sign up again. Blocking the user prevents him/her from signing up with the same email address and username. Of course, he/she could sign up again with a different email address and a different username. But this helps us to keep things under control.

Deleting a user

At the bottom of the edit user screen, there are two buttons: Save and Delete.

The Save button will confirm and save any changes made to the user's account, and the delete button will permanently remove the user from our social network.

When to delete a user
A user may request to be removed from the web site, in which case, we can use this feature.

Roles

Users are grouped into roles, which in turn have permissions assigned to them. By default, there are two roles within Drupal. These two roles are:

  • anonymous users
  • authenticated users

These roles can be edited, but they can neither be renamed nor deleted. This is why the Operations column in the table below is locked.

The anonymous user role is the role for any user who is not logged-in, and so the permissions associated with it are those which a guest user has. Whereas the role of an authenticated user suits all those users who are logged-in. Additional roles which are added can apply to any number of users. At this stage, we must select which users have which roles assigned to them. Users can change their roles and get more active within the network with features such as Organic Groups, but it is out of the scope of this article.

Editing the permissions of a role allows us to select which permissions are granted to users who have that role assigned to their account. New roles are simply created by entering the name of a new role into the text box and then clicking the Add role button and selecting the permissions to be granted to those users.

Permissions

The Permissions section provides us with a grid view for roles and the permissions assigned to them. All the permissions which can be granted are listed down theside (for example, create blog entries) and the roles along the top. The use of this view, if we were to install a new module with new permissions related to it, is that we could easily update all of our roles to have the desired permissions directly from the grid view.

The Save permissions link at the bottom of the page saves the changes made.

Drupal 6 Social Networking Build a social or community web site, with friends lists, groups, custom user profiles, and much more
Published: February 2009
eBook Price: $23.99
Book Price: $39.99
See more
Select your format and quantity:

Adding special properties to user profiles

With the Profile module enabled, we now have a new section within the User management area, called Profiles.

This provides us with a number of new options to add new fields to user profiles, including:

  • Single-line text fields
  • Multi-line text fields
  • Checkboxes
  • List selections
  • Freeform lists
  • Web addresses
  • Dates

Earlier in this article, we looked at how to extend the user profile in our site. Let's look at this again, but relate the options we wished to add to the types of fields that are available.

  • Their pet dinosaurs' name—this would be a single-line text field
  • Their pet dinosaurs' birthday—this would be a date
  • Breed of dinosaur—this would be a list selection, with the different dinosaur breeds available from a list
  • The dinosaur's hobbies and so on—this could be a multi-line text field, or a free form list allowing the user to either enter a lot of text or a number of different options
  • Their web address (if they have one)—this would be a web address field
  • Location/City/Area—this would be a single-line text field
  • More information about the user—this would be a multi-line text field

Module overview

The module overview screen (the page we see when we click the Profiles link) lists fields which are currently set up (we don't have any at the moment) and lists the types of fields which we can create at the click of a button.

Extending our users' profiles

All the different field types have very similar configuration options available, including:

  • Category
  • Title
  • Form name
  • Explanation
  • Visibility
  • Page title
  • Weight
  • Auto-complete
  • Mandatory
  • Visible in the user registration form

The list selection field also has an additional option. It is Selection options field, which contains the list of options the select field will have, each separated by a new line. The first three options for the field are compulsory, and must be completed for each field that we create.

Different custom fields can be grouped together using the Category option; fields with the same category would be grouped together. The Title of the field would be entered in the title field, and a unique Form name is required for the HTML behind the field we are creating. This could just be profile_ followed by a version of the title field but without spaces and punctuation.

To explain to the user what the field is for, and provide more details as to why or what is being asked from them, we can enter some information in the Explanation setting. The Visibility setting defines who can see the information relating to the user in the custom profile field:

  • Hidden—It may be hidden, visible only to administrators; useful if we were to have a field for leaving notes about a user, for example, reasons why an account has been blocked temporarily
  • Private—Accessible only to privileged users (users with permission to see that particular field)
  • Public—This field is on the users profile page, but not listed on the members list

If the field was made public (the latter public option) and we wanted to view a page where a user has that option, we can enter the title for that page.

We then have the Weight of the field which determines its position in the list of fields, and the auto-complete option, which if enabled, will try to guess the value of the field based on the first view characters (for example, useful for selecting the breed of dinosaur a user owns). Finally, we have options as to whether the field is mandatory, and whether the form is to be shown on the user registration page.

Single-line text fields

We want to create two custom text fields, they should be created as shown here:

Dinosaur name

  • Category: About your dinosaur
  • Title: Dinosaurs' name
  • Form name: profile_dinosaur_name
  • Explanation: The name of your pet dinosaur
  • Visibility: Public (latter)
  • Page title: Owners of dinosaurs called %value
  • Weight: 0
  • Auto-complete: No
  • Mandatory: No
  • Visible in the user registration form: Yes

Location

  • Category: About your dinosaur
  • Title: Location
  • Form name: profile_location
  • Explanation: Where you and your dinosaur live
  • Visibility: Public (latter)
  • Page title: Dinosaur owners located in %value
  • Weight: 4
  • Auto-complete: No
  • Mandatory: No
  • Visible in the user registration form: Yes
Drupal 6 Social Networking Build a social or community web site, with friends lists, groups, custom user profiles, and much more
Published: February 2009
eBook Price: $23.99
Book Price: $39.99
See more
Select your format and quantity:

Multi-line text fields

We would have one multi-line text field as shown here:

About you

  • Category: About you
  • Title: About you
  • Form name: profile_about
  • Explanation: More information about you
  • Visibility: Public (former)
  • Page title: N/A
  • Weight: 6
  • Auto-complete: No
  • Mandatory: No
  • Visible in the user registration form: Yes

Date field

We would have one date field as shown here:

Dinosaur's date of birth

  • Category: About your dinosaur
  • Title: Dinosaurs' date of birth
  • Form name: profile_dinosaur_dob
  • Explanation: When was your dinosaur born
  • Visibility: Public (former)
  • Page title: N/A
  • Weight: 1
  • Auto-complete: No
  • Mandatory: No
  • Visible in the user registration form: Yes

List selection field

We would have one list selection field containing all of the breeds of dinosaurs as shown here:

Breed

  • Category: About your dinosaur
  • Title: Dinosaurs' breed
  • Form name: profile_dinosaur_breed
  • Selection options: T-Rex, Triceratops, etc. all separated by a new line.
  • Explanation: The breed of your pet dinosaur
  • Visibility: Public (latter)
  • Page title: Owners of %value dinosaurs
  • Weight: 2
  • Auto-complete: Yes
  • Mandatory: No
  • Visible in the user registration form: Yes

Free form list field

We would have one free form list field for the activities which the dinosaur enjoys such as:

About your dinosaur

  • Category: About your dinosaur
  • Title: Dinosaurs' activities
  • Form name: profile_dinosaur_activities
  • Explanation: Activities your dinosaur loves
  • Visibility: Public (former)
  • Page title: N/A
  • Weight: 3
  • Auto-complete: No
  • Mandatory: No
  • Visible in the user registration form: Yes

Web address field

We would have one web address field that looks like this:

Your web address

  • Category: About you
  • Title: Your web address
  • Form name: profile_url
  • Explanation: About you
  • Visibility: Public (former)
  • Page title: N/A
  • Weight: 7
  • Auto-complete: No
  • Mandatory: No
  • Visible in the user registration form: Yes

Editing our profile

If we go to our profile (the My account link in the menu) now and then click edit, we have two new tabs containing options: About you and About your dinosaur.

About you

The About you section contains all of the fields in the about you category we created.

About your dinosaur

The About your dinosaur section contains the fields from the about your dinosaur section we created.

Summary

In this article, we learned how to install the modules and add extra fields to our user profiles. We also had a detailed look at users, roles, and permissions.

If you have read this article you may be interested to view :

 

About the Author :


Michael Peacock

Michael Peacock is a web developer from Newcastle, UK and has a degree in Software Engineering from the University of Durham. After meeting his business partner at Durham, he co-founded Peacock Carter, a Newcastle based creative consultancy specializing in web design, web development and corporate identity.

Michael loves working on web related projects. When he is not working on client projects, he is often tinkering with a web app of his own.

He has been involved with a number of books, having written two books himself (and working on his third): Selling online with Drupal e-Commerce Packt, and Building websites with TYPO3 Packt. He has also done technical reviews of two other books: Mobile Web Development Packt, and Drupal Education & E-Learning Packt.

You can follow Michael on Twitter.

Contact Michael Peacock

Books From Packt

Drupal 6 Site Builder Solutions
Drupal 6 Site Builder Solutions

WordPress for Business Bloggers
WordPress for Business Bloggers

Spring 2.5 Aspect Oriented Programming
Spring 2.5 Aspect Oriented Programming

OpenCms 7 Development
OpenCms 7 Development

Drupal Multimedia
Drupal Multimedia

Expert Python Programming
Expert Python Programming

jQuery UI 1.6: The User Interface Library for jQuery
jQuery UI 1.6: The User Interface Library for jQuery

Drupal for Education and E-Learning
Drupal for Education and E-Learning

No votes yet
this is all great information but by
I was wondering you could tell me where I could edit the history of a members join date. For example if it says 5 weeks but I want it to say 20 weeks.

Post new comment

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
3
g
Q
k
z
H
Enter the code without spaces and pay attention to upper/lower case.
Code Download and Errata
Packt Anytime, Anywhere
Register Books
Print Upgrades
eBook Downloads
Video Support
Contact Us
Awards Voting Nominations Previous Winners
Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Resources
Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software