Skip to content
Snippets Groups Projects
Commit ae11e04c authored by Stephan Porada's avatar Stephan Porada :speech_balloon:
Browse files

Add email confirmation

parent 30e82088
No related merge requests found
......@@ -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:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment