0
0
Flaskframework~20 mins

Why email matters in web apps in Flask - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Email Mastery in Web Apps
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Why do web apps commonly require email verification?

In web applications, why is email verification often required during user registration?

ATo confirm the user owns the email and reduce fake accounts
BTo speed up the app loading time
CTo increase the number of users automatically
DTo avoid using passwords altogether
Attempts:
2 left
💡 Hint

Think about why confirming contact info is important for trust and security.

component_behavior
intermediate
1:30remaining
What happens after sending a confirmation email in Flask?

In a Flask app, after sending a confirmation email with a token link, what should the app do when the user clicks the link?

ALog the user out of the app
BDelete the user account immediately
CVerify the token, activate the user account, and redirect to login
DSend another confirmation email automatically
Attempts:
2 left
💡 Hint

Think about what confirming an email means for the user's account status.

📝 Syntax
advanced
2:00remaining
Identify the correct Flask code to send an email

Which Flask code snippet correctly sends an email using Flask-Mail?

Flask
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?
Amail.send_message(msg)
Bmail.send_mail(msg)
Cmail.send_email(msg)
Dmail.send(msg)
Attempts:
2 left
💡 Hint

Check Flask-Mail documentation for the method to send a Message object.

state_output
advanced
1:30remaining
What is the user status after email confirmation?

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?

Flask
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)
ATrue
BFalse
CNone
DRaises AttributeError
Attempts:
2 left
💡 Hint

Think about what the confirmation link does to the user's active status.

🔧 Debug
expert
2:30remaining
Why does this Flask email confirmation fail to activate the user?

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?

Flask
@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'
Adb.session.commit() is missing
BUser.verify_token returns a new user object not linked to the session
CThe route URL is incorrect
Duser.is_active is set to False instead of True
Attempts:
2 left
💡 Hint

Consider how the user object returned by verify_token relates to the database session.