chapter eight

8 User authentication

 

This chapter covers

  • Registering and activating new user accounts
  • Installing and creating Django apps
  • Logging into and out of your project
  • Accessing user profile information
  • Testing authentication

Users and groups are analogous to authentication and authorization. In this chapter you create users and learn about authentication; in a later chapter you create groups and learn about authorization. You begin this chapter by creating a new user registration workflow in the Django project you created previously. Bob uses this workflow to create and activate an account for himself. Next, you create an authentication workflow. Bob uses this workflow to log in, access his profile information, and log out. HTTP session management, from the previous chapter, makes an appearance. Finally, you write tests to verify this functionality.

8.1      User registration

In this section you leverage django-registration, a Django extension library, to create a user registration workflow. Along the way you learn about the basic building blocks of Django web development. Bob uses your user registration workflow to create and activate an account for himself. This section prepares you and Bob for the next section where you build an authentication workflow for him.

The user registration workflow is a two-step process; you have probably already experienced it.

  1. Bob creates his account
  2. Bob activates his account

8.1.1   Templates

8.1.2   Bob registers his account

8.2      User authentication

8.2.1   Built-in Django views

8.2.2   Creating a Django app

8.2.3   Bob logs into and out of his account

8.3      Requiring authentication concisely

8.4      Testing authentication

8.5      Summary