Complete the code to import the Flask class.
from flask import [1]
The Flask class is imported from the flask module to create the app.
Complete the code to define a route for email verification.
@app.route('/verify_email/[1]') def verify_email(token): pass
The route uses a variable part named 'token' to capture the verification token from the URL.
Fix the error in the code to generate a timed token for email verification.
from itsdangerous import URLSafeTimedSerializer def generate_token(email): serializer = URLSafeTimedSerializer(app.config['SECRET_KEY']) return serializer.[1](email, salt=app.config['SECURITY_PASSWORD_SALT'])
The 'dumps' method creates a signed token from the email string.
Fill both blanks to decode the token and handle expiration.
def confirm_token(token, expiration=3600): serializer = URLSafeTimedSerializer(app.config['SECRET_KEY']) try: email = serializer.[1](token, salt=app.config['SECURITY_PASSWORD_SALT'], max_age=[2]) except Exception: return False return email
'loads' decodes the token and 'max_age' sets the expiration time in seconds.
Fill all three blanks to send a verification email with a token link.
from flask_mail import Message def send_verification_email(user_email): token = generate_token(user_email) verify_url = url_for('verify_email', token=[1], _external=True) msg = Message('Please verify your email', sender=app.config['MAIL_DEFAULT_SENDER'], recipients=[user_email]) msg.body = f'Click the link to verify your email: [2]' mail.[3](msg)
The token variable is passed to the URL, the URL is used in the email body, and 'send' sends the email message.
