Complete the code to import the Flask-Login extension needed for user session management.
from flask_login import [1]
The LoginManager class is imported to manage user sessions and handle login-related tasks in Flask.
Complete the code to protect a Flask route so only logged-in users can access it.
@app.route('/dashboard') @[1] def dashboard(): return 'Welcome to your dashboard!'
The @login_required decorator restricts access to the route to only logged-in users.
Fix the error in the user loader function to load a user by ID.
@login_manager.user_loader def load_user([1]): return User.query.get(int(user_id))
The parameter must be named user_id to match the variable used inside the function.
Fill both blanks to check if the current user has the 'admin' role and restrict access accordingly.
from flask_login import current_user from flask import abort @app.route('/admin') def admin_panel(): if current_user.[1]('admin'): return 'Welcome Admin' else: return [2]('Access denied', 403)
The has_role method checks if the user has the 'admin' role. abort(403) sends a forbidden error if not authorized.
Fill all three blanks to create a dictionary comprehension that maps usernames to their roles only if the user is active.
user_roles = {user.[1]: user.[2] for user in users if user.[3]This comprehension creates a dictionary with usernames as keys and roles as values, but only for users who are active.