Add email confirmation

This commit is contained in:
Stephan Porada 2019-07-08 15:58:46 +02:00
parent 30e82088b4
commit ae11e04c6c

View File

@ -36,15 +36,32 @@ def register():
return redirect(url_for('main.index'))
form = RegistrationForm()
if form.validate_on_submit():
user = User(email=form.email.data, username=form.username.data,
user = User(email=form.email.data.lower(),
username=form.username.data,
password=form.password.data)
db.session.add(user)
db.session.commit()
flash('Successfully registered! You can now login.')
token = user.generate_confirmation_token()
send_email(user.email, 'Confirm Your Account',
'auth/email/confirm', user=user, token=token)
flash('A confirmation email has been sent to you by email.')
return redirect(url_for('auth.login'))
return render_template('auth/register.html.j2', form=form)
@auth.route('/confirm/<token>')
@login_required
def confirm(token):
if current_user.confirmed:
return redirect(url_for('main.index'))
if current_user.confirm(token):
db.session.commit()
flash('You have confirmed your account. Thanks!')
else:
flash('The confirmation link is invalid or has expired.')
return redirect(url_for('main.index'))
@auth.route('/reset', methods=['GET', 'POST'])
def password_reset_request():
if not current_user.is_anonymous: