Exercise: Record e-mail sending

Implement a registration for a Flask (or other) web application: Accept e-mail as input send e-mail with a code to the given address use that code to verify e-mail address. Without actually sending e-mails.

from flask import Flask, request
import random

app = Flask(__name__)
db = {}

@app.route('/', methods=['GET'])
def home():
    return '''
''' @app.route('/register', methods=['POST']) def register(): email = request.form.get('email') code = str(random.random()) if db_save(email, code): html = 'here'.format(email=email, code = code) sendmail({'to': email, 'subject': 'Registration', 'html': html }) return 'OK' else: return 'FAILED' @app.route('/verify//', methods=['GET']) def verify(email, code): if db_verify(email, code): sendmail({'to': email, 'subject': 'Welcome!', 'html': '' }) return 'OK' else: return 'FAILED' def sendmail(data): pass def db_save(email, code): if email in db: return False db[email] = code return True def db_verify(email, code): return email in db and db[email] == code