python
from flask import Flask, render_template, redirect, url_for, request
from flask_sqlalchemy import SQLAlchemy
from flask_wtf import FlaskForm
from wtforms import StringField, PasswordField, SubmitField
from wtforms.validators import DataRequired, Email, EqualTo
app = Flask(__name__)
app.config['SECRET_KEY'] = 'your_secret_key'
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///users.db'
db = SQLAlchemy(app)
class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
email = db.Column(db.String(150), unique=True, nullable=False)
password = db.Column(db.String(150), nullable=False)
class RegistrationForm(FlaskForm):
email = StringField('Email', validators=[DataRequired(), Email()])
password = PasswordField('Password', validators=[DataRequired()])
confirm_password = PasswordField(
'Confirm Password',
validators=[DataRequired(), EqualTo('password')]
)
submit = SubmitField('Sign Up')
@app.route('/register', methods=['GET', 'POST'])
def register():
form = RegistrationForm()
if form.validate_on_submit():
new_user = User(email=form.email.data, password=form.password.data)
db.session.add(new_user)
db.session.commit()
return redirect(url_for('success'))
return render_template('register.html', form=form)
@app.route('/success')
def success():
return 'Registration successful!'
if __name__ == '__main__':
db.create_all()
app.run(debug=True)