Creating users and user roles

Creating users and assigning roles to them through Drush is really helpful when we do not want to fill all the required fields of the Add User form (especially those that make sense only for registration purposes). We only need to provide a username, an e-mail, and a password. Let's see how we can manage users with a practical example.

Start by creating, through the web interface, a simple content type called Band, which will represent the list of bands attending our music festival. We will then create roles and users to manage this content type through Drush. Here is an example of how the content type fields would look. We have even added an Image field for each band's image.

Creating users and user roles

Then, as we know that there will be collaborators who will register bands in our site, we are going to create a role for them and then create a couple of users. First, we create a role LINE-UP EDITOR with all permissions for the Band content type, as in the following screenshot:

Creating users and user roles

Having done that, we can create a user and assign it the line-up editor role:

$ drush user-create --mail="[email protected]" --password="editor" an_editor
User ID : 2
User name : an_editor
User mail : [email protected]
User roles : authenticated user
User status : active
$ drush user-add-role "line-up editor" an_editor
Added the line-up editor role to uid 2 [success]

The first command (user-create) created the user. The second one (user-add-role) assigned the role line-up editor to it. Now, log in with the mentioned credentials and you will see that you can manage all content related to Bands.

The user commands offer us some really neat shortcuts to deal with the users of a Drupal site. Have a look at the following scenarios and possible solutions:

  • Block a specific user:
$ drush user-block [email protected]

  • Unblock it:
$ drush user-unblock [email protected]

  • Change the password of the user with username houdini:
$ drush user-password --password=h4rderPaSSword houdini

  • Reset the admin user password and open a one-time login screen in the web browser (note that the Drush command is surrounded by left back ticks):
$ firefox `drush user-login --uri=drupal.localhost admin`

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.76.237