Book Image

Learning Flask Framework

Book Image

Learning Flask Framework

Overview of this book

Table of Contents (17 chapters)
Learning Flask Framework
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Creating a user model


The first step in building our authentication system will be to create a database model representing an individual user account. We will store the user's login credentials, along with some additional information such as the user's display name, and their account creation timestamp. Our model will have the following fields:

  • email (unique): store the user's email address and use that for authentication

  • password_hash: instead of stringing each user's password as plaintext, we will hash the password using a one-way cryptographic hash function

  • name: the user's name, so we can display it alongside their blog entries

  • slug: A URL-friendly representation of the user's name, also unique

  • active: Boolean flag indicating whether this account is active. Only active users will be able to log into the site

  • created_timestamp: The time this user account was created

Tip

If there are other fields you think might be useful, feel free to make your own additions to this list.

Now that we have...