In web applications, why is email verification often required during user registration?
Think about why confirming contact info is important for trust and security.
Email verification helps confirm the user owns the email address, which reduces fake or spam accounts and allows secure communication.
In a Flask app, after sending a confirmation email with a token link, what should the app do when the user clicks the link?
Think about what confirming an email means for the user's account status.
Clicking the confirmation link verifies the token, activates the account, and usually redirects the user to login or a welcome page.
Which Flask code snippet correctly sends an email using Flask-Mail?
from flask_mail import Mail, Message mail = Mail(app) msg = Message('Hello', sender='noreply@example.com', recipients=['user@example.com']) msg.body = 'Welcome to our app!' # Which line sends the email?
Check Flask-Mail documentation for the method to send a Message object.
The correct method to send an email message in Flask-Mail is mail.send(msg).
Given a Flask app where users start with is_active = False, what is the value of is_active after the user clicks the email confirmation link?
user = User.query.filter_by(email='user@example.com').first() # Initially user.is_active == False # After confirmation link is clicked: user.is_active = True print(user.is_active)
Think about what the confirmation link does to the user's active status.
Clicking the confirmation link sets is_active to True, activating the user account.
Consider this Flask route handling email confirmation:
@app.route('/confirm/')
def confirm_email(token):
user = User.verify_token(token)
if user:
user.is_active = True
db.session.commit()
return 'Confirmed'
return 'Invalid token' Why might the user account not activate after clicking the link?
@app.route('/confirm/<token>') def confirm_email(token): user = User.verify_token(token) if user: user.is_active = True db.session.commit() return 'Confirmed' return 'Invalid token'
Consider how the user object returned by verify_token relates to the database session.
If User.verify_token returns a user object not attached to the current database session, changes like user.is_active = True won't persist after commit.