Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # form is submitted via a POST request to the /register route
- @app.route('/register', methods=['GET', 'POST'])
- def register():
- # this is using a class created using WTForms
- form = RegForm()
- if request.method == 'POST':
- # form is validated via WTForms .validate() method
- if form.validate():
- # checks if submitted email has already been registered
- existing_user = User.objects(email=form.email.data).first()
- if existing_user is None:
- # the password is hashed using generate_password_hash function from werkzeug.security.
- hashpass = generate_password_hash(form.password.data, method='sha256')
- # users credentials are saved to database
- hey = User(form.email.data,hashpass).save()
- # login_user function from flask_login logs the user in
- login_user(hey)
- # user is then redirected to the dashboard route
- return redirect(url_for('dashboard'))
- return render_template('register.html', form=form)
Add Comment
Please, Sign In to add comment