9 What can you do? Authorization

 

This chapter covers

  • Adding login/logout to page navigation
  • Confirming new users with email
  • Allowing users to reset forgotten passwords
  • Allowing existing users to change passwords
  • Adding authorization roles to users
  • Securing routes in the application

In the previous chapter, you created functionality to support users logging in and out of the MyBlog application. Logging in and out is essential functionality we need to make easily accessible to users. Therefore, you’ll add this navigation functionality to the parent base.html template so that it’s available everywhere on the MyBlog application.

9.1 Login/logout navigation

You’ve created a working authentication system, but, currently, it’s accessible primarily by entering the URL into the browser navigation bar. Let’s add the login/logout URL routes to the Bootstrap navigation system.

The authentication system has two mutually exclusive states as a user; you can only be logged in or logged out. Because of this, the authentication system is represented in the navigation menu as a single item that toggles between states depending on the user’s current authentication status. Keeping with the idea of single responsibility and not overcomplicating the base.html template, the login/logout menu functionality will exist as a Jinja macro in the examples/CH_09/examples/01/app/templates/macros.jinja file:

9.2 Confirming new friends

9.2.1 Sending email

9.3 Resetting passwords

9.4 User profiles

9.5 Security

9.5.1 Protecting routes

9.6 User authorization roles

9.6.1 Creating the roles

9.6.2 Authorizing routes

9.7 Protecting forms