How it works...
Once the Flask modules are imported, the login decorator function provides the main logic for handling user authentication. The Python standard library's @wraps() decorator call does the same thing we have done previously with the def wrapper() function, except we are utilizing the functools.wraps function provided by Flask. This is necessary because the login decorator wraps and replaces the original function; without a wrapper, that original data would be lost during the handover.
The decorated_function() takes any number of arguments, either as positional or keyword:value pairs. This function first checks to see whether the global object g.user is None, that is, a user not logged in. If this is the case, the user is automatically ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access