Implementing web form authentication
Flask-Login is an extension module that provides utility methods to manage user sessions, supports Bcrypt hashing, and equips helper classes to build the Flask-Login model and callback methods to secure view functions with user credentials. To use flask-login, install it first using the following pip command:
pip install flask-login
Also, install and set up the Flask-Session module for Flask-Login to store its user session in the filesystem.
Then, to integrate Flask-login into the Flask application, instantiate its LoginManager class in the create_app() method and set it up through the app instance. Define some of its properties such as session_protection, which requires the installation of Flask-Bcrypt, and login_view, which designates the login view function. The following snippet shows the setup of Flask-Login for our ch09-web-login project:
from flask_login import LoginManager def create_app(config_file): Â Â Â Â app...